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])
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])
def __init__(self): if len(self._params) == 0: # Scelta tra Audio o Video nw.createAudioVideoItems(self._handle) # Show items. xbmcplugin.endOfDirectory(self._handle) elif len(self._params) == 1 and self._params['content_type'] == 'video': # Visualizzazione del menu video (diretta e video). qlty = int(xbmcplugin.getSetting(self._handle, 'vid_quality')) + 1 streamParam = self._getStreamParam(qlty) if streamParam != None: response = self._getVirginResponse('/video') if response.isSucceeded: title = nw.getTranslation(30003) img = '{0}/resources/images/VirginRadioTV.png'.format(os.path.dirname(os.path.abspath(__file__))) li = nw.createListItem(title, thumbnailImage = img, streamtype = 'video', infolabels = { 'title' : title }) # Diretta. url = 'rtmp://{0}:1935/{1}/{2} app={1} playpath={2} swfUrl=http://video.virginradioitaly.it/com/universalmind/swf/video_player_102.swf?xmlPath=http://video.virginradioitaly.it/com/universalmind/tv/virgin/videoXML.xml&advXML=http://video.virginradioitaly.it/com/universalmind/adsWizzConfig/1.xml pageURL=http://www.virginradio.it swfVfy=true live=true timeout=30 flashVer=LNX 11,2,202,297'.format(streamParam[0], streamParam[1], streamParam[2]) xbmcplugin.addDirectoryItem(self._handle, url, li, False) videos = response.body.findAll('div', 'anteprima_articolo article_cont vrg_article_preview_tree_medium') for video in videos: title = video.a.img['title'] img = self._makeUrl(video.a.img['data-original']).replace('206/122', '600/315') descr = '' if video.h3 != None: descr = video.h3.a.text li = nw.createListItem(title, thumbnailImage = img, streamtype = 'video', infolabels = { 'title' : title, 'plot' : descr }, isPlayable = True) url = nw.formatUrl({ 'id' : 'v', 'page' : video.a['href'].replace('http://www.virginradio.it', '') }) xbmcplugin.addDirectoryItem(self._handle, url, li, False) nw.createNextPageItem(self._handle, 1, { 'id' : 'p', 'page' : 1 }) # Show items. xbmcplugin.endOfDirectory(self._handle) if (streamParam == None or not streamParam) and (response == None or not response or not response.isSucceeded): nw.showNotification(nw.getTranslation(30004)) elif len(self._params) == 1 and self._params['content_type'] == 'audio': # Visualizzazione delle web radio. response = self._getVirginResponse('/webradio') if response.isSucceeded: divs = response.body.findAll('div', { 'class' : re.compile('.+') }) for div in divs: if div['class'].find('overbox_vrg_article_preview_webradio') > -1: radios = div.findAll('div', 'anteprima_articolo article_cont') for radio in radios: title = self._webradioRe.sub('', radio.a.img['title']).strip() img = self._makeImageUrl(radio.a.img['data-original']) li = nw.createListItem(title, thumbnailImage = img, streamtype = 'music', infolabels = { 'title' : title }, isPlayable = True) url = nw.formatUrl({ 'id' : 'r', 'page' : radio.a['href'].replace('http://www.virginradio.it', '') }) xbmcplugin.addDirectoryItem(self._handle, url, li, False) elif div['class'].find('text_edit') > -1 and div['class'].find('vrg_box_title_webradio') > -1 and div['class'].find('last') > -1: break # Stops "for div in divs:". xbmcplugin.endOfDirectory(self._handle) elif self._params['id'] == 'p': response = self._getVirginResponse('/archivio/1099/video?sortElement=data_pubblicazione,true&page={0}'.format(self._params['page'])) if response.isSucceeded: videos = response.body.findAll('div', 'anteprima_ricerca_archivio vrg_archive_results VRG') for video in videos: title = video.a.img['title'] img = self._makeUrl(video.a.img['src']).replace('130/90', '600/315') descr = video.find('p', 'testo').a.text li = nw.createListItem(title, thumbnailImage = img, streamtype = 'video', infolabels = { 'title' : title, 'plot' : descr }, isPlayable = True) url = nw.formatUrl({ 'id' : 'v', 'page' : video.a['href'].replace('http://www.virginradio.it', '') }) xbmcplugin.addDirectoryItem(self._handle, url, li, False) if len(response.body.findAll('a', id='prossimi')) == 1: page = int(self._params['page']) + 1 nw.createNextPageItem(self._handle, page, { 'id' : 'p', 'page' : page }) xbmcplugin.endOfDirectory(self._handle) else: response = self._getVirginResponse(self._params['page']) if response.isSucceeded: # Riproduzione di un video. if self._params['id'] == 'v': title = response.body.find('meta', { 'property' : 'og:title' })['content'] img = response.body.find('meta', { 'property' : 'og:image' })['content'] descr = response.body.find('meta', { 'property' : 'og:description' })['content'] play = response.body.find('a', 'player plain') if play == None: play = response.body.find('div', 'multimedia video') play = re.search('embed/(.+?)\\"', play.renderContents()) if play == None: nw.showVideoNotAvailable() else: play = 'plugin://plugin.video.youtube/play/?video_id={0}'.format(play.group(1)) else: server = re.search('netConnectionUrl: "rtmp://(.+?)/(.+?)/', response.body.renderContents()) play = play['href'] play = re.search('(.+?):(.+)', play) play = 'rtmp://{0}:1935/{1}/{2} app={1} playpath={3}:{2} pageURL=http://www.virginradio.it swfVfy=true live=false flashVer=LNX 10,1,82,76'.format(server.group(1), server.group(2), play.group(2), play.group(1)) nw.playStream(self._handle, title, img, play, 'video', { 'title' : title, 'plot' : descr }) # Riproduzione di una radio. elif self._params['id'] == 'r': stream = re.search("radioUrl_AdsWizz='(.+?)'", response.body.renderContents()) if stream != None: title = self._webradioRe.sub('', response.body.find('meta', { 'property' : 'og:title' })['content']).strip() img = self._makeImageUrl(response.body.find('img', 'lazy')['data-original']) nw.playStream(self._handle, title, img, stream.group(1), 'music', { 'title' : title })
def __init__(self): if len(self._params) == 0: # Visualizzazione del menu. # Shows. title = nw.getTranslation(30000) li = nw.createListItem(title, streamtype = 'video', infolabels = { 'title' : title }) xbmcplugin.addDirectoryItem(self._handle, nw.formatUrl({ 'id' : 'a', 'page' : self._getLaCosaUrl('archivio') }), li, True) shows = nw.getResponseBS(self._getLaCosaUrl('rubriche')) if shows.isSucceeded: shows = shows.body.findAll('div', 'icon_programmi') for show in shows: title = show.h3.a.text li = nw.createListItem(title, thumbnailImage = show.img['src'], streamtype = 'video', infolabels = { 'title' : title, 'plot' : show.p.text }) xbmcplugin.addDirectoryItem(self._handle, nw.formatUrl({ 'id' : 's', 'page' : show.a['href'] }), li, True) xbmcplugin.endOfDirectory(self._handle) if shows == None or not shows: nw.showNotification(nw.getTranslation(30001)) # Errore recupero shows. else: response = nw.getResponseBS(self._params['page']) if response.isSucceeded: # Archivio. if self._params['id'] == 'a': videos = response.body.find('div', id='video-recenti').findAll('div', 'video-block') for video in videos: title = re.search('<a title="(.+?)"', video.renderContents()) if title != None: title = nw.htmlDecode(title.group(1)) time = self._getTime(video) self._setEpItem(video, title, time) if len(videos) > 0: nextPage = response.body.find('span', 'current') nextPage = nextPage.findNext('a') if nextPage.get('class') and nextPage['class'] == 'page-numbers': nw.createNextPageItem(self._handle, nextPage.text, { 'id' : 'a', 'page' : nextPage['href'] }) xbmcplugin.endOfDirectory(self._handle) else: nw.showNotification(nw.getTranslation(30002)) # Errore recupero dei videos shows. # Videos. if self._params['id'] == 's': # Visualizzazione dei videos di uno show. videos = response.body.find('div', id='recenti_canale').findAll('li') for video in videos: title = video.h4.text time = self._getTime(video) self._setEpItem(video, title, time) if len(videos) > 0: xbmcplugin.endOfDirectory(self._handle) else: nw.showNotification(nw.getTranslation(30002)) # Errore recupero dei videos shows. # Play video. elif self._params['id'] == 'v': title = response.body.find('meta', { 'property' : 'og:title' })['content'] img = response.body.find('meta', { 'property' : 'og:image' })['content'] descr = response.body.find('meta', { 'property' : 'og:description' })['content'] streams = response.body.find('iframe') if streams != None: response = nw.getResponseForRegEx(streams['src']) found_stream = None if response.isSucceeded: streams = re.findall('mp4_[0-9]+":"(.*?)",', response.body) if not streams: streams = re.search('hd_src_no_ratelimit":"(.+?)"', response.body) found_stream = streams.group(1).replace('\/', '/') if streams == None: streams = re.search('sd_src_no_ratelimit":"(.+?)"', response.body) found_stream = streams.group(1).replace('\/', '/') if streams == None: streams = re.search('hd_src":"(.+?)"', response.body) found_stream = streams.group(1).replace('\/', '/') if streams == None: streams = re.search('sd_src":"(.+?)"', response.body) found_stream = streams.group(1).replace('\/', '/') if found_stream == None: for stream in reversed(streams): if stream != '': found_stream = stream break if found_stream is not None: nw.playStream(self._handle, title, img, found_stream, 'video', { 'title' : title, 'plot' : descr }) else: nw.showVideoNotAvailable() # Video non disponibile. else: nw.showVideoNotAvailable() # Video non disponibile.
def __init__(self): # Audio, Video, Foto. if len(self._params) == 0: nw.createAudioVideoItems(self._handle, self._fanart) xbmcplugin.addDirectoryItem(self._handle, nw.formatUrl({ 'content_type' : 'image' }), nw.createListItem(nw.getTranslation(30005), thumbnailImage = 'DefaultPicture.png', fanart = self._fanart), True) xbmcplugin.endOfDirectory(self._handle) elif 'content_type' in self._params: # Video. if self._params['content_type'] == 'video': qlty = int(xbmcplugin.getSetting(self._handle, 'vid_quality')) + 1 streamParam = self._getStreamParam(qlty) if streamParam != None: title = nw.getTranslation(30003) img = '{0}/resources/images/VirginRadioTV.png'.format(os.path.dirname(os.path.abspath(__file__))) li = nw.createListItem(title, thumbnailImage = img, fanart = self._fanart, streamtype = 'video', infolabels = { 'title' : title }) # Diretta. url = 'rtmp://{0}:1935/{1}/{2} app={1} playpath={2} swfUrl=http://video.virginradioitaly.it/com/universalmind/swf/video_player_102.swf?xmlPath=http://video.virginradioitaly.it/com/universalmind/tv/virgin/videoXML.xml&advXML=http://video.virginradioitaly.it/com/universalmind/adsWizzConfig/1.xml pageURL=http://www.virginradio.it swfVfy=true live=true timeout=30 flashVer=LNX 11,2,202,297'.format(streamParam[0], streamParam[1], streamParam[2]) xbmcplugin.addDirectoryItem(self._handle, url, li) page_num = 700 addon_page = 2 response = self._getVirginResponse('VideoList.jsp?x_pag={0}&page=1'.format(page_num)) if response.isSucceeded: for video in response.body['videos']: li = self._setVideoListItem(video) nw.createNextPageItem(self._handle, addon_page, { 'action' : 'v', 'page' : page_num + 1, 'page_tot' : response.body['total'], 'addon_page' : addon_page + 1 }, self._fanart) xbmcplugin.endOfDirectory(self._handle) if (streamParam == None or not streamParam) or (response == None or not response or not response.isSucceeded): nw.showNotification(nw.getTranslation(30004)) # Audio. elif self._params['content_type'] == 'audio': xbmcplugin.addDirectoryItem(self._handle, nw.formatUrl({ 'action' : 'r' }), nw.createListItem('Radio', thumbnailImage = 'DefaultFolder.png', fanart = self._fanart), True) xbmcplugin.addDirectoryItem(self._handle, nw.formatUrl({ 'action' : 'p' }), nw.createListItem('Podcast', thumbnailImage = 'DefaultFolder.png', fanart = self._fanart), True) xbmcplugin.endOfDirectory(self._handle) # Foto. elif self._params['content_type'] == 'image': response = self._getVirginResponse('GalleryList.jsp') if response.isSucceeded: response = self._getVirginResponse('GalleryList.jsp?thumbSize=1280x720&x_pag={0}'.format(response.body['total'])) if response.isSucceeded: for gallery in response.body['gallery']: title = self._formatTitle(gallery) img = gallery['thumb'] descr = self._formatDescr(gallery) li = nw.createListItem(title, thumbnailImage = img, fanart = self._fanart, streamtype = 'video', infolabels = { 'title' : title, 'plot' : descr }) xbmcplugin.addDirectoryItem(self._handle, nw.formatUrl({ 'action' : 'f', 'id' : gallery['id'], 'fanart' : img }), li, True) xbmcplugin.endOfDirectory(self._handle) # Video - pagina o riproduzione. elif self._params['action'] == 'v': if 'id' in self._params: response = self._getVirginResponse('Video.jsp?id={0}'.format(self._params['id'])) if response.isSucceeded: video = response.body['videos'] vd = self._getVideoInfo(video) nw.playStream(self._handle, vd['title'], vd['img'], video['file_video'], 'video', { 'title' : vd['title'], 'plot' : vd['descr'] }) elif 'page' in self._params: video_num = 0 page_num = int(self._params['page']) page_tot = int(self._params['page_tot']) addon_page = int(self._params['addon_page']) while video_num < 30 and page_num <= page_tot: response = self._getVirginResponse('VideoList.jsp?x_pag=1&page={0}'.format(page_num), show_error_msg = False) if response.isSucceeded: page_tot = response.body['total'] if response.body['videos'] != None and len(response.body['videos']) > 0: for video in response.body['videos']: li = self._setVideoListItem(video) video_num += 1 page_num += 1 if page_num < page_tot: nw.createNextPageItem(self._handle, addon_page, { 'action' : 'v', 'page' : page_num + 1, 'page_tot' : page_tot, 'addon_page' : addon_page + 1 }, self._fanart) xbmcplugin.endOfDirectory(self._handle) # Video - download. elif self._params['action'] == 'd': response = self._getVirginResponse('Video.jsp?id={0}'.format(self._params['id'])) if response.isSucceeded: video = response.body['videos'] vd = self._getVideoInfo(video) name = ''.join([i if ord(i) < 128 else '' for i in vd['title'].replace(' ', '_')]) name = '{0}.mp4'.format(name) os.chdir(nw.addon.getSetting('download_path')) #~ subprocess.call([nw.addon.getSetting('ffmpeg_path'), '-i', video['file_video'], '-c', 'copy', name]) subprocess.Popen([nw.addon.getSetting('ffmpeg_path'), '-i', video['file_video'], '-c', 'copy', name]) else: nw.showVideoNotAvailable() # Radio elif self._params['action'] == 'r': response = self._getVirginResponse('WebRadioList.jsp') if response.isSucceeded: self._setRadiosListItem(response.body['webradios']['webradioChannel']) self._setRadiosListItem(response.body['webradios']['musicStar']) xbmcplugin.endOfDirectory(self._handle) if response == None or not response or not response.isSucceeded: nw.showNotification(nw.getTranslation(30004)) # Podcast. elif self._params['action'] == 'p': if 'id' in self._params: response = self._getVirginResponse('PodcastAudio.jsp?slug={0}'.format(self._params['id'])) if response.isSucceeded: for podcast in response.body['podcast_audio']['podcasts']: title = self._formatTitle(podcast) li = nw.createListItem(title, fanart = self._params['fanart'], streamtype = 'music', infolabels = { 'title' : title }, isPlayable = True) xbmcplugin.addDirectoryItem(self._handle, podcast['file'], li) else: response = self._getVirginResponse('PodcastAudioList.jsp?imageSize=1280x720') if response.isSucceeded: for podcast in response.body['podcast_audio']: title = podcast['titolo'] img = podcast['immagine'] descr = self._formatDescr(podcast) li = nw.createListItem(title, thumbnailImage = img, fanart = self._fanart, streamtype = 'video', infolabels = { 'title' : title, 'plot' : descr }) xbmcplugin.addDirectoryItem(self._handle, nw.formatUrl({ 'action' : 'p', 'id' : podcast['slug'], 'fanart' : img }), li, True) xbmcplugin.endOfDirectory(self._handle) # Foto. elif self._params['action'] == 'f': response = self._getVirginResponse('Gallery.jsp?id={0}'.format(self._params['id'])) if response.isSucceeded: for idx, photo in enumerate(response.body['gallery']['immagini']): title = '{0} {1}'.format(nw.getTranslation(30005), idx + 1) img = photo['thumb'].replace('100/100', self._def_size_img) li = nw.createListItem(title, thumbnailImage = img, fanart = self._params['fanart'], streamtype = 'image', infolabels = { 'title' : title }) xbmcplugin.addDirectoryItem(self._handle, photo['original'], li) xbmcplugin.endOfDirectory(self._handle)