From 40986c5453dd767829ef86cd854a4eae8117a32c Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Wed, 21 Nov 2007 23:29:08 -0600 Subject: [PATCH] All most wotking TVBus stuff. Just need some stuff with times --- plugins/video/templates/TvBus.tmpl | 197 +++++++++++++++++++++++---------- plugins/video/templates/container.tmpl | 12 +- plugins/video/video.py | 103 ++++++++++++++--- 3 files changed, 232 insertions(+), 80 deletions(-) diff --git a/plugins/video/templates/TvBus.tmpl b/plugins/video/templates/TvBus.tmpl index eab3109..9919256 100644 --- a/plugins/video/templates/TvBus.tmpl +++ b/plugins/video/templates/TvBus.tmpl @@ -3,76 +3,159 @@ PT00M - - - PT00M - - - - - COLOR - - 5 - - - - - false - 2006-01-23T04:39:43Z - - - false - - - - SERIES - - - - - 0 - 0 - - - PG + + + $video.iso_durarion + + + #for $element in $video.vActor + $element + #end for + + + + + #for $element in $video.vChoreographer + $element + #end for + + $video.colorCode[0] + $video.description + + #for $element in $video.vDirector + $element + #end for + + $video.episodeNumber + + #for $element in $video.vExecProducer + $element + #end for + + + #for $element in $video.vProgramGenre + $element + #end for + + + #for $element in $video.vGuestStar + $element + #end for + + + #for $element in $video.vHost + $element + #end for + + $video.isEpisode + 2006-01-23T04:39:43Z + + #for $element in $video.vProducer + $element + #end for + + + $video.isEpisode + + #for $element in $video.vSeriesGenre + $element + #end for + + $video.seriesTitle + + $video.showType[0] + $video.title + + #for $element in $video.vWriter + $element + #end for + + + + $video.displayMajorNumber + $video.displayMinorNumber + $video.callsign + + $video.tvRating[0] HIGH - + - PT00M + $video.iso_durarion - - - - COLORIZED - - - 0 - - - - - false + + #for $element in $video.vActor + $element + #end for + + + + + #for $element in $video.vChoreographer + $element + #end for + + $video.colorCode[0] + $video.description + + #for $element in $video.vDirector + $element + #end for + + $video.episodeNumber + + #for $element in $video.vExecProducer + $element + #end for + + + #for $element in $video.vProgramGenre + $element + #end for + + + #for $element in $video.vGuestStar + $element + #end for + + + #for $element in $video.vHost + $element + #end for + + $video.isEpisode 2006-01-23T04:39:43Z - + + #for $element in $video.vProducer + $element + #end for + - false - - + $video.isEpisode + + #for $element in $video.vSeriesGenre + $element + #end for + + $video.seriesTitle - SERIES - parkrun1920_12mbps - + $video.showType[0] + $video.title + + #for $element in $video.vWriter + $element + #end for + - 0 - 0 - + $video.displayMajorNumber + $video.displayMinorNumber + $video.callsign - PG + $video.tvRating[0] 2008-01-23T04:39:43Z 2008-01-23T04:39:43Z diff --git a/plugins/video/templates/container.tmpl b/plugins/video/templates/container.tmpl index ab0f943..368154c 100644 --- a/plugins/video/templates/container.tmpl +++ b/plugins/video/templates/container.tmpl @@ -12,7 +12,7 @@ #if $video.is_dir
- $escape($video.name) + $escape($video.title) x-container/folder x-tivo-container/tivo-dvr
@@ -26,16 +26,16 @@ #else
- #echo $escape('.'.join(video['name'].split('.')[:-1])) # + $video.title video/x-tivo-mpeg video/x-ms-wmv $video.size $video.duration $escape($video.description) - $escape($video.episode_title) - $escape($video.source_channel) - $escape($video.source_station) - $video.series_id + $escape($video.episodeTitle) + $escape($video.sourceChannel) + $escape($video.sourceStation) + $video.seriesId
diff --git a/plugins/video/video.py b/plugins/video/video.py index c98506e..bf1324c 100644 --- a/plugins/video/video.py +++ b/plugins/video/video.py @@ -5,6 +5,8 @@ from urllib import unquote_plus, quote, unquote from urlparse import urlparse from xml.sax.saxutils import escape from lrucache import LRUCache +from UserDict import DictMixin +from datetime import timedelta import config SCRIPTDIR = os.path.dirname(__file__) @@ -53,18 +55,11 @@ class Video(Plugin): videoBPS = strtod(config.getVideoBR()) bitrate = audioBPS + videoBPS return int((self.__duration(full_path)/1000)*(bitrate * 1.02 / 8)) - - def __metadata(self, full_path): - description_file = full_path + '.txt' - - metadata = { - 'description' : '', - 'episode_title' : '', - 'source_channel' : '', - 'source_station' : '', - 'series_id' : '', - } + + def __getMetadateFromTxt(self, full_path): + metadata = {} + description_file = full_path + '.txt' if os.path.exists(description_file): for line in open(description_file): if line.strip().startswith('#'): @@ -76,11 +71,30 @@ class Video(Plugin): key = key.strip() value = value.strip() - if key in metadata and not metadata[key]: + if key.startswith('v'): + if key in metadata: + metadata[key].append(value) + else: + metadata[key] = [value] + else: metadata[key] = value return metadata + def __metadata(self, full_path): + + metadata = {} + + metadata.update( self.__getMetadateFromTxt(full_path) ) + + metadata['size'] = self.__est_size(full_path) + metadata['duration'] = self.__duration(full_path) + + duration = timedelta(milliseconds = metadata['duration']) + metadata['iso_durarion'] = 'P' + str(duration.days) + 'DT' + str(duration.seconds) + 'S' + + return metadata + def QueryContainer(self, handler, query): subcname = query['Container'][0] @@ -105,12 +119,12 @@ class Video(Plugin): path = self.get_local_path(handler, query) full_path = os.path.join(path, file) - video = {} + video = VideoDetails() video['name'] = file + video['title'] = file video['is_dir'] = self.__isdir(full_path) if not video['is_dir']: - video['size'] = self.__est_size(full_path) - video['duration'] = self.__duration(full_path) + video['title'] = '.'.join(file.split('.')[:-1]) video.update(self.__metadata(full_path)) videos.append(video) @@ -132,14 +146,69 @@ class Video(Plugin): path = self.get_local_path(handler, query) file_path = os.path.join(path, file) - file_info = self.__metadata(file_path) + + file_info = VideoDetails() + file_info['seriesTitle'] = os.path.split(path)[-1] + file_info['title'] = '.'.join(file.split('.')[:-1]) + file_info.update(self.__metadata(file_path)) + + print file_info handler.send_response(200) handler.end_headers() t = Template(file=os.path.join(SCRIPTDIR,'templates', 'TvBus.tmpl')) t.video = file_info handler.wfile.write(t) - + +class VideoDetails(DictMixin): + + def __init__(self, d = None): + if d: + self.d = d + else: + self.d = {} + + def __getitem__(self, key): + if key not in self.d: + self.d[key] = self.default(key) + return self.d[key] + + def __contains__(self, key): + return True + + def __setitem__(self, key, value): + self.d[key] = value + + def __delitem__(self): + del self.d[key] + + def keys(self): + return self.d.keys() + + def __iter__(self): + return self.d.__iter__() + + def iteritems(self): + return self.d.iteritems() + + def default(self, key): + defaults = { + 'showingBits' : '0', + 'episodeNumber' : '0', + 'displayMajorNumber' : '0', + 'displayMinorNumber' : '0', + 'isEpisode' : 'true', + 'colorCode' : ('COLOR', '4'), + 'showType' : ('SERIES', '5'), + 'tvRating' : ('NR', '7'), + } + if key in defaults: + return defaults[key] + elif key.startswith('v'): + return ['Default'] + else: + return 'Default' + # Parse a bitrate using the SI/IEEE suffix values as if by ffmpeg # For example, 2K==2000, 2Ki==2048, 2MB==16000000, 2MiB==16777216 -- 2.11.4.GIT