From e3270433d5048366ef679e9d249d5c38250f7b43 Mon Sep 17 00:00:00 2001 From: lucas_nz Date: Wed, 6 Apr 2011 22:34:20 +1200 Subject: [PATCH] set up video pushes to read useragent and provide a different template for mobile devices --- plugins/video/templates/container_mob.tmpl | 87 ++++++++++++++++++++++++++++++ plugins/video/video.py | 13 ++++- 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 plugins/video/templates/container_mob.tmpl diff --git a/plugins/video/templates/container_mob.tmpl b/plugins/video/templates/container_mob.tmpl new file mode 100644 index 0000000..ec82fee --- /dev/null +++ b/plugins/video/templates/container_mob.tmpl @@ -0,0 +1,87 @@ + + + +pyTivo - Push - $escape($name) + + + +
+

pyTivo - Push - $escape($name)

+

Home

+ + + ## Header Row + + + + + + + + #set $i = 0 + ## i variable is used to alternate colors of row + ## loop through passed data printing row for each show or folder + #for $video in $videos + #set $i += 1 + #set $j = $i%2 + + #if $video.is_dir + ## This is a folder + + + + + + #else + ## This is a show + + + + + + #end if + + #end for +
TitleSizeCapture Date
$video.title $video.total_items Items$video.textDate + + + #if $video.episodeTitle + $escape($video.title): $escape($video.episodeTitle) + #else + $escape($video.title) + #end if + + #if $video.description + $escape($video.description) + #end if + #if $video.displayMajorNumbe and $video.callsign + $video.displayMajorNumber $video.callsign + #end if + + $video.textSize + $video.textDate
+

+ + + + +

+
+ + diff --git a/plugins/video/video.py b/plugins/video/video.py index a20b0e5..4fab60e 100644 --- a/plugins/video/video.py +++ b/plugins/video/video.py @@ -33,6 +33,7 @@ PUSHED = '

Queued for Push to %s

%s

' def tmpl(name): return file(os.path.join(SCRIPTDIR, 'templates', name), 'rb').read() +CONTAINER_TEMPLATE_MOBILE = tmpl('container_mob.tmpl') CONTAINER_TEMPLATE = tmpl('container.tmpl') TVBUS_TEMPLATE = tmpl('TvBus.tmpl') @@ -278,6 +279,7 @@ class Video(Plugin): tsn = handler.headers.getheader('tsn', '') subcname = query['Container'][0] cname = subcname.split('/')[0] + useragent = handler.headers.getheader('User-Agent', '') if (not cname in handler.server.containers or not self.get_local_path(handler, query)): @@ -329,7 +331,11 @@ class Video(Plugin): videos.append(video) - t = Template(CONTAINER_TEMPLATE, filter=EncodeUnicode) + logger.debug('mobileagent: %d useragent: %s' % (useragent.lower().find('mobile'), useragent.lower())) + if useragent.lower().find('mobile') > 0: + t = Template(CONTAINER_TEMPLATE_MOBILE, filter=EncodeUnicode) + else: + t = Template(CONTAINER_TEMPLATE, filter=EncodeUnicode) t.container = cname t.name = subcname t.total = total @@ -342,7 +348,10 @@ class Video(Plugin): t.tivos = config.tivos t.tivo_names = config.tivo_names handler.send_response(200) - handler.send_header('Content-Type', 'text/xml') + if useragent.lower().find('mobile') > 0: + handler.send_header('Content-Type', 'text/html; charset=utf-8') + else: + handler.send_header('Content-Type', 'text/xml') handler.send_header('Expires', '0') handler.end_headers() handler.wfile.write(t) -- 2.11.4.GIT