Changeset 8b942de2822ae69316152244f6c6d807e2bd4bd3

Show
Ignore:
Timestamp:
12/02/07 21:04:02 (1 year ago)
Author:
Jason Michalski <armooo@armooo.net>
git-committer:
Jason Michalski <armooo@armooo.net> 1196651042 -0600
git-parent:

[3854c6a75c597ac0fcdbc323a36189204a2f3831]

git-author:
Jason Michalski <armooo@armooo.net> 1196537632 -0600
Message:

Updated base plugin to use full paths and support random play

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugin.py

    r214a148 r8b942de  
    1 import os, shutil, re 
     1import os, shutil, re, random 
    22from urllib import unquote, unquote_plus 
    33from urlparse import urlparse 
     
    3232        shutil.copyfileobj(f, handler.wfile) 
    3333 
     34    def get_local_base_path(self, handler, query): 
     35 
     36        subcname = query['Container'][0] 
     37        container = handler.server.containers[subcname.split('/')[0]] 
     38 
     39        return container['path'] 
     40 
    3441    def get_local_path(self, handler, query): 
    3542 
     
    4653    def get_files(self, handler, query, filterFunction=None): 
    4754        subcname = query['Container'][0] 
     55        cname = subcname.split('/')[0] 
    4856        path = self.get_local_path(handler, query) 
    4957         
    50         files = os.listdir(path) 
     58        files = [ os.path.join(path, file) for file in os.listdir(path)] 
     59        if query.get('Recurse',['No'])[0]  == 'Yes': 
     60            for file in files: 
     61                if os.path.isdir(file): 
     62                    for new_file in os.listdir(file): 
     63                        files.append( os.path.join(file, new_file) ) 
     64 
     65        file_type = query['Filter'][0] 
    5166        if filterFunction: 
    52             files = filter(filterFunction, files) 
     67            files = [file for file in files if filterFunction(file, file_type)] 
     68 
    5369        totalFiles = len(files) 
    5470 
     
    88104                return cmp(xStr, yStr) 
    89105 
    90         files.sort(dir_sort) 
     106        if query.get('SortOrder',['Normal'])[0] == 'Random': 
     107            seed = query.get('RandomSeed', ['1'])[0] 
     108            random.seed(seed) 
     109            random.shuffle(files) 
     110        else: 
     111            files.sort(dir_sort) 
     112         
     113        local_base_path = self.get_local_base_path(handler, query) 
    91114 
    92115        index = 0 
     
    97120        if query.has_key('AnchorItem'): 
    98121            anchor = unquote(query['AnchorItem'][0]) 
    99             for i in range(len(files)): 
    100                 if os.path.isdir(os.path.join(path,files[i])): 
    101                     file_url = '/TiVoConnect?Command=QueryContainer&Container=' + subcname + '/' + files[i] 
     122            for file, i in zip(files, range(len(files))): 
     123                file_name = file.replace(local_base_path, '') 
     124 
     125                if os.path.isdir(os.path.join(file)): 
     126                    file_url = '/TiVoConnect?Command=QueryContainer&Container=' + cname + file_name 
    102127                else:                                 
    103                     file_url = '/' + subcname + '/' + files[i] 
     128                    file_url = '/' + cname + file_name 
     129 
    104130                if file_url == anchor: 
    105131                    if count > 0: 
     
    110136                        index = i 
    111137                    break 
     138 
    112139            if query.has_key('AnchorOffset'): 
    113140                index = index +  int(query['AnchorOffset'][0]) 
    114                  
     141 
    115142        #foward count 
    116143        if index < index + count: 
     
    119146        #backwards count 
    120147        else: 
    121             print 'index, count', index, count 
    122             print index + count 
    123148            #off the start of the list 
    124149            if index + count < 0: 
    125                 print 0 - (index + count) 
    126150                index += 0 - (index + count) 
    127             print index + count 
    128151            files = files[index + count:index] 
    129152            return files, totalFiles, index + count