class Dplay(object): _handle = int(sys.argv[1]) _params = Util.urlParametersToDict(sys.argv[2]) def __init__(self): # Shows. if len(self._params) == 0: self._getShowsPage( 0, xbmcplugin.getSetting(self._handle, 'items_per_page')) # Seasons. elif self._params['action'] == 's': headers = { 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.1.1; D6503 Build/23.4.A.0.546)' } url = 'http://it.dplay.com/api/v1/content/device/shows/{0}/seasons?realm=DPLAYIT&appVersion=2.0.0&platform=ANDROID&platformVersion=5.1.1'.format( self._params['showid']) seasons = Util.getResponseJson(url, headers) if seasons.isSucceeded: if xbmcplugin.getSetting(self._handle, 'show_seasons') == 'false' or len( seasons.body['data']) > 1: for season in seasons.body['data']: title = Util.getTranslation(30010).format( season=season['name'], numberof=season['episodes_available'], numbertot=season['episodes_total']) li = Util.createListItem( title, thumbnailImage='DefaultFolder.png', streamtype='video', infolabels={'title': title}) xbmcplugin.addDirectoryItem( self._handle, Util.formatUrl({ 'action': 'e', 'showid': self._params['showid'], 'seasonid': season['id'] }), li, True) xbmcplugin.endOfDirectory(self._handle) else: self._getEpisodes(self._params['showid'], seasons.body['data'][0]['id']) # Episodes. elif self._params['action'] == 'e': self._getEpisodes(self._params['showid'], self._params['seasonid']) # Play video. elif self._params['action'] == 'v': stream = Util.getResponseForRegEx(self._params['url']) if stream.isSucceeded: qlySetting = xbmcplugin.getSetting(self._handle, 'vid_quality') if qlySetting == '0': qlySetting = 180 elif qlySetting == '1': qlySetting = 270 elif qlySetting == '2': qlySetting = 360 elif qlySetting == '3': qlySetting = 432 elif qlySetting == '4': qlySetting = 576 elif qlySetting == '5': qlySetting = 720 elif qlySetting == '6': qlySetting = 1080 urls = re.findall('RESOLUTION=.+?x(.+?),CODECS=".+?"(.+?)#', stream.body) items = [] for qly, url in urls: items.append((abs(qlySetting - int(qly)), url)) items = sorted(items, key=lambda item: item[0]) Util.playStream(self._handle, '', path=items[0][1]) def _getShowsPage(self, Page, Items): shows = Util.getResponseJson( 'http://it.dplay.com/api/v2/ajax/modules?items={0}&page_id=32&module_id=26&page={1}' .format(Items, Page)) if shows.isSucceeded: for show in shows.body['data']: episodes = 0 for ti in show['taxonomy_items']: if ti['type'] == 'show': episodes = ti['metadata']['episodes'] break # Stops "for ti in show['taxonomy_items']:". title = Util.getTranslation(30009).format(show=show['title'], number=episodes) img = show['image_data'] li = Util.createListItem(title, thumbnailImage=self._getImage(img), streamtype='video', infolabels={ 'title': title, 'plot': show['description'] }) xbmcplugin.addDirectoryItem( self._handle, Util.formatUrl({ 'action': 's', 'showid': show['id'] }), li, True) pages = shows.body['total_pages'] if Page < pages - 1: self._getShowsPage(Page + 1, Items) else: xbmcplugin.endOfDirectory(self._handle) def _getEpisodes(self, showId, seasonId): url = 'http://it.dplay.com/api/v2/ajax/shows/{0}/seasons/{1}?show_id={0}&items=50&sort=episode_number_asc&video_types=-clip&season_id={1}'.format( showId, seasonId) episodes = Util.getResponseJson(url) if episodes.isSucceeded: for episode in episodes.body['data']: if episode['title'].lower().find('episodio') > -1: title = episode['title'] else: title = Util.getTranslation(30011).format( episode=episode['title'], number=episode['episode']) img = episode['image_data'] desc = episode['description'] or episode[ 'video_metadata_longDescription'] time = self._getDuration(int(episode['video_metadata_length'])) li = Util.createListItem(title, thumbnailImage=self._getImage(img), streamtype='video', infolabels={ 'title': title, 'plot': desc }, duration=time, isPlayable=True) xbmcplugin.addDirectoryItem( self._handle, Util.formatUrl({ 'action': 'v', 'url': episode['hls'] }), li) xbmcplugin.endOfDirectory(self._handle) def _getImage(self, image): if image is not None: return u'{0}c_fill,h_246,w_368/{1}'.format( 'http://res.cloudinary.com/db79cecgq/image/upload/', image['file']) else: return 'DefaultVideo.png' def _getDuration(self, milliseconds): return str(timedelta(milliseconds / 1000.0))
class MTV(object): _handle = int(sys.argv[1]) _params = Util.urlParametersToDict(sys.argv[2]) def __init__(self): # Programmi. if len(self._params) == 0: shows = self._getMTVResponse('/serie-tv') if shows.isSucceeded: shows = shows.body.findAll('h3', 'showpass') for show in shows: name = show.nextSibling.strong.text img = show.img['data-original'] index = img.rfind('?') show.nextSibling.strong.extract() li = Util.createListItem(name, thumbnailImage=img[:index], streamtype='video', infolabels={ 'title': name, 'plot': show.nextSibling.text }) xbmcplugin.addDirectoryItem( self._handle, Util.formatUrl({ 'action': 's', 'path': show.a['href'] }), li, True) xbmcplugin.endOfDirectory(self._handle) # Stagioni. elif self._params['action'] == 's': response = self._getMTVResponse(self._params['path']) if response.isSucceeded: if response.body.renderContents().find( '<h2>Troppo tardi! <b>☻</b></h2>') == -1: seasons = response.body.find('ul', 'nav').findAll('a') if xbmcplugin.getSetting( self._handle, 'show_seasons') == 'false' or len(seasons) > 1: title = response.body.find('h1', { 'itemprop': 'name' }).text for season in seasons: link = season['href'] season = season.text li = Util.createListItem(season, streamtype='video', infolabels={ 'title': season, 'plot': '{0} di {1}'.format( season, title) }) xbmcplugin.addDirectoryItem( self._handle, Util.formatUrl({ 'action': 'p', 'path': link }), li, True) xbmcplugin.endOfDirectory(self._handle) else: self._getEpisodes(seasons[0]['href']) else: xbmcgui.Dialog().ok( Util._addonName, Util.getTranslation(30000) ) # Troppo tardi! I diritti di questo video sono scaduti. # Puntate. elif self._params['action'] == 'p': self._getEpisodes(self._params['path']) # Risoluzioni. elif self._params['action'] == 'r': videoId = Util.getResponseBS(self._params['path']) if videoId.isSucceeded: videoId = videoId.body.find('div', 'MTVNPlayer') if videoId != None: qlySetting = xbmcplugin.getSetting(self._handle, 'vid_quality') if qlySetting == '0': qlySetting = 180 elif qlySetting == '1': qlySetting = 270 elif qlySetting == '2': qlySetting = 360 elif qlySetting == '3': qlySetting = 432 elif qlySetting == '4': qlySetting = 576 elif qlySetting == '5': qlySetting = 720 elif qlySetting == '6': qlySetting = 1080 videoId = videoId['data-contenturi'] response = Util.getResponseBS( 'http://intl.esperanto.mtvi.com/www/xml/media/mediaGen.jhtml?uri=mgid:uma:video:mtv.it{0}' .format(videoId[videoId.rfind(':'):])) if response.isSucceeded: response = response.body.findAll('rendition') streams = [] for stream in response: streams.append( (abs(qlySetting - int(stream['height'])), stream.src.text)) streams = sorted(streams, key=lambda stream: stream[0]) Util.playStream(self._handle, '', path=streams[0][1]) #for duration, bitrate, url in streams: # title = Util.getTranslation(idLabel) # idLabel += 1 # li = Util.createListItem(title, streamtype = 'video', infolabels = { 'title' : title }, duration = duration) # xbmcplugin.addDirectoryItem(self._handle, '{0} swfUrl=http://media.mtvnservices.com/player/prime/mediaplayerprime.2.3.7.swf?uri={1}.swf swfVfy=true'.format(url, self._params['path']), li, False) #xbmcplugin.endOfDirectory(self._handle) else: xbmcgui.Dialog().ok(Util._addonName, Util.showVideoNotAvailableDialog() ) # Video non disponibile. def _getMTVResponse(self, link): return Util.getResponseBS('http://ondemand.mtv.it{0}'.format(link)) def _getEpisodes(self, path): index = path.rfind('/') videos = self._getMTVResponse('{0}.rss'.format(path[:index])) if videos.isSucceeded: videos = videos.body.findAll('item') season = '{0}/'.format(path[index:]) for video in videos: if video.link.nextSibling.find(season) > -1: name = video.title.text img = video.enclosure['url'] iResEnd = img.rfind('.') iResStart = iResEnd - 3 if img[iResStart:iResEnd] == '140': img = '{0}640{1}'.format(img[:iResStart], img[iResEnd:]) li = Util.createListItem(name, thumbnailImage=img, streamtype='video', infolabels={ 'title': name, 'plot': video.description.text }, isPlayable=True) xbmcplugin.addDirectoryItem( self._handle, Util.formatUrl({ 'action': 'r', 'path': video.link.nextSibling }), li) xbmcplugin.endOfDirectory(self._handle)