Changeset f119c965fdada55f12312fd1eed9e5dbc4f32b49

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

[10bf9e4e15a51c6a758fabefb75f6502b7809e09], [e0d9839dbdb9b608c2ea90c31a946c526c44b5d5]

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

Merge branch 'master' into subfolders-8.3

Conflicts:

httpserver.py

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • beacon.py

    r8698247 r3854c6a  
    2626        beacon.append('identity=%s' % guid) 
    2727 
    28         import socket 
    29         beacon.append('machine=%s' % socket.gethostname()) 
     28        beacon.append('machine=%s' % gethostname()) 
    3029        beacon.append('platform=pc') 
    3130        beacon.append('services=' + self.format_services()) 
     
    3635        beacon_ips = config.getBeaconAddreses() 
    3736        for beacon_ip in beacon_ips.split(): 
    38             self.UDPSock.sendto(self.format_beacon(), (beacon_ip, 2190)) 
     37            try: 
     38                self.UDPSock.sendto(self.format_beacon(), (beacon_ip, 2190)) 
     39            except error, e: 
     40                print e 
     41                pass 
    3942 
    4043    def start(self): 
  • httpserver.py

    r10bf9e4 rf119c96  
    66from plugin import GetPlugin 
    77import config 
     8from xml.sax.saxutils import escape 
    89 
    910SCRIPTDIR = os.path.dirname(__file__) 
     
    9091         t.containers = self.server.containers 
    9192         t.hostname = socket.gethostname() 
     93         t.escape = escape 
    9294         self.send_response(200) 
    9395         self.end_headers() 
  • plugin.py

    r214a148 re7d0360  
    1 import os, shutil, re 
     1import os, shutil, re, random, threading 
    22from urllib import unquote, unquote_plus 
    33from urlparse import urlparse 
     
    1010 
    1111class Plugin(object): 
     12 
     13    random_lock = threading.Lock() 
    1214 
    1315    CONTENT_TYPE = '' 
     
    3234        shutil.copyfileobj(f, handler.wfile) 
    3335 
     36    def get_local_base_path(self, handler, query): 
     37 
     38        subcname = query['Container'][0] 
     39        container = handler.server.containers[subcname.split('/')[0]] 
     40 
     41        return container['path'] 
     42 
    3443    def get_local_path(self, handler, query): 
    3544 
     
    4655    def get_files(self, handler, query, filterFunction=None): 
    4756        subcname = query['Container'][0] 
     57        cname = subcname.split('/')[0] 
    4858        path = self.get_local_path(handler, query) 
    4959         
    50         files = os.listdir(path) 
     60        files = [ os.path.join(path, file) for file in os.listdir(path)] 
     61        if query.get('Recurse',['No'])[0]  == 'Yes': 
     62            for file in files: 
     63                if os.path.isdir(file): 
     64                    for new_file in os.listdir(file): 
     65                        files.append( os.path.join(file, new_file) ) 
     66 
     67        file_type = query.get('Filter', [''])[0] 
    5168        if filterFunction: 
    52             files = filter(filterFunction, files) 
     69            files = [file for file in files if filterFunction(file, file_type)] 
     70 
    5371        totalFiles = len(files) 
    5472 
     
    88106                return cmp(xStr, yStr) 
    89107 
    90         files.sort(dir_sort) 
     108        if query.get('SortOrder',['Normal'])[0] == 'Random': 
     109            seed = query.get('RandomSeed', ['1'])[0] 
     110            self.random_lock.acquire() 
     111            random.seed(seed) 
     112            random.shuffle(files) 
     113            self.random_lock.release() 
     114        else: 
     115            files.sort(dir_sort) 
     116         
     117        local_base_path = self.get_local_base_path(handler, query) 
    91118 
    92119        index = 0 
     
    97124        if query.has_key('AnchorItem'): 
    98125            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] 
     126            for file, i in zip(files, range(len(files))): 
     127                file_name = file.replace(local_base_path, '') 
     128 
     129                if os.path.isdir(os.path.join(file)): 
     130                    file_url = '/TiVoConnect?Command=QueryContainer&Container=' + cname + file_name 
    102131                else:                                 
    103                     file_url = '/' + subcname + '/' + files[i] 
     132                    file_url = '/' + cname + file_name 
     133 
    104134                if file_url == anchor: 
    105135                    if count > 0: 
     
    110140                        index = i 
    111141                    break 
     142 
    112143            if query.has_key('AnchorOffset'): 
    113144                index = index +  int(query['AnchorOffset'][0]) 
    114                  
     145 
    115146        #foward count 
    116147        if index < index + count: 
     
    119150        #backwards count 
    120151        else: 
    121             print 'index, count', index, count 
    122             print index + count 
    123152            #off the start of the list 
    124153            if index + count < 0: 
    125                 print 0 - (index + count) 
    126154                index += 0 - (index + count) 
    127             print index + count 
    128155            files = files[index + count:index] 
    129156            return files, totalFiles, index + count 
  • plugins/music/music.py

    r214a148 rba90f24  
    1414     
    1515    CONTENT_TYPE = 'x-container/tivo-music' 
     16 
     17    AUDIO = 'audio' 
     18    DIRECTORY = 'dir' 
     19 
    1620    playable_cache = {} 
    1721    playable_cache = LRUCache(1000) 
     
    2226        subcname = query['Container'][0] 
    2327        cname = subcname.split('/')[0] 
     28        local_base_path = self.get_local_base_path(handler, query) 
    2429          
    2530        if not handler.server.containers.has_key(cname) or not self.get_local_path(handler, query): 
     
    2833            return 
    2934         
    30         path = self.get_local_path(handler, query) 
    31         def isdir(file): 
    32             return os.path.isdir(os.path.join(path, file)) 
     35        def AudioFileFilter(file, filter_type = None): 
    3336 
    34         def AudioFileFilter(file): 
    35             full_path = os.path.join(path, file) 
     37            if filter_type: 
     38                filter_start = filter_type.split('/')[0] 
     39            else: 
     40                filter_start = filter_type 
    3641 
    37             if full_path in self.playable_cache: 
    38                 return self.playable_cache[full_path] 
    39             if os.path.isdir(full_path) or eyeD3.isMp3File(full_path): 
    40                 self.playable_cache[full_path] = True 
    41                 return True 
    42             else: 
    43                 self.playable_cache[full_path] = False 
    44                 return False  
     42            if file not in self.playable_cache: 
     43                if os.path.isdir(file): 
     44                    self.playable_cache[file] = self.DIRECTORY 
     45                     
     46                elif eyeD3.isMp3File(file): 
     47                    self.playable_cache[file] = self.AUDIO 
     48                else: 
     49                    self.playable_cache[file] = False 
     50             
     51            if filter_start == self.AUDIO: 
     52                if self.playable_cache[file] == self.AUDIO: 
     53                    return self.playable_cache[file] 
     54                else: 
     55                    return False 
     56            else:  
     57                return self.playable_cache[file] 
     58 
    4559 
    4660        def media_data(file): 
    4761            dict = {} 
    4862            dict['path'] = file 
    49  
    50             file = os.path.join(path, file) 
     63            dict['part_path'] = file.replace(local_base_path, '') 
     64            dict['name'] = os.path.split(file)[1] 
     65            dict['is_dir'] = os.path.isdir(file) 
    5166 
    5267            if file in self.media_data_cache: 
    5368                return self.media_data_cache[file] 
    5469         
    55             if isdir(file) or not eyeD3.isMp3File(file): 
     70            if os.path.isdir(file) or not eyeD3.isMp3File(file): 
    5671                self.media_data_cache[file] = dict 
    5772                return dict 
     
    8095        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'container.tmpl')) 
    8196        t.name = subcname 
     97        t.container = cname 
    8298        t.files, t.total, t.start = self.get_files(handler, query, AudioFileFilter) 
    8399        t.files = map(media_data, t.files) 
    84         t.isdir = isdir 
    85100        t.quote = quote 
    86101        t.escape = escape 
  • plugins/music/templates/container.tmpl

    r6ab8361 rba90f24  
    1010    </Details> 
    1111    #for $file in $files 
    12     #if $isdir($file['path']) 
     12    #if $file['is_dir'] 
    1313    <Item> 
    1414        <Details> 
    15             <Title>$escape($file.path)</Title> 
     15            <Title>$escape($file.name)</Title> 
    1616            <ContentType>x-container/folder</ContentType> 
    1717            <SourceFormat>x-container/folder</SourceFormat> 
     
    1919        <Links> 
    2020            <Content> 
    21                     <Url>/TiVoConnect?Command=QueryContainer&amp;Container=$quote($name)/$quote($file.path)</Url> 
     21                    <Url>/TiVoConnect?Command=QueryContainer&amp;Container=$quote($name)/$quote($file.name)</Url> 
    2222                    <ContentType>x-tivo-container/folder</ContentType> 
    2323            </Content> 
     
    2727    <Item> 
    2828        <Details> 
    29             <Title>#echo '.'.join(file['path'].split('.')[:-1]) #</Title> 
     29            <Title>#echo '.'.join(file['name'].split('.')[:-1]) #</Title> 
    3030            <ContentType>audio/*</ContentType> 
    3131            <SourceFormat>audio/mpeg</SourceFormat> 
     
    4040                <ContentType>audio/*</ContentType> 
    4141                    <AcceptsParams>No</AcceptsParams> 
    42                     <Url>/$quote($name)/$quote($file.path)</Url> 
     42                    <Url>/$quote($container)$quote($file.part_path)</Url> 
    4343                </Content> 
    4444        </Links> 
  • plugins/video/video.py

    r10bf9e4 rf119c96  
    306306            return 
    307307         
    308         def video_file_filter(file): 
    309             path = self.get_local_path(handler, query) 
    310             full_path = os.path.join(path, file) 
     308        def video_file_filter(file, type = None): 
     309            full_path = file 
    311310            if os.path.isdir(full_path): 
    312311                return True 
     
    317316        videos = [] 
    318317        for file in files: 
    319             path = self.get_local_path(handler, query) 
    320             full_path = os.path.join(path, file) 
    321              
    322318            video = VideoDetails() 
    323             video['name'] = file 
    324             video['title'] = file 
    325             video['is_dir'] = self.__isdir(full_path) 
     319            video['name'] = os.path.split(file)[1] 
     320            video['path'] = file 
     321            video['title'] = os.path.split(file)[1] 
     322            video['is_dir'] = self.__isdir(file) 
    326323            if not  video['is_dir']: 
    327                 video['title'] = '.'.join(file.split('.')[:-1]) 
    328                 video.update(self.__metadata(full_path)) 
     324                video.update(self.__metadata(file)) 
    329325 
    330326            videos.append(video) 
     
    346342        path = self.get_local_path(handler, query) 
    347343        file_path = os.path.join(path, file) 
    348  
    349344         
    350345        file_info = VideoDetails() 
  • templates/root_container.tmpl

    r6ddab42 rd49819f  
    55        <ContentType>x-container/tivo-server</ContentType> 
    66        <SourceFormat>x-container/folder</SourceFormat> 
    7         <TotalItems>1</TotalItems> 
     7        <TotalItems>#echo len($containers) #</TotalItems> 
    88    </Details> 
    99 
     
    1111    <Item> 
    1212        <Details> 
    13             <Title>$name</Title> 
    14             <ContentType>$details.content_type</ContentType> 
     13            <Title>$escape($name)</Title> 
     14            <ContentType>$escape($details.content_type)</ContentType> 
    1515            <SourceFormat>x-container/folder</SourceFormat> 
    1616        </Details> 
    1717        <Links> 
    1818            <Content> 
    19                 <Url>/TiVoConnect?Command=QueryContainer&amp;Container=$name</Url> 
    20                 <ContentType>$details.content_type</ContentType> 
     19                <Url>/TiVoConnect?Command=QueryContainer&amp;Container=$escape($name)</Url> 
     20                <ContentType>$escape($details.content_type)</ContentType> 
    2121            </Content> 
    2222        </Links>