示例#1
0
    def play(self, videoId):
        api = NetworkTenVideo()
        media = api.get_media_for_video(videoId)
        self.log.debug('Found media renditions for video: %s',
                       repr(media.items))
        if len(media.items):
            # Blindly go for the highest bitrate for now.
            # Later versions could include a customisable setting of which stream to use
            media_sorted = sorted(media.items,
                                  key=lambda m: m.encodingRate,
                                  reverse=True)
            media = media_sorted[0]
            path = media.defaultURL
            self.log.info('Using rendition: %s with url: %s' % (media, path))
        else:
            # Fallback to API FLVFullLength (e.g. for live streams)
            media = api.get_fallback_media_for_video(videoId)
            path = media.remoteUrl
            self.log.info('Using fallback rendition: %s with url: %s' %
                          (media, path))

        if path.startswith('rtmp'):
            path = path.replace('&mp4:', ' playpath=mp4:')
            path += ' swfVfy=true swfUrl=%s pageUrl=%s' % (SWF_URL, PAGE_URL)

        # Set the resolved url, and include media stream info
        item = ListItem.from_dict(path=path)
        item.add_stream_info(
            'video', {
                'codec': media.videoCodec,
                'width': media.frameWidth,
                'height': media.frameHeight
            })
        self.plugin.set_resolved_url(path)
 def __init__(self, plugin=None):
   self.api = NetworkTenVideo()
   self.log = plugin.log
   self.log.debug('Cache TTL set to %d minutes', config.CACHE_TTL)
   self.cache = plugin.get_storage('showlist', TTL=config.CACHE_TTL)
   print repr(self.cache)
  def showlist(self, type):
    api = NetworkTenVideo(self.plugin.cached(TTL=config.CACHE_TTL))
    shows = []
    if 'news' == type:
      for news in api.get_news():
        fanart_url = api.get_fanart(news)

        item = ListItem.from_dict(
          label=news['Title'],
          path=self.url_for('videolist.videolist', explicit=True, query=news['BCQueryForVideoListing'], page='0', fanart=fanart_url),
        )

        if fanart_url:
          item.set_property('fanart_image', fanart_url)

        if 'Thumbnail' in news:
          url = news['Thumbnail']
          if url.startswith('//'):
            url = 'http:' + url
          item.set_thumbnail(url)
        shows.append(item)
    elif 'sport' == type:
      for sport in api.get_sports():
        item = ListItem.from_dict(
          label=sport['Title'],
          path=self.url_for('videolist.videolist', explicit=True, query=sport['BCQueryForVideoListing'], page='0'),
        )
        shows.append(item)
    elif 'live' == type:
      for category in api.get_live_categories():
        fanart_url = None

        if 'fanart' in category:
          fanart_url = category['fanart']

        item = ListItem.from_dict(
          label=category['title'],
          path=self.url_for('videolist.videolist', explicit=True, query=category['query'], page='0', fanart=fanart_url),
        )

        if fanart_url:
          item.set_property('fanart_image', fanart_url)

        if 'thumbnail' in category:
          item.set_thumbnail(category['thumbnail'])

        shows.append(item)
    else: #tvshows
      for show in api.get_shows():
        info_dict = {}
        if show['IsLongFormAvailable'] is not True: #todo: make this a setting
          continue
        if 'Genres' in show and len(show['Genres']):
          info_dict['genre'] = show['Genres'][0]['Name']
        if 'Description' in show:
          info_dict['plot'] = show['Description']
        if 'CurrentSeasonFirstEpisodeAirDateTime' in show:
          try:
            date = time.strptime(show['CurrentSeasonFirstEpisodeAirDateTime'],'%d-%m-%Y %H:%M:%S %p')
            info_dict['aired'] = time.strftime('%Y-%m-%d', date)
            info_dict['premiered'] = time.strftime('%Y-%m-%d', date)
            info_dict['year'] = time.strftime('%Y', date)
          except Exception, e:
            pass
        if 'Channel' in show:
          info_dict['studio'] = show['Channel']
        if 'NumberOfVideosFromBCQuery' in show:
          # not technically correct as this also returns the number of short form as well but close enough
          info_dict['episode'] = show['NumberOfVideosFromBCQuery']

        if 'BCQueryForVideoListing' in show and len(show['BCQueryForVideoListing']):
          query = urlparse.parse_qs(show['BCQueryForVideoListing'], True)
          if 'all' not in query:
            query['all'] = []
          elif not isinstance(query['all'], list):
            query['all'] = [ query['all'] ]
          query['all'].append('video_type_long_form:Full Episode')
        else:
          continue

        fanart_url = api.get_fanart(show)

        item = ListItem.from_dict(
          label=show['Title'],
          path=self.url_for('videolist.videolist', explicit=True, query=urllib.urlencode(query, True), fanart=fanart_url), #ShowPageItemId=show['ShowPageItemId']
          info=info_dict
        )

        if fanart_url:
          item.set_property('fanart_image', fanart_url)

        if 'Thumbnail' in show:
          url = show['Thumbnail']
          if url.startswith('//'):
            url = 'http:' + url
          item.set_thumbnail(url)
        shows.append(item)