def ExportVideoList(self, url): xml = common.getFEED(url) tree = ElementTree.XML(xml) items = tree.findall('item') del tree for item in items: self.ExportVideo(item)
def convert_subtitles(self, url): xml = common.getFEED(url) tree = ElementTree.XML(xml) lines = tree.find('BODY').findall('SYNC') srt_output = '' count = 1 displaycount = 1 for line in lines: if (line.get('Encrypted') == 'true'): sub = self.decrypt_subs(line.text) else: sub = line.text sub = self.clean_subs(sub) if sub == '': count += 1 continue start = self.convert_time(int(line.get('start'))) if count < len(lines): end = self.convert_time(int(lines[count].get('start'))) line = str(displaycount ) + "\n" + start + " --> " + end + "\n" + sub + "\n\n" srt_output += line count += 1 displaycount += 1 return srt_output
def ExportVideoList(self,url): xml=common.getFEED(url) tree = ElementTree.XML(xml) items = tree.findall('item') del tree for item in items: self.ExportVideo(item)
def getIDS4HTTP(self, url): pagedata = common.getFEED(url) common.args.videoid = url.split('watch/')[1].split('/')[0] content_id = re.compile('so.addVariable\("content_id", (.*?)\);' ).findall(pagedata)[0].strip() common.args.eid = self.cid2eid(content_id) return content_id
def ExportShowList(self,url,delay=0): xml=common.getFEED(url) tree = ElementTree.XML(xml) items = tree.findall('item') del tree for item in items: self.ExportShowMovie(item) xbmc.sleep(delay)
def ExportShowList(self, url, delay=0): xml = common.getFEED(url) tree = ElementTree.XML(xml) items = tree.findall('item') del tree for item in items: self.ExportShowMovie(item) xbmc.sleep(delay)
def getTotalCount( self, itemsurl ): if '?' in itemsurl: itemsurl += '&dp_id='+dp_id+'&package_id='+package_id+'&total=1' else: itemsurl += '?dp_id='+dp_id+'&package_id='+package_id+'&total=1' xml=common.getFEED(itemsurl) tree = ElementTree.XML(xml) if tree.findtext('total_count') == "": return 0 else: return int(tree.findtext('total_count'))
def getTotalCount(self, itemsurl): if '?' in itemsurl: itemsurl += '&dp_id=' + dp_id + '&package_id=' + package_id + '&total=1' else: itemsurl += '?dp_id=' + dp_id + '&package_id=' + package_id + '&total=1' xml = common.getFEED(itemsurl) tree = ElementTree.XML(xml) if tree.findtext('total_count') == "": return 0 else: return int(tree.findtext('total_count'))
def checkCaptions(self, video_id): subtitles = os.path.join(common.subtitlepath,video_id+'.srt') if os.path.isfile(subtitles): log( "HULU --> Using Cached Subtitles") else: url = 'http://www.hulu.com/captions?content_id='+video_id xml = common.getFEED(url) tree = ElementTree.XML(xml) hasSubs = tree.findtext('en') if(hasSubs): log( "HULU --> Grabbing subtitles...") subtitles = self.convert_subtitles(hasSubs) common.SaveFile(os.path.join(common.subtitlepath,video_id+'.srt'), subtitles) log( "HULU: --> Successfully converted subtitles to SRT") else: log( "HULU --> No subtitles available.")
def NetworkPreroll( self ): url = 'http://r.hulu.com/videos?eid='+common.args.eid+'&include=video_assets&include_eos=1&_language=en&_package_group_id=1&_region=US' data=common.getFEED(url) tree=BeautifulStoneSoup(data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) networkPreroll = tree.find('show').find('link-url').string if networkPreroll is not None: if '.flv' in networkPreroll: name = tree.find('channel').string infoLabels={ "Title":name } item = xbmcgui.ListItem(name+' Intro',path=networkPreroll) item.setInfo( type="Video", infoLabels=infoLabels) if self.queue: item.setProperty('IsPlayable', 'true') common.playlist.add(url=networkPreroll, listitem=item) else: self.queue = True xbmcplugin.setResolvedUrl(common.handle, True, item)
def getSMIL(self, video_id, retry=0): epoch = int(time.mktime(time.gmtime())) parameters = { 'video_id': video_id, 'v': '888324234', 'ts': str(epoch), 'np': '1', 'vp': '1', 'enable_fa': '1', 'device_id': self.GUID, 'pp': 'Desktop', 'dp_id': 'Hulu', 'region': 'US', 'ep': '1', 'language': 'en' } if retry > 0: parameters['retry'] = str(retry) if common.settings['enable_login'] == 'true' and common.settings[ 'enable_plus'] == 'true' and common.settings['usertoken']: parameters['token'] = common.settings['usertoken'] smilURL = False for item1, item2 in parameters.iteritems(): if not smilURL: smilURL = 'http://s.hulu.com/select?' + item1 + '=' + item2 else: smilURL += '&' + item1 + '=' + item2 smilURL += '&bcs=' + self.content_sig(parameters) log('HULU --> SMILURL: ' + smilURL) if common.settings['proxy_enable'] == 'true': proxy = True else: proxy = False smilXML = common.getFEED(smilURL, proxy=proxy) if smilXML: smilXML = self.decrypt_SMIL(smilXML) log("GOT SMIL") if smilXML: smilSoup = BeautifulStoneSoup( smilXML, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) log(smilSoup.prettify()) return smilSoup else: return False else: return False
def NetworkPreroll(self): url = 'http://r.hulu.com/videos?eid=' + common.args.eid + '&include=video_assets&include_eos=1&_language=en&_package_group_id=1&_region=US' data = common.getFEED(url) tree = BeautifulStoneSoup( data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) networkPreroll = tree.find('show').find('link-url').string if networkPreroll is not None: if '.flv' in networkPreroll: name = tree.find('channel').string infoLabels = {"Title": name} item = xbmcgui.ListItem(name + ' Intro', path=networkPreroll) item.setInfo(type="Video", infoLabels=infoLabels) if self.queue: item.setProperty('IsPlayable', 'true') common.playlist.add(url=networkPreroll, listitem=item) else: self.queue = True xbmcplugin.setResolvedUrl(common.handle, True, item)
def checkCaptions(self, video_id): subtitles = os.path.join(common.subtitlepath, video_id + '.srt') if os.path.isfile(subtitles): log("HULU --> Using Cached Subtitles") else: url = 'http://www.hulu.com/captions?content_id=' + video_id xml = common.getFEED(url) tree = ElementTree.XML(xml) hasSubs = tree.findtext('en') if (hasSubs): log("HULU --> Grabbing subtitles...") subtitles = self.convert_subtitles(hasSubs) common.SaveFile( os.path.join(common.subtitlepath, video_id + '.srt'), subtitles) log("HULU: --> Successfully converted subtitles to SRT") else: log("HULU --> No subtitles available.")
def getSMIL(self, video_id,retry=0): epoch = int(time.mktime(time.gmtime())) parameters = {'video_id' : video_id, 'v' : '888324234', 'ts' : str(epoch), 'np' : '1', 'vp' : '1', 'enable_fa' : '1', 'device_id' : self.GUID, 'pp' : 'Desktop', 'dp_id' : 'Hulu', 'region' : 'US', 'ep' : '1', 'language' : 'en' } if retry > 0: parameters['retry']=str(retry) if common.settings['enable_login']=='true' and common.settings['enable_plus']=='true' and common.settings['usertoken']: parameters['token'] = common.settings['usertoken'] smilURL = False for item1, item2 in parameters.iteritems(): if not smilURL: smilURL = 'http://s.hulu.com/select?'+item1+'='+item2 else: smilURL += '&'+item1+'='+item2 smilURL += '&bcs='+self.content_sig(parameters) log( 'HULU --> SMILURL: ' + smilURL) if common.settings['proxy_enable'] == 'true': proxy=True else: proxy=False smilXML=common.getFEED(smilURL,proxy=proxy) if smilXML: smilXML=self.decrypt_SMIL(smilXML) log( "GOT SMIL") if smilXML: smilSoup=BeautifulStoneSoup(smilXML, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) log( smilSoup.prettify()) return smilSoup else: return False else: return False
def addMainHomeItems( self ): xml=common.getFEED(common.BASE_MENU_URL) tree = ElementTree.XML(xml) menuitems = tree.findall('item') fanart = common.hulu_fanart for item in menuitems: display= item.findtext('display') items_url='http://m.hulu.com'+item.findtext('items_url') cmtype=item.find('app_data').findtext('cmtype') thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon.png")) cm = [] if cmtype == 'None' or display == 'Help' or display == 'Profiles' or display == 'Now Playing': continue elif display =='Popular': thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon_popular.jpg")) cm.append( ('Export Popular Shows', "XBMC.RunPlugin(%s?mode='ForcePopularShowsLibrary')" % ( sys.argv[0] ) ) ) cm.append( ('Export Popular Movies', "XBMC.RunPlugin(%s?mode='ForcePopularMoviesLibrary')" % ( sys.argv[0] ) ) ) cm.append( ('Export Popular Episodes', "XBMC.RunPlugin(%s?mode='ForcePopularEpisodesLibrary')" % ( sys.argv[0] ) ) ) elif display =='Recently Added': thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon_recently_added.jpg")) elif display == 'TV': cm.append( ('Export All Full Shows', "XBMC.RunPlugin(%s?mode='ForceFullShowsLibrary')" % ( sys.argv[0] ) ) ) thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon_tv.jpg")) elif display == 'Movies': cm.append( ('Export All Full Movies', "XBMC.RunPlugin(%s?mode='ForceFullMoviesLibrary')" % ( sys.argv[0] ) ) ) thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon_movies.jpg")) elif display == 'Search': thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon_search.jpg")) common.addDirectory(display,items_url,cmtype,thumbnail,thumbnail,fanart=fanart,page='1',perpage='25',cm=cm) if common.settings['enable_login']=='true': if not os.path.isfile(common.QUEUETOKEN): common.login_queue() thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon_queue.jpg")) cm = [ ('Add Queue to Library', "XBMC.RunPlugin(%s?mode='ForceQueueLibrary')" % ( sys.argv[0] ) ) ] cm.append( ('Clear Library Directory', "XBMC.RunPlugin(%s?mode='ClearLibrary')" % ( sys.argv[0] ) ) ) common.addDirectory('Queue' ,'http://m.hulu.com/menu/hd_user_queue' , 'Queue' ,thumbnail,thumbnail,fanart=fanart,page='1',perpage='2000',cm=cm) thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon_subscriptions.jpg")) cm = [ ('Add Subscriptions to Library', "XBMC.RunPlugin(%s?mode='ForceSubscriptionsLibrary')" % ( sys.argv[0] ) ) ] cm.append( ('Clear Library Directory', "XBMC.RunPlugin(%s?mode='ClearLibrary')" % ( sys.argv[0] ) ) ) common.addDirectory('Subscriptions' ,'http://m.hulu.com/menu/hd_user_subscriptions' , 'Subscriptions' ,thumbnail,thumbnail,fanart=fanart,page='1',perpage='2000',cm=cm) thumbnail = xbmc.translatePath(os.path.join(common.imagepath,"icon_history.jpg")) common.addDirectory('History' ,'http://m.hulu.com/menu/hd_user_history' , 'History' ,thumbnail,thumbnail,fanart=fanart,page='1',perpage='2000')
def convert_subtitles(self, url): xml=common.getFEED(url) tree = ElementTree.XML(xml) lines = tree.find('BODY').findall('SYNC') srt_output = '' count = 1 displaycount = 1 for line in lines: if(line.get('Encrypted') == 'true'): sub = self.decrypt_subs(line.text) else: sub = line.text sub = self.clean_subs(sub) if sub == '': count += 1 continue start = self.convert_time(int(line.get('start'))) if count < len(lines): end = self.convert_time(int(lines[count].get('start'))) line = str(displaycount)+"\n"+start+" --> "+end+"\n"+sub+"\n\n" srt_output += line count += 1 displaycount += 1 return srt_output
def addMenuItems( self, perpage, pagenumber ,url=common.args.url ): # Grab xml item list orginalUrl = url if '?' in url: url += '&' else: url += '?' noCache = False if 'Queue' == common.args.mode or 'Subscriptions' == common.args.mode or 'History' == common.args.mode: usertoken = common.settings['usertoken'] url += 'dp_id='+dp_id+'&limit='+perpage+'&package_id='+package_id+'&user_id='+usertoken noCache = True total_count = 0 else: url += 'dp_id='+dp_id+'&package_id='+package_id+'&limit='+perpage+'&page='+pagenumber total_count = self.getTotalCount( orginalUrl ) if noCache: xml = common.getFEED(url) else: xml=common.getFEED(url) while xml == False: if noCache: xml = common.getFEED(url) else: xml=common.getFEED(url) #xbmc.sleep(400) # Add Next/Prev Pages count = 0 if int(perpage) < int(total_count): if 'Popular' in common.args.name or 'Featured' in common.args.name or 'Recently' in common.args.name: popular='true' else: try: popular = common.args.popular except: popular='false' current_page = int(pagenumber) next_page = int(pagenumber)+1 prev_page = int(pagenumber)-1 npage_begin = int(perpage)*current_page + 1 npage_end = int(perpage)*next_page if total_count < npage_end: npage_end = total_count if npage_begin < total_count: next_name = 'Next Page ('+str(npage_begin)+'-'+str(npage_end)+' of '+str(total_count)+')' nextthumb=xbmc.translatePath(os.path.join(common.imagepath,"next.png")) common.addDirectory(next_name,url,common.args.mode,page=str(next_page),icon=nextthumb,perpage=perpage,popular=popular,fanart=common.hulu_fanart,updatelisting='true') if prev_page > 0: ppage_begin = int(perpage)*(prev_page-1)+1 ppage_end = int(perpage)*prev_page prev_name = 'Previous Page ('+str(ppage_begin)+'-'+str(ppage_end)+' of '+str(total_count)+')' prevthumb=xbmc.translatePath(os.path.join(common.imagepath,"prev.png")) common.addDirectory(prev_name,url,common.args.mode,page=str(prev_page),icon=prevthumb,perpage=perpage,popular=popular,fanart=common.hulu_fanart,updatelisting='true') tree = ElementTree.XML(xml) menuitems = tree.findall('item') del tree hasMovies = False hasEpisodes = False hasTVShows = False for item in menuitems: display=item.findtext('display').encode('utf-8') displayname=display url='http://m.hulu.com'+item.findtext('items_url') mode=item.find('app_data').findtext('cmtype') #Flatten All and Alphabetical if display == 'All' and total_count == 1: return self.addMenuItems(common.settings['allperpage'],common.args.page,url) # Skip unwanted menu items elif mode == 'None' or display == 'Add to queue' or display == 'Subscriptions': continue #set Data isVideo = False if common.args.fanart and common.args.fanart <> '': fanart = common.args.fanart else: fanart = common.hulu_fanart if common.args.art <> '': art = common.args.art elif 'Popular' in common.args.name or 'Popular' in display: art = xbmc.translatePath(os.path.join(common.imagepath,"icon_popular.jpg")) elif 'Recently' in common.args.name or 'Recently' in display: art = xbmc.translatePath(os.path.join(common.imagepath,"icon_recently_added.jpg")) elif 'TV' == common.args.name: art = xbmc.translatePath(os.path.join(common.imagepath,"icon_tv.jpg")) elif 'Movies' == common.args.name: art = xbmc.translatePath(os.path.join(common.imagepath,"icon_movies.jpg")) else: art = common.hulu_icon infoLabels={'Title':display} show_id = False ishd = False data = item.find('data') if data: #data = data[0] canonical_name = data.findtext('canonical_name') show_canonical_name = data.findtext('show_canonical_name') #Show Only if canonical_name: infoLabels['TVShowTitle'] = data.findtext('name').encode('utf-8') infoLabels['Genre'] = data.findtext('genre', default="") totalEpisodes = data.findtext('full_episodes_count') if totalEpisodes: infoLabels['Episode'] = int(totalEpisodes) totalSeasons = data.findtext('total_seasons_count') parent_id = data.findtext('parent_id') if parent_id: displayname = '- '+displayname art = "http://assets.hulu.com/shows/key_art_"+canonical_name.replace('-','_')+".jpg" #Video Only elif show_canonical_name: isVideo = True canonical_name = show_canonical_name content_id = data.findtext('content_id') video_id = data.findtext('video_id') eid = data.findtext('eid') media_type = data.findtext('media_type') art = data.findtext('thumbnail_url_16x9_large') infoLabels['TVShowTitle'] = data.findtext('show_name').encode('utf-8') infoLabels['Genre'] = data.findtext('parent_channel_name', default="") infoLabels['MPAA'] = data.findtext('content_rating') votes_data = data.findtext('votes_count') seasondata = data.findtext('season_number') if seasondata.isdigit(): infoLabels['Season'] = int(seasondata) else: infoLabels['Season'] = 0 episodedata = data.findtext('episode_number') if episodedata.isdigit(): infoLabels['Episode'] = int(episodedata) else: infoLabels['Episode'] = 0 durationseconds = int(float(data.findtext('duration'))) infoLabels['Duration'] = str(datetime.timedelta(seconds=durationseconds)) #Both Show and Video plot=data.findtext('description') if plot: plot = unicode(plot.replace('\n', ' ').replace('\r', ' ')).encode('utf-8') else: plot = '' plus_only=data.findtext('plus_only') if plus_only == 'True': plus_web_expires_at=data.findtext('plus_web_expires_at') if plus_web_expires_at: plot = 'Plus Expires: '+plus_web_expires_at.replace(' 00:00:00','')+'\n'+plot else: expires_at=data.findtext('expires_at') if expires_at: plot = 'Expires: '+expires_at.replace(' 00:00:00','')+'\n'+plot else: composite_expires_at=data.findtext('composite_expires_at') if composite_expires_at: plot = 'Expires: '+composite_expires_at.replace(' 00:00:00','')+'\n'+plot infoLabels['Plot'] = plot premiered = data.findtext('original_premiere_date') if premiered: premiered = premiered.split(' ')[0] infoLabels['Premiered'] = premiered datesplit=premiered.split('-') infoLabels['date'] = datesplit[2]+'.'+datesplit[1]+'.'+datesplit[0] infoLabels['Year'] = int(premiered.split('-')[0]) rating = data.findtext('rating') if rating: #if rating.isdigit(): infoLabels['Rating'] = float(rating)*2 company_name = data.findtext('company_name', default="") infoLabels['Studio'] = company_name ishd = data.findtext('has_hd') language = data.findtext('language', default="").upper() hascaptions=data.findtext('has_captions') show_id = data.findtext('show_id') if canonical_name: fanart = "http://assets.hulu.com/shows/key_art_"+canonical_name.replace('-','_')+".jpg" if mode == 'SeasonMenu': xbmcplugin.setContent(pluginhandle, 'seasons') dtotal_count = self.getTotalCount( url ) #displayname = displayname + ' ('+str(dtotal_count)+')' episode_number = dtotal_count isVideo = False elif mode == 'ShowPage': xbmcplugin.setContent(pluginhandle, 'tvshows') hasTVShows = True isVideo = False elif common.args.mode == 'ChannelMenu': xbmcplugin.setContent(pluginhandle, 'tvshows') fanart = common.hulu_fanart art = common.hulu_icon elif common.args.mode == 'ShowPage': xbmcplugin.setContent(pluginhandle, 'episodes') dtotal_count = self.getTotalCount( url ) episode_number = dtotal_count displayname = displayname + ' ('+str(dtotal_count)+')' if dtotal_count == 0: continue #Set Networks and Studios fanart elif common.args.name == 'Networks' or common.args.name == 'Studios': xbmcplugin.setContent(pluginhandle, 'tvshows') canonical_name = self.remove_accents(canonical_name.encode('utf-8')) fanart = "http://assets.huluim.com/companies/key_art_"+canonical_name.replace('-','_')+".jpg" art = fanart #Add Count to Display Name for Non-Show/Episode Lists elif common.args.mode == 'Menu' and isVideo == False: dtotal_count = self.getTotalCount( url ) if dtotal_count <> 1: displayname = displayname + ' ('+str(dtotal_count)+')' elif dtotal_count == 0: continue #Set Final Video Name elif isVideo == True: url=content_id #URL of video #url="http://www.hulu.com/watch/"+videoid mode = 'TV_play' if media_type == 'TV': xbmcplugin.setContent(pluginhandle, 'episodes') hasEpisodes = True elif media_type == 'Film': xbmcplugin.setContent(pluginhandle, 'episodes') hasMovies = True #infoLabels['TVShowTitle'] = company_name #xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_EPISODE) if infoLabels['Season'] <> 0 and infoLabels['Episode'] <> 0: if 'Popular' in common.args.name or 'Featured' in common.args.name or 'Recently' in common.args.name or 'Queue' == common.args.mode or 'History' == common.args.mode or common.args.popular == 'true': displayname = infoLabels['TVShowTitle']+' - '+str(infoLabels['Season'])+'x'+str(infoLabels['Episode'])+' - '+display else: displayname = str(infoLabels['Season'])+'x'+str(infoLabels['Episode'])+' - '+display if 'EN' <> language: displayname += ' ('+language+')' if 'True' == ishd: displayname += ' (HD)' u = sys.argv[0] u += '?url="'+urllib.quote_plus(url)+'"' u += '&mode="'+urllib.quote_plus(mode)+'"' item=xbmcgui.ListItem(displayname, iconImage=art, thumbnailImage=art) infoLabels['Title']=displayname infoLabels['count']=count count += 1 item.setInfo( type="Video", infoLabels=infoLabels) item.setProperty('fanart_image',fanart) #Set total count if int(perpage) < int(total_count): total_items = int(perpage) elif int(perpage) < len(menuitems): total_items = len(menuitems) else: total_items = int(total_count) cm = [] if isVideo == False: u += '&name="'+urllib.quote_plus(display.replace("'",""))+'"' u += '&art="'+urllib.quote_plus(art)+'"' u += '&fanart="'+urllib.quote_plus(fanart)+'"' u += '&page="1"' u += '&popular="false"' u += '&updatelisting="false"' if common.settings['enable_login']=='true' and common.settings['usertoken']: if 'Subscriptions' == common.args.mode: cm.append( ('Remove Subscription', "XBMC.RunPlugin(%s?mode='removesub'&url=%s)" % ( sys.argv[0], show_id ) ) ) elif show_id <> '': cm.append( ('Add to Subscriptions', "XBMC.RunPlugin(%s?mode='addsub'&url=%s)" % ( sys.argv[0], show_id ) ) ) item.addContextMenuItems( cm )#,replaceItems=True) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=True,totalItems=total_items) elif isVideo == True: u += '&videoid="'+urllib.quote_plus(video_id)+'"' u += '&eid="'+urllib.quote_plus(eid)+'"' if common.settings['enable_login']=='true' and common.settings['usertoken']: if 'History' == common.args.mode: cm.append( ('Remove from History', "XBMC.RunPlugin(%s?mode='removehistory'&url=%s)" % ( sys.argv[0], video_id ) ) ) if 'Queue' == common.args.mode: cm.append( ('Remove from Queue', "XBMC.RunPlugin(%s?mode='removequeue'&url=%s)" % ( sys.argv[0], video_id ) ) ) else: cm.append( ('Add to Queue', "XBMC.RunPlugin(%s?mode='addqueue'&url=%s)" % ( sys.argv[0], video_id ) ) ) if show_id <> '': cm.append( ('Add to Subscriptions', "XBMC.RunPlugin(%s?mode='addsub'&url=%s)" % ( sys.argv[0], show_id ) ) ) if 'True' == hascaptions: if common.settings['enable_captions'] == 'true': cm.append( ('Play without Subtitles', "XBMC.RunPlugin(%s?mode='NoCaptions_TV_play'&url='%s'&videoid='%s')" % ( sys.argv[0], url, video_id ) ) ) else: cm.append( ('Play with Subtitles', "XBMC.RunPlugin(%s?mode='Captions_TV_play'&url='%s'&videoid='%s')" % ( sys.argv[0], url, video_id ) ) ) cm.append( ('Assign Subtitles', "XBMC.RunPlugin(%s?mode='SUBTITLE_play'&url='%s'&videoid='%s')" % ( sys.argv[0], url, video_id ) ) ) cm.append( ('Select Quality', "XBMC.RunPlugin(%s?mode='Select_TV_play'&url='%s'&videoid='%s')" % ( sys.argv[0], url, video_id ) ) ) cm.append( ('Vote for Video', "XBMC.RunPlugin(%s?mode='vote'&url=%s)" % ( sys.argv[0], video_id ) ) ) item.addContextMenuItems( cm )#,replaceItems=True) item.setProperty('IsPlayable', 'true') xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False,totalItems=total_items)
def addMenuItems(self, perpage, pagenumber, url=common.args.url): # Grab xml item list orginalUrl = url if '?' in url: url += '&' else: url += '?' noCache = False if 'Queue' == common.args.mode or 'Subscriptions' == common.args.mode or 'History' == common.args.mode: usertoken = common.settings['usertoken'] url += 'dp_id=' + dp_id + '&limit=' + perpage + '&package_id=' + package_id + '&user_id=' + usertoken noCache = True total_count = 0 else: url += 'dp_id=' + dp_id + '&package_id=' + package_id + '&limit=' + perpage + '&page=' + pagenumber total_count = self.getTotalCount(orginalUrl) if noCache: xml = common.getFEED(url) else: xml = common.getFEED(url) while xml == False: if noCache: xml = common.getFEED(url) else: xml = common.getFEED(url) #xbmc.sleep(400) # Add Next/Prev Pages count = 0 if int(perpage) < int(total_count): if 'Popular' in common.args.name or 'Featured' in common.args.name or 'Recently' in common.args.name: popular = 'true' else: try: popular = common.args.popular except: popular = 'false' current_page = int(pagenumber) next_page = int(pagenumber) + 1 prev_page = int(pagenumber) - 1 npage_begin = int(perpage) * current_page + 1 npage_end = int(perpage) * next_page if total_count < npage_end: npage_end = total_count if npage_begin < total_count: next_name = 'Next Page (' + str(npage_begin) + '-' + str( npage_end) + ' of ' + str(total_count) + ')' nextthumb = xbmc.translatePath( os.path.join(common.imagepath, "next.png")) common.addDirectory(next_name, url, common.args.mode, page=str(next_page), icon=nextthumb, perpage=perpage, popular=popular, fanart=common.hulu_fanart, updatelisting='true') if prev_page > 0: ppage_begin = int(perpage) * (prev_page - 1) + 1 ppage_end = int(perpage) * prev_page prev_name = 'Previous Page (' + str(ppage_begin) + '-' + str( ppage_end) + ' of ' + str(total_count) + ')' prevthumb = xbmc.translatePath( os.path.join(common.imagepath, "prev.png")) common.addDirectory(prev_name, url, common.args.mode, page=str(prev_page), icon=prevthumb, perpage=perpage, popular=popular, fanart=common.hulu_fanart, updatelisting='true') tree = ElementTree.XML(xml) menuitems = tree.findall('item') del tree hasMovies = False hasEpisodes = False hasTVShows = False for item in menuitems: display = item.findtext('display').encode('utf-8') displayname = display url = 'http://m.hulu.com' + item.findtext('items_url') mode = item.find('app_data').findtext('cmtype') #Flatten All and Alphabetical if display == 'All' and total_count == 1: return self.addMenuItems(common.settings['allperpage'], common.args.page, url) # Skip unwanted menu items elif mode == 'None' or display == 'Add to queue' or display == 'Subscriptions': continue #set Data isVideo = False if common.args.fanart and common.args.fanart <> '': fanart = common.args.fanart else: fanart = common.hulu_fanart if common.args.art <> '': art = common.args.art elif 'Popular' in common.args.name or 'Popular' in display: art = xbmc.translatePath( os.path.join(common.imagepath, "icon_popular.jpg")) elif 'Recently' in common.args.name or 'Recently' in display: art = xbmc.translatePath( os.path.join(common.imagepath, "icon_recently_added.jpg")) elif 'TV' == common.args.name: art = xbmc.translatePath( os.path.join(common.imagepath, "icon_tv.jpg")) elif 'Movies' == common.args.name: art = xbmc.translatePath( os.path.join(common.imagepath, "icon_movies.jpg")) else: art = common.hulu_icon infoLabels = {'Title': display} show_id = False ishd = False data = item.find('data') if data: #data = data[0] canonical_name = data.findtext('canonical_name') show_canonical_name = data.findtext('show_canonical_name') #Show Only if canonical_name: infoLabels['TVShowTitle'] = data.findtext('name').encode( 'utf-8') infoLabels['Genre'] = data.findtext('genre', default="") totalEpisodes = data.findtext('full_episodes_count') if totalEpisodes: infoLabels['Episode'] = int(totalEpisodes) totalSeasons = data.findtext('total_seasons_count') parent_id = data.findtext('parent_id') if parent_id: displayname = '- ' + displayname art = "http://assets.hulu.com/shows/key_art_" + canonical_name.replace( '-', '_') + ".jpg" #Video Only elif show_canonical_name: isVideo = True canonical_name = show_canonical_name content_id = data.findtext('content_id') video_id = data.findtext('video_id') eid = data.findtext('eid') media_type = data.findtext('media_type') art = data.findtext('thumbnail_url_16x9_large') infoLabels['TVShowTitle'] = data.findtext( 'show_name').encode('utf-8') infoLabels['Genre'] = data.findtext('parent_channel_name', default="") infoLabels['MPAA'] = data.findtext('content_rating') votes_data = data.findtext('votes_count') seasondata = data.findtext('season_number') if seasondata.isdigit(): infoLabels['Season'] = int(seasondata) else: infoLabels['Season'] = 0 episodedata = data.findtext('episode_number') if episodedata.isdigit(): infoLabels['Episode'] = int(episodedata) else: infoLabels['Episode'] = 0 durationseconds = int(float(data.findtext('duration'))) infoLabels['Duration'] = str( datetime.timedelta(seconds=durationseconds)) #Both Show and Video plot = data.findtext('description') if plot: plot = unicode(plot.replace('\n', ' ').replace( '\r', ' ')).encode('utf-8') else: plot = '' plus_only = data.findtext('plus_only') if plus_only == 'True': plus_web_expires_at = data.findtext('plus_web_expires_at') if plus_web_expires_at: plot = 'Plus Expires: ' + plus_web_expires_at.replace( ' 00:00:00', '') + '\n' + plot else: expires_at = data.findtext('expires_at') if expires_at: plot = 'Expires: ' + expires_at.replace( ' 00:00:00', '') + '\n' + plot else: composite_expires_at = data.findtext( 'composite_expires_at') if composite_expires_at: plot = 'Expires: ' + composite_expires_at.replace( ' 00:00:00', '') + '\n' + plot infoLabels['Plot'] = plot premiered = data.findtext('original_premiere_date') if premiered: premiered = premiered.split(' ')[0] infoLabels['Premiered'] = premiered datesplit = premiered.split('-') infoLabels['date'] = datesplit[2] + '.' + datesplit[ 1] + '.' + datesplit[0] infoLabels['Year'] = int(premiered.split('-')[0]) rating = data.findtext('rating') if rating: #if rating.isdigit(): infoLabels['Rating'] = float(rating) * 2 company_name = data.findtext('company_name', default="") infoLabels['Studio'] = company_name ishd = data.findtext('has_hd') language = data.findtext('language', default="").upper() hascaptions = data.findtext('has_captions') show_id = data.findtext('show_id') if canonical_name: fanart = "http://assets.hulu.com/shows/key_art_" + canonical_name.replace( '-', '_') + ".jpg" if mode == 'SeasonMenu': xbmcplugin.setContent(pluginhandle, 'seasons') dtotal_count = self.getTotalCount(url) #displayname = displayname + ' ('+str(dtotal_count)+')' episode_number = dtotal_count isVideo = False elif mode == 'ShowPage': xbmcplugin.setContent(pluginhandle, 'tvshows') hasTVShows = True isVideo = False elif common.args.mode == 'ChannelMenu': xbmcplugin.setContent(pluginhandle, 'tvshows') fanart = common.hulu_fanart art = common.hulu_icon elif common.args.mode == 'ShowPage': xbmcplugin.setContent(pluginhandle, 'episodes') dtotal_count = self.getTotalCount(url) episode_number = dtotal_count displayname = displayname + ' (' + str(dtotal_count) + ')' if dtotal_count == 0: continue #Set Networks and Studios fanart elif common.args.name == 'Networks' or common.args.name == 'Studios': xbmcplugin.setContent(pluginhandle, 'tvshows') canonical_name = self.remove_accents( canonical_name.encode('utf-8')) fanart = "http://assets.huluim.com/companies/key_art_" + canonical_name.replace( '-', '_') + ".jpg" art = fanart #Add Count to Display Name for Non-Show/Episode Lists elif common.args.mode == 'Menu' and isVideo == False: dtotal_count = self.getTotalCount(url) if dtotal_count <> 1: displayname = displayname + ' (' + str(dtotal_count) + ')' elif dtotal_count == 0: continue #Set Final Video Name elif isVideo == True: url = content_id #URL of video #url="http://www.hulu.com/watch/"+videoid mode = 'TV_play' if media_type == 'TV': xbmcplugin.setContent(pluginhandle, 'episodes') hasEpisodes = True elif media_type == 'Film': xbmcplugin.setContent(pluginhandle, 'episodes') hasMovies = True #infoLabels['TVShowTitle'] = company_name #xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_EPISODE) if infoLabels['Season'] <> 0 and infoLabels['Episode'] <> 0: if 'Popular' in common.args.name or 'Featured' in common.args.name or 'Recently' in common.args.name or 'Queue' == common.args.mode or 'History' == common.args.mode or common.args.popular == 'true': displayname = infoLabels['TVShowTitle'] + ' - ' + str( infoLabels['Season']) + 'x' + str( infoLabels['Episode']) + ' - ' + display else: displayname = str(infoLabels['Season']) + 'x' + str( infoLabels['Episode']) + ' - ' + display if 'EN' <> language: displayname += ' (' + language + ')' if 'True' == ishd: displayname += ' (HD)' u = sys.argv[0] u += '?url="' + urllib.quote_plus(url) + '"' u += '&mode="' + urllib.quote_plus(mode) + '"' item = xbmcgui.ListItem(displayname, iconImage=art, thumbnailImage=art) infoLabels['Title'] = displayname infoLabels['count'] = count count += 1 item.setInfo(type="Video", infoLabels=infoLabels) item.setProperty('fanart_image', fanart) #Set total count if int(perpage) < int(total_count): total_items = int(perpage) elif int(perpage) < len(menuitems): total_items = len(menuitems) else: total_items = int(total_count) cm = [] if isVideo == False: u += '&name="' + urllib.quote_plus(display.replace("'", "")) + '"' u += '&art="' + urllib.quote_plus(art) + '"' u += '&fanart="' + urllib.quote_plus(fanart) + '"' u += '&page="1"' u += '&popular="false"' u += '&updatelisting="false"' if common.settings[ 'enable_login'] == 'true' and common.settings[ 'usertoken']: if 'Subscriptions' == common.args.mode: cm.append( ('Remove Subscription', "XBMC.RunPlugin(%s?mode='removesub'&url=%s)" % (sys.argv[0], show_id))) elif show_id <> '': cm.append(('Add to Subscriptions', "XBMC.RunPlugin(%s?mode='addsub'&url=%s)" % (sys.argv[0], show_id))) item.addContextMenuItems(cm) #,replaceItems=True) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=item, isFolder=True, totalItems=total_items) elif isVideo == True: u += '&videoid="' + urllib.quote_plus(video_id) + '"' u += '&eid="' + urllib.quote_plus(eid) + '"' if common.settings[ 'enable_login'] == 'true' and common.settings[ 'usertoken']: if 'History' == common.args.mode: cm.append( ('Remove from History', "XBMC.RunPlugin(%s?mode='removehistory'&url=%s)" % (sys.argv[0], video_id))) if 'Queue' == common.args.mode: cm.append( ('Remove from Queue', "XBMC.RunPlugin(%s?mode='removequeue'&url=%s)" % (sys.argv[0], video_id))) else: cm.append( ('Add to Queue', "XBMC.RunPlugin(%s?mode='addqueue'&url=%s)" % (sys.argv[0], video_id))) if show_id <> '': cm.append( ('Add to Subscriptions', "XBMC.RunPlugin(%s?mode='addsub'&url=%s)" % (sys.argv[0], show_id))) if 'True' == hascaptions: if common.settings['enable_captions'] == 'true': cm.append(( 'Play without Subtitles', "XBMC.RunPlugin(%s?mode='NoCaptions_TV_play'&url='%s'&videoid='%s')" % (sys.argv[0], url, video_id))) else: cm.append(( 'Play with Subtitles', "XBMC.RunPlugin(%s?mode='Captions_TV_play'&url='%s'&videoid='%s')" % (sys.argv[0], url, video_id))) cm.append(( 'Assign Subtitles', "XBMC.RunPlugin(%s?mode='SUBTITLE_play'&url='%s'&videoid='%s')" % (sys.argv[0], url, video_id))) cm.append(( 'Select Quality', "XBMC.RunPlugin(%s?mode='Select_TV_play'&url='%s'&videoid='%s')" % (sys.argv[0], url, video_id))) cm.append(('Vote for Video', "XBMC.RunPlugin(%s?mode='vote'&url=%s)" % (sys.argv[0], video_id))) item.addContextMenuItems(cm) #,replaceItems=True) item.setProperty('IsPlayable', 'true') xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=item, isFolder=False, totalItems=total_items)
def ExportShow(self, show): data = show.find('data') show_name = data.findtext('name').encode('utf-8').strip() directory = os.path.join(TV_SHOWS_PATH,self.cleanfilename(show_name)) nfo_fullpath = os.path.join(directory,'tvshow.nfo') if os.path.isfile(nfo_fullpath) == False: # print '\n'.join(str(p) for p in data) tvshowDetails = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n<tvshow>\n' try: tvshowDetails += ' <title>'+data.findtext('name').encode('utf-8').strip()+'</title>\n' except: tvshowDetails += ' <title>'+'</title>\n' try: tvshowDetails += ' <showtitle>'+data.findtext('name').encode('utf-8').strip()+'</showtitle>\n' except: tvshowDetails += ' <showtitle>'+'</showtitle>\n' try: tvshowDetails += ' <rating>'+data.findtext('rating').encode('utf-8').strip()+'</rating>\n' except: tvshowDetails += ' <rating>'+'</rating>\n' try: tvshowDetails += ' <thumb>'+"http://assets.hulu.com/shows/key_art_"+data.findtext('canonical_name').encode('utf-8').strip().replace('-','_')+".jpg"+'</thumb>\n' except: tvshowDetails += ' <thumb>'+'</thumb>\n' try: tvshowDetails += ' <fanart>\n <thumb>' tvshowDetails += "http://assets.hulu.com/shows/key_art_"+data.findtext('canonical_name').encode('utf-8').strip().replace('-','_')+".jpg" tvshowDetails += '</thumb>\n </fanart>\n' except: tvshowDetails += ' <fanart>'+'</fanart>\n' try: tvshowDetails += ' <plot>'+data.findtext('description').encode('utf-8').strip()+'</plot>\n' except: tvshowDetails += ' <plot>'+'</plot>\n' tvshowDetails += ' <genre>Hulu</genre>\n' try: tvshowDetails += ' <genre>'+data.findtext('genre').encode('utf-8').strip()+'</genre>\n' except: pass try: tvshowDetails += ' <season>'+data.findtext('total_seasons_count').encode('utf-8').strip()+'</season>\n' except: tvshowDetails += ' <season>'+'</season>\n' try: premiered = data.findtext('original_premiere_date').encode('utf-8').strip() if "T" in premiered: premiered = premiered.split("T")[0] elif " " in premiered: premiered = premiered.split(" ")[0] tvshowDetails += ' <premiered>'+premiered+'</premiered>\n' except: tvshowDetails += ' <premiered>'+'</premiered>\n' try: if "-" in premiered: tvyear = premiered.split("-")[0] else: tvyear = "" tvshowDetails += ' <year>'+tvyear+'</year>\n' except: pass try: tvshowDetails += ' <studio>'+data.findtext('company_name').encode('utf-8').strip()+'</studio>\n' except: tvshowDetails += ' <studio>'+'</studio>\n' try: tvshowDetails += ' <episode>'+data.findtext('full_episodes_count').encode('utf-8').strip()+'</episode>\n' except: tvshowDetails += ' <episode>'+'</episode>\n' tvshowDetails += ' <resume>\n <position>0.000000</position>\n <total>0.000000</total>\n </resume>\n' tvshowDetails += '</tvshow>\n' # log( "tvshowDetails = "+tvshowDetails) self.CreateDirectory(directory) self.SaveFile( 'tvshow.nfo', tvshowDetails, directory) show_id = data.findtext('show_id') url = 'http://m.hulu.com/menu/11674?show_id='+show_id+'&dp_id=hulu&limit=2000&package_id='+package_id xml=common.getFEED(url) tree = ElementTree.XML(xml) episodes = tree.findall('item') del tree for episode in episodes: self.ExportVideo(episode)
def addMenuItems( self, perpage, pagenumber , search, huluonly ): url = 'http://m.hulu.com/search?items_per_page='+perpage+'&hulu_only='+huluonly+'&dp_identifier='+dp_id+'&package_id='+package_id+'&query='+search xml=common.getFEED(url) while xml == False: xml=common.getFEED(url) xbmc.sleep(400) tree = ElementTree.XML(xml) total_count= int(tree.findtext('count')) menuitems = tree.find('videos').findall('video') del tree for item in menuitems: infoLabels={} infoLabels['Title']=item.findtext('title').encode('utf-8') infoLabels['Genre'] = item.findtext('genre', default="") infoLabels['TVShowTitle'] = item.find('show').findtext('name').encode('utf-8') infoLabels['MPAA'] = item.findtext('content-rating') infoLabels['Votes'] = item.findtext('votes-count') infoLabels['Premiered'] = item.findtext('original-premiere-date').replace('T00:00:00Z','') if infoLabels['Premiered'] <> '': infoLabels['Year'] = int(infoLabels['Premiered'].split('-')[0]) season = item.findtext('season-number') if season <> '': infoLabels['Season'] = int(season) else: infoLabels['Season'] = 0 episode = item.findtext('episode-number') if episode <> '': infoLabels['Episode'] = int(episode) else: infoLabels['Episode'] = 0 durationseconds = int(float(item.findtext('duration'))) infoLabels['Duration'] = str(datetime.timedelta(seconds=durationseconds)) infoLabels['Rating'] = float(item.findtext('rating'))*2 full_description = item.findtext('full-description') description = item.findtext('description') if full_description <> '': infoLabels['Plot'] = full_description.replace('\n', ' ').replace('\r', ' ').encode('utf-8') elif description <> '': infoLabels['Plot'] = description.replace('\n', ' ').replace('\r', ' ').encode('utf-8') company_name = item.findtext('company-name') content_id = item.findtext('content-id') video_id = item.findtext('id') eid = item.findtext('eid') show_id = item.find('show').findtext('id') language = item.findtext('language', default='').upper() art = item.findtext('thumbnail-url') canonical_name = item.find('show').findtext('canonical-name') if canonical_name <> '' and canonical_name <> None: fanart = "http://assets.hulu.com/shows/key_art_"+canonical_name.replace('-','_')+".jpg" else: fanart = common.hulu_fanart if infoLabels['Season'] <> 0 and infoLabels['Episode'] <> 0: displayname = infoLabels['TVShowTitle']+' - '+str(infoLabels['Season'])+'x'+str(infoLabels['Episode'])+' - '+infoLabels['Title'] elif infoLabels['TVShowTitle'] <> '' and infoLabels['TVShowTitle'] not in infoLabels['Title']: displayname = infoLabels['TVShowTitle']+' - '+infoLabels['Title'] else: displayname = infoLabels['Title'] if 'EN' <> language: displayname += ' ('+language+')' ishd = item.findtext('has-hd') if 'True' == ishd: displayname += ' (HD)' hascaptions = item.findtext('has-captions') media_type = item.findtext('media-type') if media_type == 'TV': xbmcplugin.setContent(pluginhandle, 'episodes') elif media_type == 'Film': xbmcplugin.setContent(pluginhandle, 'movies') mode = 'TV_play' u = sys.argv[0] u += '?url="'+urllib.quote_plus(content_id)+'"' u += '&mode="'+urllib.quote_plus(mode)+'"' u += '&videoid="'+urllib.quote_plus(video_id)+'"' u += '&eid="'+urllib.quote_plus(eid)+'"' item=xbmcgui.ListItem(displayname, iconImage=art, thumbnailImage=art) item.setInfo( type="Video", infoLabels=infoLabels) item.setProperty('fanart_image',fanart) if int(perpage) < int(total_count): total_items = int(perpage) else: total_items = int(total_count) if common.settings['enable_login']=='true' and common.settings['usertoken']: cm = [] cm.append( ('Add to Queue', "XBMC.RunPlugin(%s?mode='addqueue'&url=%s)" % ( sys.argv[0], video_id ) ) ) if show_id <> '': cm.append( ('Add to Subscriptions', "XBMC.RunPlugin(%s?mode='addsub'&url=%s)" % ( sys.argv[0], show_id ) ) ) if 'true' == hascaptions: if common.settings['enable_captions'] == 'true': cm.append( ('Play without Subtitles', "XBMC.RunPlugin(%s?mode='NoCaptions_TV_play'&url='%s'&videoid='%s')" % ( sys.argv[0], url, video_id ) ) ) else: cm.append( ('Play with Subtitles', "XBMC.RunPlugin(%s?mode='Captions_TV_play'&url='%s'&videoid='%s')" % ( sys.argv[0], content_id, video_id ) ) ) cm.append( ('Assign Subtitles', "XBMC.RunPlugin(%s?mode='SUBTITLE_play'&url='%s'&videoid='%s')" % ( sys.argv[0], content_id, video_id ) ) ) cm.append( ('Select Quality', "XBMC.RunPlugin(%s?mode='Select_TV_play'&url='%s'&videoid='%s')" % ( sys.argv[0], content_id, video_id ) ) ) cm.append( ('Vote for Video', "XBMC.RunPlugin(%s?mode='vote'&url=%s)" % ( sys.argv[0], video_id ) ) ) item.addContextMenuItems( cm ,replaceItems=True) item.setProperty('IsPlayable', 'true') xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False,totalItems=total_items)
def addMenuItems(self, perpage, pagenumber, search, huluonly): url = 'http://m.hulu.com/search?items_per_page=' + perpage + '&hulu_only=' + huluonly + '&dp_identifier=' + dp_id + '&package_id=' + package_id + '&query=' + search xml = common.getFEED(url) while xml == False: xml = common.getFEED(url) xbmc.sleep(400) tree = ElementTree.XML(xml) total_count = int(tree.findtext('count')) menuitems = tree.find('videos').findall('video') del tree for item in menuitems: infoLabels = {} infoLabels['Title'] = item.findtext('title').encode('utf-8') infoLabels['Genre'] = item.findtext('genre', default="") infoLabels['TVShowTitle'] = item.find('show').findtext( 'name').encode('utf-8') infoLabels['MPAA'] = item.findtext('content-rating') infoLabels['Votes'] = item.findtext('votes-count') infoLabels['Premiered'] = item.findtext( 'original-premiere-date').replace('T00:00:00Z', '') if infoLabels['Premiered'] <> '': infoLabels['Year'] = int(infoLabels['Premiered'].split('-')[0]) season = item.findtext('season-number') if season <> '': infoLabels['Season'] = int(season) else: infoLabels['Season'] = 0 episode = item.findtext('episode-number') if episode <> '': infoLabels['Episode'] = int(episode) else: infoLabels['Episode'] = 0 durationseconds = int(float(item.findtext('duration'))) infoLabels['Duration'] = str( datetime.timedelta(seconds=durationseconds)) infoLabels['Rating'] = float(item.findtext('rating')) * 2 full_description = item.findtext('full-description') description = item.findtext('description') if full_description <> '': infoLabels['Plot'] = full_description.replace( '\n', ' ').replace('\r', ' ').encode('utf-8') elif description <> '': infoLabels['Plot'] = description.replace('\n', ' ').replace( '\r', ' ').encode('utf-8') company_name = item.findtext('company-name') content_id = item.findtext('content-id') video_id = item.findtext('id') eid = item.findtext('eid') show_id = item.find('show').findtext('id') language = item.findtext('language', default='').upper() art = item.findtext('thumbnail-url') canonical_name = item.find('show').findtext('canonical-name') if canonical_name <> '' and canonical_name <> None: fanart = "http://assets.hulu.com/shows/key_art_" + canonical_name.replace( '-', '_') + ".jpg" else: fanart = common.hulu_fanart if infoLabels['Season'] <> 0 and infoLabels['Episode'] <> 0: displayname = infoLabels['TVShowTitle'] + ' - ' + str( infoLabels['Season']) + 'x' + str( infoLabels['Episode']) + ' - ' + infoLabels['Title'] elif infoLabels['TVShowTitle'] <> '' and infoLabels[ 'TVShowTitle'] not in infoLabels['Title']: displayname = infoLabels['TVShowTitle'] + ' - ' + infoLabels[ 'Title'] else: displayname = infoLabels['Title'] if 'EN' <> language: displayname += ' (' + language + ')' ishd = item.findtext('has-hd') if 'True' == ishd: displayname += ' (HD)' hascaptions = item.findtext('has-captions') media_type = item.findtext('media-type') if media_type == 'TV': xbmcplugin.setContent(pluginhandle, 'episodes') elif media_type == 'Film': xbmcplugin.setContent(pluginhandle, 'movies') mode = 'TV_play' u = sys.argv[0] u += '?url="' + urllib.quote_plus(content_id) + '"' u += '&mode="' + urllib.quote_plus(mode) + '"' u += '&videoid="' + urllib.quote_plus(video_id) + '"' u += '&eid="' + urllib.quote_plus(eid) + '"' item = xbmcgui.ListItem(displayname, iconImage=art, thumbnailImage=art) item.setInfo(type="Video", infoLabels=infoLabels) item.setProperty('fanart_image', fanart) if int(perpage) < int(total_count): total_items = int(perpage) else: total_items = int(total_count) if common.settings['enable_login'] == 'true' and common.settings[ 'usertoken']: cm = [] cm.append(('Add to Queue', "XBMC.RunPlugin(%s?mode='addqueue'&url=%s)" % (sys.argv[0], video_id))) if show_id <> '': cm.append(('Add to Subscriptions', "XBMC.RunPlugin(%s?mode='addsub'&url=%s)" % (sys.argv[0], show_id))) if 'true' == hascaptions: if common.settings['enable_captions'] == 'true': cm.append(( 'Play without Subtitles', "XBMC.RunPlugin(%s?mode='NoCaptions_TV_play'&url='%s'&videoid='%s')" % (sys.argv[0], url, video_id))) else: cm.append(( 'Play with Subtitles', "XBMC.RunPlugin(%s?mode='Captions_TV_play'&url='%s'&videoid='%s')" % (sys.argv[0], content_id, video_id))) cm.append(( 'Assign Subtitles', "XBMC.RunPlugin(%s?mode='SUBTITLE_play'&url='%s'&videoid='%s')" % (sys.argv[0], content_id, video_id))) cm.append(( 'Select Quality', "XBMC.RunPlugin(%s?mode='Select_TV_play'&url='%s'&videoid='%s')" % (sys.argv[0], content_id, video_id))) cm.append(('Vote for Video', "XBMC.RunPlugin(%s?mode='vote'&url=%s)" % (sys.argv[0], video_id))) item.addContextMenuItems(cm, replaceItems=True) item.setProperty('IsPlayable', 'true') xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=item, isFolder=False, totalItems=total_items)
def playAD(self, video_id, pod, GUID): if os.path.isfile(common.ADCACHE): data=common.OpenFile(common.ADCACHE) playlistSoup=BeautifulStoneSoup(data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) self.sstate = playlistSoup.find('sessionstate')['value'] self.ustate = playlistSoup.find('userstate')['value'] del playlistSoup session=self.sstate state=self.ustate else: session='' state='' epoch = str(int(time.mktime(time.gmtime()))) # token plid for plsnid if common.settings['enable_login'] =='true' and common.settings['usertoken']: UserID = common.settings['userid'] if common.settings['planid'] == '' or common.settings['planid'] == None: PlanID = '0' else: PlanID = common.settings['planid'] else: UserID = '-1' PlanID = '0' xmlbase=''' <AdRequest Pod="'''+str(pod)+'''" SessionState="'''+session+'''" ResponseType="VAST" Timestamp="'''+epoch+'''"> <Distributor Name="Hulu" Platform="Desktop"/> <Visitor IPV4Address="" BT_RSSegments="null" UserId="'''+UserID+'''" MiniCount="" MiniDuration="" ComputerGuid="'''+GUID+'''" AdFeedback="null" PlanId="'''+PlanID+'''" FlashVersion="WIN 11,1,102,55" State="'''+state+'''"/> <KeyValues> <KeyValue Key="env" Value="prod"/> <KeyValue Key="version" Value="Voltron"/> </KeyValues> <SiteLocation> <VideoPlayer Url="http://download.hulu.com/huludesktop.swf" Mode="normal"> <VideoAsset PId="NO_MORE_RELEASES_PLEASE_'''+video_id+'''" Id="'''+video_id+'''" ContentLanguage="en" BitRate="650" Width="320" Height="240"/> </VideoPlayer> </SiteLocation> <Diagnostics/> </AdRequest>''' print xmlbase xmlbase=xmlbase.replace('/n','') IV = self.MakeIV() encdata = self.ADencrypt(xmlbase,IV) url = 'http://p.hulu.com/getPlaylist?kv=1&iv='+urllib.quote_plus(IV) encplaylist = common.getFEED(url,postdata=encdata) playlist = self.ADdecrypt(encplaylist) common.SaveFile(common.ADCACHE, playlist) playlistSoup=BeautifulStoneSoup(playlist, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) print playlistSoup.prettify() self.sstate = playlistSoup.find('sessionstate')['value'] self.ustate = playlistSoup.find('userstate')['value'] trackingurls = [] stack = 'stack://' title = '' for ad in playlistSoup.findAll('ad'): mediafiles = ad.findAll('mediafile') if common.settings['adquality'] <= len(mediafiles): mediaUrl = mediafiles[common.settings['adquality']].string else: mediaUrl = mediafiles[0].string adtitle = ad.find('adtitle').string title += ' '+adtitle+'' stack += mediaUrl.replace(',',',,')+' , ' stack = stack[:-3] title = title.strip() item = xbmcgui.ListItem(title, path=stack) item.setInfo( type="Video", infoLabels={ "Title":title}) if '.swf' not in stack: xbmcplugin.setResolvedUrl(common.handle, True, item) for item in playlistSoup.findAll('tracking'): common.getFEED(item.string) return True else: return False
def playAD(self, video_id, pod, GUID): if os.path.isfile(common.ADCACHE): data = common.OpenFile(common.ADCACHE) playlistSoup = BeautifulStoneSoup( data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) self.sstate = playlistSoup.find('sessionstate')['value'] self.ustate = playlistSoup.find('userstate')['value'] del playlistSoup session = self.sstate state = self.ustate else: session = '' state = '' epoch = str(int(time.mktime(time.gmtime()))) # token plid for plsnid if common.settings['enable_login'] == 'true' and common.settings[ 'usertoken']: UserID = common.settings['userid'] if common.settings['planid'] == '' or common.settings[ 'planid'] == None: PlanID = '0' else: PlanID = common.settings['planid'] else: UserID = '-1' PlanID = '0' xmlbase = ''' <AdRequest Pod="''' + str( pod ) + '''" SessionState="''' + session + '''" ResponseType="VAST" Timestamp="''' + epoch + '''"> <Distributor Name="Hulu" Platform="Desktop"/> <Visitor IPV4Address="" BT_RSSegments="null" UserId="''' + UserID + '''" MiniCount="" MiniDuration="" ComputerGuid="''' + GUID + '''" AdFeedback="null" PlanId="''' + PlanID + '''" FlashVersion="WIN 11,1,102,55" State="''' + state + '''"/> <KeyValues> <KeyValue Key="env" Value="prod"/> <KeyValue Key="version" Value="Voltron"/> </KeyValues> <SiteLocation> <VideoPlayer Url="http://download.hulu.com/huludesktop.swf" Mode="normal"> <VideoAsset PId="NO_MORE_RELEASES_PLEASE_''' + video_id + '''" Id="''' + video_id + '''" ContentLanguage="en" BitRate="650" Width="320" Height="240"/> </VideoPlayer> </SiteLocation> <Diagnostics/> </AdRequest>''' print xmlbase xmlbase = xmlbase.replace('/n', '') IV = self.MakeIV() encdata = self.ADencrypt(xmlbase, IV) url = 'http://p.hulu.com/getPlaylist?kv=1&iv=' + urllib.quote_plus(IV) encplaylist = common.getFEED(url, postdata=encdata) playlist = self.ADdecrypt(encplaylist) common.SaveFile(common.ADCACHE, playlist) playlistSoup = BeautifulStoneSoup( playlist, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) print playlistSoup.prettify() self.sstate = playlistSoup.find('sessionstate')['value'] self.ustate = playlistSoup.find('userstate')['value'] trackingurls = [] stack = 'stack://' title = '' for ad in playlistSoup.findAll('ad'): mediafiles = ad.findAll('mediafile') if common.settings['adquality'] <= len(mediafiles): mediaUrl = mediafiles[common.settings['adquality']].string else: mediaUrl = mediafiles[0].string adtitle = ad.find('adtitle').string title += ' ' + adtitle + '' stack += mediaUrl.replace(',', ',,') + ' , ' stack = stack[:-3] title = title.strip() item = xbmcgui.ListItem(title, path=stack) item.setInfo(type="Video", infoLabels={"Title": title}) if '.swf' not in stack: xbmcplugin.setResolvedUrl(common.handle, True, item) for item in playlistSoup.findAll('tracking'): common.getFEED(item.string) return True else: return False
def addMainHomeItems(self): xml = common.getFEED(common.BASE_MENU_URL) tree = ElementTree.XML(xml) menuitems = tree.findall('item') fanart = common.hulu_fanart for item in menuitems: display = item.findtext('display') items_url = 'http://m.hulu.com' + item.findtext('items_url') cmtype = item.find('app_data').findtext('cmtype') thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon.png")) cm = [] if cmtype == 'None' or display == 'Help' or display == 'Profiles' or display == 'Now Playing': continue elif display == 'Popular': thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon_popular.jpg")) cm.append( ('Export Popular Shows', "XBMC.RunPlugin(%s?mode='ForcePopularShowsLibrary')" % (sys.argv[0]))) cm.append( ('Export Popular Movies', "XBMC.RunPlugin(%s?mode='ForcePopularMoviesLibrary')" % (sys.argv[0]))) cm.append( ('Export Popular Episodes', "XBMC.RunPlugin(%s?mode='ForcePopularEpisodesLibrary')" % (sys.argv[0]))) elif display == 'Recently Added': thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon_recently_added.jpg")) elif display == 'TV': cm.append(('Export All Full Shows', "XBMC.RunPlugin(%s?mode='ForceFullShowsLibrary')" % (sys.argv[0]))) thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon_tv.jpg")) elif display == 'Movies': cm.append(('Export All Full Movies', "XBMC.RunPlugin(%s?mode='ForceFullMoviesLibrary')" % (sys.argv[0]))) thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon_movies.jpg")) elif display == 'Search': thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon_search.jpg")) common.addDirectory(display, items_url, cmtype, thumbnail, thumbnail, fanart=fanart, page='1', perpage='25', cm=cm) if common.settings['enable_login'] == 'true': if not os.path.isfile(common.QUEUETOKEN): common.login_queue() thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon_queue.jpg")) cm = [ ('Add Queue to Library', "XBMC.RunPlugin(%s?mode='ForceQueueLibrary')" % (sys.argv[0])) ] cm.append( ('Clear Library Directory', "XBMC.RunPlugin(%s?mode='ClearLibrary')" % (sys.argv[0]))) common.addDirectory('Queue', 'http://m.hulu.com/menu/hd_user_queue', 'Queue', thumbnail, thumbnail, fanart=fanart, page='1', perpage='2000', cm=cm) thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon_subscriptions.jpg")) cm = [('Add Subscriptions to Library', "XBMC.RunPlugin(%s?mode='ForceSubscriptionsLibrary')" % (sys.argv[0]))] cm.append( ('Clear Library Directory', "XBMC.RunPlugin(%s?mode='ClearLibrary')" % (sys.argv[0]))) common.addDirectory('Subscriptions', 'http://m.hulu.com/menu/hd_user_subscriptions', 'Subscriptions', thumbnail, thumbnail, fanart=fanart, page='1', perpage='2000', cm=cm) thumbnail = xbmc.translatePath( os.path.join(common.imagepath, "icon_history.jpg")) common.addDirectory('History', 'http://m.hulu.com/menu/hd_user_history', 'History', thumbnail, thumbnail, fanart=fanart, page='1', perpage='2000')
def getIDS4HTTP(self, url): pagedata=common.getFEED(url) common.args.videoid = url.split('watch/')[1].split('/')[0] content_id = re.compile('so.addVariable\("content_id", (.*?)\);').findall(pagedata)[0].strip() common.args.eid = self.cid2eid(content_id) return content_id
def ExportShow(self, show): data = show.find('data') show_name = data.findtext('name').encode('utf-8').strip() directory = os.path.join(TV_SHOWS_PATH, self.cleanfilename(show_name)) nfo_fullpath = os.path.join(directory, 'tvshow.nfo') if os.path.isfile(nfo_fullpath) == False: # print '\n'.join(str(p) for p in data) tvshowDetails = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n<tvshow>\n' try: tvshowDetails += ' <title>' + data.findtext('name').encode( 'utf-8').strip() + '</title>\n' except: tvshowDetails += ' <title>' + '</title>\n' try: tvshowDetails += ' <showtitle>' + data.findtext( 'name').encode('utf-8').strip() + '</showtitle>\n' except: tvshowDetails += ' <showtitle>' + '</showtitle>\n' try: tvshowDetails += ' <rating>' + data.findtext( 'rating').encode('utf-8').strip() + '</rating>\n' except: tvshowDetails += ' <rating>' + '</rating>\n' try: tvshowDetails += ' <thumb>' + "http://assets.hulu.com/shows/key_art_" + data.findtext( 'canonical_name').encode('utf-8').strip().replace( '-', '_') + ".jpg" + '</thumb>\n' except: tvshowDetails += ' <thumb>' + '</thumb>\n' try: tvshowDetails += ' <fanart>\n <thumb>' tvshowDetails += "http://assets.hulu.com/shows/key_art_" + data.findtext( 'canonical_name').encode('utf-8').strip().replace( '-', '_') + ".jpg" tvshowDetails += '</thumb>\n </fanart>\n' except: tvshowDetails += ' <fanart>' + '</fanart>\n' try: tvshowDetails += ' <plot>' + data.findtext( 'description').encode('utf-8').strip() + '</plot>\n' except: tvshowDetails += ' <plot>' + '</plot>\n' tvshowDetails += ' <genre>Hulu</genre>\n' try: tvshowDetails += ' <genre>' + data.findtext('genre').encode( 'utf-8').strip() + '</genre>\n' except: pass try: tvshowDetails += ' <season>' + data.findtext( 'total_seasons_count').encode( 'utf-8').strip() + '</season>\n' except: tvshowDetails += ' <season>' + '</season>\n' try: premiered = data.findtext('original_premiere_date').encode( 'utf-8').strip() if "T" in premiered: premiered = premiered.split("T")[0] elif " " in premiered: premiered = premiered.split(" ")[0] tvshowDetails += ' <premiered>' + premiered + '</premiered>\n' except: tvshowDetails += ' <premiered>' + '</premiered>\n' try: if "-" in premiered: tvyear = premiered.split("-")[0] else: tvyear = "" tvshowDetails += ' <year>' + tvyear + '</year>\n' except: pass try: tvshowDetails += ' <studio>' + data.findtext( 'company_name').encode('utf-8').strip() + '</studio>\n' except: tvshowDetails += ' <studio>' + '</studio>\n' try: tvshowDetails += ' <episode>' + data.findtext( 'full_episodes_count').encode( 'utf-8').strip() + '</episode>\n' except: tvshowDetails += ' <episode>' + '</episode>\n' tvshowDetails += ' <resume>\n <position>0.000000</position>\n <total>0.000000</total>\n </resume>\n' tvshowDetails += '</tvshow>\n' # log( "tvshowDetails = "+tvshowDetails) self.CreateDirectory(directory) self.SaveFile('tvshow.nfo', tvshowDetails, directory) show_id = data.findtext('show_id') url = 'http://m.hulu.com/menu/11674?show_id=' + show_id + '&dp_id=hulu&limit=2000&package_id=' + package_id xml = common.getFEED(url) tree = ElementTree.XML(xml) episodes = tree.findall('item') del tree for episode in episodes: self.ExportVideo(episode)
def getIDS4HTTP(self, url): pagedata=common.getFEED(url) common.args.videoid = url.split('watch/')[1].split('/')[0] content_id = re.compile('video/(\d+)').findall(pagedata)[0].strip() common.args.eid = self.cid2eid(content_id) return content_id