Advertisement
alexdunlop81

ustvow default.py

Dec 9th, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.45 KB | None | 0 0
  1. '''
  2.    ustvnow XBMC Plugin
  3.    Copyright (C) 2011 t0mm0
  4.  
  5.    This program is free software: you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation, either version 3 of the License, or
  8.    (at your option) any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. '''
  18.  
  19. from resources.lib import Addon, ustvnow
  20. import sys
  21. import urllib
  22. import time
  23. import xbmc, xbmcgui, xbmcplugin
  24.  
  25. Addon.plugin_url = sys.argv[0]
  26. Addon.plugin_handle = int(sys.argv[1])
  27. Addon.plugin_queries = Addon.parse_query(sys.argv[2][1:])
  28.  
  29. email = Addon.get_setting('email')
  30. password = Addon.get_setting('password')
  31. ustv = ustvnow.Ustvnow(email, password)
  32.  
  33. Addon.log('plugin url: ' + Addon.plugin_url)
  34. Addon.log('plugin queries: ' + str(Addon.plugin_queries))
  35. Addon.log('plugin handle: ' + str(Addon.plugin_handle))
  36.  
  37. mode = Addon.plugin_queries['mode']
  38.  
  39. if mode == 'main':
  40.     Addon.log(mode)
  41.     Addon.add_directory({'mode': 'live'}, Addon.get_string(30001))
  42.     Addon.add_directory({'mode': 'recordings'}, Addon.get_string(30002))
  43.  
  44. elif mode == 'live':
  45.     Addon.log(mode)
  46.     stream_type = ['rtmp', 'rtsp'][int(Addon.get_setting('stream_type'))]
  47.     channels = ustv.get_channels(int(Addon.get_setting('quality')),
  48.                                      stream_type)
  49.     for c in channels:
  50.         episode_airdate = time.strftime('%Y-%m-%d', time.gmtime())
  51.         Addon.add_video_item(c['url'],
  52.                              {'title': '%s - %s' % (c['name'],
  53.                                                     c['now']['title']),
  54.                               'plot': c['now']['plot'],
  55.                               'premiered' : episode_airdate},
  56.                              img=c['icon'])
  57.         xbmcplugin.setContent(Addon.plugin_handle, 'episodes')
  58.  
  59. elif mode == 'recordings':
  60.     Addon.log(mode)
  61.     stream_type = ['rtmp', 'rtsp'][int(Addon.get_setting('stream_type'))]
  62.     recordings = ustv.get_recordings(int(Addon.get_setting('quality')),
  63.                                      stream_type)
  64.     for r in recordings:
  65.       #  print r
  66.         cm_del = (Addon.get_string(30003),
  67.                   'XBMC.RunPlugin(%s/?mode=delete&del=%s)' %
  68.                        (Addon.plugin_url, urllib.quote(r['del_url'])))
  69.         title = '%s (%s)' % (r['title'],  r['channel'])
  70.         episode_airdate = time.strftime('%Y-%m-%d', time.strptime(r['rec_date'].replace('Recorded ',''), '%B %d, %Y'))
  71.         Addon.add_video_item(r['stream_url'], {'title': title,
  72.                                                'plot': r['plot'],
  73.                                                'premiered' : episode_airdate},
  74.                              img=r['icon'], cm=[cm_del], cm_replace=True)
  75.         xbmcplugin.setContent(Addon.plugin_handle, 'episodes')
  76.  
  77. elif mode == 'delete':
  78.     dialog = xbmcgui.Dialog()
  79.     ret = dialog.yesno(Addon.get_string(30000), Addon.get_string(30004),
  80.                        Addon.get_string(30005))
  81.     if ret == 1:
  82.         ustv.delete_recording(Addon.plugin_queries['del'])
  83.    
  84. Addon.end_of_directory()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement