Changeset f119c965fdada55f12312fd1eed9e5dbc4f32b49
- Timestamp:
- 12/02/07 21:08:49 (1 year ago)
- git-parent:
[10bf9e4e15a51c6a758fabefb75f6502b7809e09], [e0d9839dbdb9b608c2ea90c31a946c526c44b5d5]
- Files:
-
- beacon.py (modified) (2 diffs)
- httpserver.py (modified) (2 diffs)
- plugin.py (modified) (8 diffs)
- plugins/music/music.py (modified) (4 diffs)
- plugins/music/templates/container.tmpl (modified) (4 diffs)
- plugins/video/video.py (modified) (3 diffs)
- templates/root_container.tmpl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
beacon.py
r8698247 r3854c6a 26 26 beacon.append('identity=%s' % guid) 27 27 28 import socket 29 beacon.append('machine=%s' % socket.gethostname()) 28 beacon.append('machine=%s' % gethostname()) 30 29 beacon.append('platform=pc') 31 30 beacon.append('services=' + self.format_services()) … … 36 35 beacon_ips = config.getBeaconAddreses() 37 36 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 39 42 40 43 def start(self): httpserver.py
r10bf9e4 rf119c96 6 6 from plugin import GetPlugin 7 7 import config 8 from xml.sax.saxutils import escape 8 9 9 10 SCRIPTDIR = os.path.dirname(__file__) … … 90 91 t.containers = self.server.containers 91 92 t.hostname = socket.gethostname() 93 t.escape = escape 92 94 self.send_response(200) 93 95 self.end_headers() plugin.py
r214a148 re7d0360 1 import os, shutil, re 1 import os, shutil, re, random, threading 2 2 from urllib import unquote, unquote_plus 3 3 from urlparse import urlparse … … 10 10 11 11 class Plugin(object): 12 13 random_lock = threading.Lock() 12 14 13 15 CONTENT_TYPE = '' … … 32 34 shutil.copyfileobj(f, handler.wfile) 33 35 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 34 43 def get_local_path(self, handler, query): 35 44 … … 46 55 def get_files(self, handler, query, filterFunction=None): 47 56 subcname = query['Container'][0] 57 cname = subcname.split('/')[0] 48 58 path = self.get_local_path(handler, query) 49 59 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] 51 68 if filterFunction: 52 files = filter(filterFunction, files) 69 files = [file for file in files if filterFunction(file, file_type)] 70 53 71 totalFiles = len(files) 54 72 … … 88 106 return cmp(xStr, yStr) 89 107 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) 91 118 92 119 index = 0 … … 97 124 if query.has_key('AnchorItem'): 98 125 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 102 131 else: 103 file_url = '/' + subcname + '/' + files[i] 132 file_url = '/' + cname + file_name 133 104 134 if file_url == anchor: 105 135 if count > 0: … … 110 140 index = i 111 141 break 142 112 143 if query.has_key('AnchorOffset'): 113 144 index = index + int(query['AnchorOffset'][0]) 114 145 115 146 #foward count 116 147 if index < index + count: … … 119 150 #backwards count 120 151 else: 121 print 'index, count', index, count122 print index + count123 152 #off the start of the list 124 153 if index + count < 0: 125 print 0 - (index + count)126 154 index += 0 - (index + count) 127 print index + count128 155 files = files[index + count:index] 129 156 return files, totalFiles, index + count plugins/music/music.py
r214a148 rba90f24 14 14 15 15 CONTENT_TYPE = 'x-container/tivo-music' 16 17 AUDIO = 'audio' 18 DIRECTORY = 'dir' 19 16 20 playable_cache = {} 17 21 playable_cache = LRUCache(1000) … … 22 26 subcname = query['Container'][0] 23 27 cname = subcname.split('/')[0] 28 local_base_path = self.get_local_base_path(handler, query) 24 29 25 30 if not handler.server.containers.has_key(cname) or not self.get_local_path(handler, query): … … 28 33 return 29 34 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): 33 36 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 36 41 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 45 59 46 60 def media_data(file): 47 61 dict = {} 48 62 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) 51 66 52 67 if file in self.media_data_cache: 53 68 return self.media_data_cache[file] 54 69 55 if isdir(file) or not eyeD3.isMp3File(file):70 if os.path.isdir(file) or not eyeD3.isMp3File(file): 56 71 self.media_data_cache[file] = dict 57 72 return dict … … 80 95 t = Template(file=os.path.join(SCRIPTDIR,'templates', 'container.tmpl')) 81 96 t.name = subcname 97 t.container = cname 82 98 t.files, t.total, t.start = self.get_files(handler, query, AudioFileFilter) 83 99 t.files = map(media_data, t.files) 84 t.isdir = isdir85 100 t.quote = quote 86 101 t.escape = escape plugins/music/templates/container.tmpl
r6ab8361 rba90f24 10 10 </Details> 11 11 #for $file in $files 12 #if $ isdir($file['path'])12 #if $file['is_dir'] 13 13 <Item> 14 14 <Details> 15 <Title>$escape($file. path)</Title>15 <Title>$escape($file.name)</Title> 16 16 <ContentType>x-container/folder</ContentType> 17 17 <SourceFormat>x-container/folder</SourceFormat> … … 19 19 <Links> 20 20 <Content> 21 <Url>/TiVoConnect?Command=QueryContainer&Container=$quote($name)/$quote($file. path)</Url>21 <Url>/TiVoConnect?Command=QueryContainer&Container=$quote($name)/$quote($file.name)</Url> 22 22 <ContentType>x-tivo-container/folder</ContentType> 23 23 </Content> … … 27 27 <Item> 28 28 <Details> 29 <Title>#echo '.'.join(file[' path'].split('.')[:-1]) #</Title>29 <Title>#echo '.'.join(file['name'].split('.')[:-1]) #</Title> 30 30 <ContentType>audio/*</ContentType> 31 31 <SourceFormat>audio/mpeg</SourceFormat> … … 40 40 <ContentType>audio/*</ContentType> 41 41 <AcceptsParams>No</AcceptsParams> 42 <Url>/$quote($ name)/$quote($file.path)</Url>42 <Url>/$quote($container)$quote($file.part_path)</Url> 43 43 </Content> 44 44 </Links> plugins/video/video.py
r10bf9e4 rf119c96 306 306 return 307 307 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 311 310 if os.path.isdir(full_path): 312 311 return True … … 317 316 videos = [] 318 317 for file in files: 319 path = self.get_local_path(handler, query)320 full_path = os.path.join(path, file)321 322 318 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) 326 323 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)) 329 325 330 326 videos.append(video) … … 346 342 path = self.get_local_path(handler, query) 347 343 file_path = os.path.join(path, file) 348 349 344 350 345 file_info = VideoDetails() templates/root_container.tmpl
r6ddab42 rd49819f 5 5 <ContentType>x-container/tivo-server</ContentType> 6 6 <SourceFormat>x-container/folder</SourceFormat> 7 <TotalItems> 1</TotalItems>7 <TotalItems>#echo len($containers) #</TotalItems> 8 8 </Details> 9 9 … … 11 11 <Item> 12 12 <Details> 13 <Title>$ name</Title>14 <ContentType>$ details.content_type</ContentType>13 <Title>$escape($name)</Title> 14 <ContentType>$escape($details.content_type)</ContentType> 15 15 <SourceFormat>x-container/folder</SourceFormat> 16 16 </Details> 17 17 <Links> 18 18 <Content> 19 <Url>/TiVoConnect?Command=QueryContainer&Container=$ name</Url>20 <ContentType>$ details.content_type</ContentType>19 <Url>/TiVoConnect?Command=QueryContainer&Container=$escape($name)</Url> 20 <ContentType>$escape($details.content_type)</ContentType> 21 21 </Content> 22 22 </Links>
