Beispiel #1
0
 def _getVideoInfo(self, video, time_zone = None):
     title = u'{0} ({1} {2} - {3} {4})'.format(video['name'], nw.getTranslation(30011), video['seasonNumber'], nw.getTranslation(30012), video['episodeNumber'])
     descr = video['description']
     
     if 'publishEnd' in video:
         if time_zone == None:
             time_zone = nw.gettzlocal()
             date = nw.strptime(video['publishEnd'], '%Y-%m-%dT%H:%M:%SZ')
             date = date.replace(tzinfo = nw.gettz('UTC'))
             date = date.astimezone(time_zone)
             descr = u'{0}\n\n{1} {2}'.format(descr, nw.getTranslation(30013), date.strftime(nw.datetime_format))
     
     plus = False
                         
     if 'packages' in video:
         descr = descr + "\n" + nw.getTranslation(30015) + ":" # cambiare stringa
         for p in video['packages']:
             if p == "Premium" :
                 pp = "Dplay plus"
                 plus = True
                 title = title + " (PLUS)"
             else:
                 pp = p
             
             descr = descr + " " + pp
     
     # aggiungere immagini
     
     return { 'img' : '' , 'title' : title, 'descr' : descr , 'plus' : plus}
Beispiel #2
0
  def __init__(self):
    fanart = nw.addon.getAddonInfo('fanart')

    if len(self._params) == 0:
      response = self._getResponseJson(None)
      if response.isSucceeded:
        #~ for menu in response.body['Menu']:
          #~ if menu['Url'] == None:
            #~ self._addItem(menu['Label'], { 'at' : self._access_token, 'action' : 'm', 'value' : re.sub('\s+', '', menu['Label']) }, fanart = fanart)
        #~ xbmcplugin.endOfDirectory(self._handle)
        response = self._getResponseJson('http://dplayproxy.azurewebsites.net//api/Show/GetList')
        for show in response.body:
          self._addItem(show['Name'], { 'at' : self._access_token, 'action' : 's', 'value' : show['Id'] }, show['Images'][0]['Src'], fanart, show['Description'])
        xbmcplugin.endOfDirectory(self._handle)
    else:
      self._access_token = self._params['at']

      if self._params['action'] == 's':
        response = self._getResponseJson('http://dplayproxy.azurewebsites.net/api/Show/GetById/?id={0}'.format(self._params['value']))
        if response.isSucceeded:
          if len(response.body['Sections']) > 0:
            fanart = response.body['Images'][0]['Src']
            time_zone = nw.gettzlocal()
            haveFFmpeg = os.path.isfile(nw.addon.getSetting('ffmpeg_path')) and os.path.isdir(nw.addon.getSetting('download_path'))
            for video in response.body['Sections'][0]['Items']:
              season_number = video['SeasonNumber']
              for video in video['Episodes']:
                vd = self._getVideoInfo(video, time_zone)
                cm = None
                params = { 'at' : self._access_token, 'action' : 'd', 'value' : video['Id'] }
                if haveFFmpeg:
                  cm = nw.getDownloadContextMenu('RunPlugin({0})'.format(nw.formatUrl(params)), vd['title'])
                params['action'] = 'v'
                self._addItem(vd['title'], params, vd['img'], fanart, vd['descr'], self._getDuration(video['Duration']), True, cm)
            xbmcplugin.endOfDirectory(self._handle)
          else:
            nw.showNotification(nw.getTranslation(30014))

      elif self._params['action'] == 'v':
        result = self._getStream(self._params['value'])
        if not result:
          nw.showVideoNotAvailable()
        else:
          nw.playStream(self._handle, result['title'], result['img'], result['url'], 'video', { 'title' : result['title'], 'plot' : result['descr'] })

      elif self._params['action'] == 'd':
        result = self._getStream(self._params['value'])
        if not result:
          nw.showVideoNotAvailable()
        else:
          name = ''.join([i if ord(i) < 128 else '' for i in result['title'].replace(' ', '_')])
          name = '{0}.ts'.format(name)
          os.chdir(nw.addon.getSetting('download_path'))
          #~ subprocess.call([nw.addon.getSetting('ffmpeg_path'), '-i', result['url'], '-c', 'copy', name])
          subprocess.Popen([nw.addon.getSetting('ffmpeg_path'), '-i', result['url'], '-c', 'copy', name])
Beispiel #3
0
 def _getVideoInfo(self, video, time_zone = None):
   title = u'{0} ({1} {2} - {3} {4})'.format(video['Name'], nw.getTranslation(30011), video['SeasonNumber'], nw.getTranslation(30012), video['EpisodeNumber'])
   descr = video['Description']
   if video['PublishEndDate'] != None:
     if time_zone == None:
       time_zone = nw.gettzlocal()
     date = nw.strptime(video['PublishEndDate'], '%Y-%m-%dT%H:%M:%SZ')
     date = date.replace(tzinfo = nw.gettz('UTC'))
     date = date.astimezone(time_zone)
     descr = u'{0}\n\n{1} {2}'.format(descr, nw.getTranslation(30013), date.strftime(nw.datetime_format))
   return { 'img' : video['Images'][0]['Src'], 'title' : title, 'descr' : descr }
Beispiel #4
0
    def __init__(self):
        fanart = nw.addon.getAddonInfo('fanart')

        if len(self._params) == 0:
            response = self._getResponseJson(None)
            if response.isSucceeded:
                response = self._getResponseJson('https://eu2-prod.disco-api.com/content/shows?sort=name&page[size]=100&include=images', self._getHeaders(True))
        
                pages = response.body["meta"]["totalPages"]
        
                for p in range(1,pages+1):
                    response = self._getResponseJson('https://eu2-prod.disco-api.com/content/shows?sort=name&page[size]=100&include=images&page[number]={0}'.format(p), self._getHeaders(True))

                    imgList = self.loadImagesFromJson(response.body["included"])
                    
                    for show in response.body['data']:
                        attr = show["attributes"]
                        desc = attr['description'] if 'description' in attr else ''
                        title = attr['name']
                        
                        rel = show.get("relationships",{})

                        plus = False 

                        try:
                            packages = rel["contentPackages"]["data"]
                            for p in packages:
                                if p.get("id","") == "Premium" :
                                    pp = "Dplay plus"
                                    plus = True
                                    title = title + " (PLUS)"
                                else:
                                    pp = p
                                
                        
                        except: 
                            pass
                        
                        images = rel.get("images",[])
                        if images:
                            icon_code = images["data"][0]["id"] 
                            
                            if icon_code in imgList:
                                icon = imgList[icon_code]
                            else:
                                icon = ""
                        else:
                            icon = ""                        
                        
                        self._addItem(title, { 'at' : self._access_token, 'action' : 's', 'value' : show['id'] }, icon , fanart, desc)
        
                xbmcplugin.endOfDirectory(self._handle)
        else:
            self._access_token = self._params['at']

            if self._params['action'] == 's':
                url = 'https://eu2-prod.disco-api.com/content/videos?filter[show.id]={0}&page[size]=100&include=images&sort=seasonNumber,episodeNumber&filter[videoType]=EPISODE'.format(self._params['value'])
                xbmc.log("Dplay. OPEN URL: %s" % url)
                response = self._getResponseJson(url, self._getHeaders(True))
                if response.isSucceeded:

                    #if len(response.body['Sections']) > 0:
                    #    fanart = response.body['Images'][0]['Src']
                    fanart = ""  # da aggiustare
                    time_zone = nw.gettzlocal()
                    haveFFmpeg = os.path.isfile(nw.addon.getSetting('ffmpeg_path')) and os.path.isdir(nw.addon.getSetting('download_path'))

                    xbmc.log("Dplay. start reading images")
                    imgList = self.loadImagesFromJson(response.body["included"])
                    xbmc.log("Dplay. end reading images")
                    
                    for video in response.body["data"]:
                        attr = video["attributes"]
                        season_number = attr.get("seasonNumber", 0)
                        episode_number = attr.get("episodeNumber",0)

                        vd = self._getVideoInfo(attr, time_zone)
                        
                        rel = video.get("relationships",{})
                        images = rel.get("images",[])
                        if images:
                            icon_code = images["data"][0]["id"] 
                            
                            if icon_code in imgList:
                                icon = imgList[icon_code]
                            else:
                                icon = ""
                        else:
                            icon = ""                        
                        
                        cm = nw.getDownloadContextMenu('RunPlugin({0})'.format(nw.formatUrl(params)), vd['title']) if haveFFmpeg else None
                        params = { 'at' : self._access_token, 'action' : 'v', 'value' : video['id'] } #'v' instead of 'd'
                        #params['action'] = 'v'
                        self._addItem(vd['title'], params, icon, icon, vd['descr'], self._getDuration(attr["videoDuration"]), True, cm)
                        xbmcplugin.setContent(self._handle, 'episodes')
                    xbmcplugin.endOfDirectory(self._handle)
                else:
                    nw.showNotification(nw.getTranslation(30014))

            elif self._params['action'] == 'v':
                result = self._getStream(self._params['value'])
                if not result:
                    nw.showVideoNotAvailable()
                else:
                    # Force XBMC to set the User-Agent HTTP header to the correct value
                    result_url = result['url'] + "|User-Agent=%s" % Dplay.USER_AGENT

                    nw.playStream(self._handle, result['title'], result['img'], result_url,
                        'video', { 'title' : result['title'], 'plot' : result['descr'] })

            elif self._params['action'] == 'd':
                result = self._getStream(self._params['value'])
                if not result:
                    nw.showVideoNotAvailable()
                else:
                    name = ''.join([i if ord(i) < 128 else '' for i in result['title'].replace(' ', '_')])
                    name = '{0}.ts'.format(name)
                    os.chdir(nw.addon.getSetting('download_path'))
                    #~ subprocess.call([nw.addon.getSetting('ffmpeg_path'), '-i', result['url'], '-c', 'copy', name])
                    subprocess.Popen([nw.addon.getSetting('ffmpeg_path'), '-user-agent', Dplay.USER_AGENT, '-i', result['url'], '-c', 'copy', name])