def Browse(section): add_dir_title() url_content = net.http_GET(BASEURL + 'home', headers=headers).content try: url_content = univ_common.str_conv(url_content) except: url_content = net.http_GET(BASEURL, headers=headers).content url_content = univ_common.str_conv(url_content) url_content = re.sub("<!--.+?-->", " ", url_content) cats = re.search("(?s)<div id=\"" + section + "\-2\".+?<ul>(.+?)</ul>", url_content) if cats: cats = cats.group(1) for cat in re.finditer("<li.*?><a href=[\"'](.+?)[\"'].*?>(.+?)</a>", cats): cat_url = cat.group(1) cat_title = cat.group(2) if 'tna/ppv-tna' in cat_url: cat_title = cat_title + ' ( TNA )' elif 'wwe/ppv' in cat_url: cat_title = cat_title + ' ( WWE )' image = os.path.join(IconPath, cat_url[cat_url[0:cat_url.rfind('/')].rfind('/')+1:cat_url.rfind('/')] + '.jpg') addon.add_directory({'mode' : 'Page', 'title': cat_title, 'img' : image, 'url' : cat_url, 'page' : '1', 'sort': 'date', 'sortorder' : 'desc'}, {'title': cat_title}, img=image) xbmcplugin.endOfDirectory(int(sys.argv[1]))
def Browse(section): add_dir_title() url_content = net.http_GET(BASEURL + 'home', headers=headers).content try: url_content = univ_common.str_conv(url_content) except: url_content = net.http_GET(BASEURL, headers=headers).content url_content = univ_common.str_conv(url_content) url_content = re.sub("<!--.+?-->", " ", url_content) soup = BeautifulSoup(url_content, "html5lib") cats = soup.find("div", id="categories-2") if cats: for cat in cats.find_all("li", class_="cat-item"): cat_url = cat.a["href"] cat_title = cat.a.string if 'tna/ppv-tna' in cat_url: cat_title = cat_title + ' ( TNA )' elif 'wwe/ppv' in cat_url: cat_title = cat_title + ' ( WWE )' image = os.path.join(IconPath, cat_url[cat_url[0:cat_url.rfind('/')].rfind('/')+1:cat_url.rfind('/')] + '.jpg') addon.add_directory({'mode' : 'Page', 'title': cat_title, 'img' : image, 'url' : cat_url, 'page' : '1', 'sort': 'date', 'sortorder' : 'desc'}, {'title': cat_title}, img=image) xbmcplugin.endOfDirectory(int(sys.argv[1]))
def GetLatest(): add_dir_title() url_content = net.http_GET(BASEURL + 'home', headers=headers).content try: url_content = univ_common.str_conv(url_content) except: url_content = net.http_GET(BASEURL, headers=headers).content url_content = univ_common.str_conv(url_content) url_content = re.sub("<!--.+?-->", " ", url_content) for latest_headers in re.finditer(r"(?s)<span class=\"name\">(.+?)</span>.*?<a class=\"more-link\" href=\"(.+?)\">(.+?)</div> </div></div> </div>", url_content): latest_title = latest_headers.group(1) more_url = latest_headers.group(2) latest_items = latest_headers.group(3) more_title = latest_title more_title = more_title.replace('Latest', '') more_title = more_title.replace('Shows', '') more_title = more_title.replace('Wrestling', '') more_title = more_title.strip() more_image = os.path.join(IconPath, more_title.lower().replace(' ','-') + '.jpg') addon.add_directory({'mode' : 'DUMMY-DIR'}, {'title': '[COLOR blue]' + latest_title + '[/COLOR]'}, img=more_image) for item in re.finditer(r"(?s)<a class=\"clip-link\".+?title=\"(.+?)\".+?href=\"(.+?)\".+?<img src=\"(.+?)\"", latest_items): item_title = univ_common.str_conv(addon.decode(item.group(1))) item_url = item.group(2) item_image = item.group(3) addon.add_directory({'mode' : 'GetLinks', 'url' : item_url, 'title' : item_title, 'img':item_image}, {'title': '.....' + item_title}, img=item_image) addon.add_directory({'mode' : 'Page', 'url' : more_url, 'page' : '1', 'sort': 'date', 'sortorder' : 'desc', 'title' : more_title, 'img' : more_image}, {'title': '[COLOR yellow].....More >>[/COLOR]'}, img=more_image) xbmcplugin.endOfDirectory(int(sys.argv[1]))
def Browse(section): add_dir_title() url_content = net.http_GET(BASEURL + 'home', headers=headers).content try: url_content = univ_common.str_conv(url_content) except: url_content = net.http_GET(BASEURL, headers=headers).content url_content = univ_common.str_conv(url_content) url_content = re.sub("<!--.+?-->", " ", url_content) cats = re.search("(?s)<div id=\"" + section + "\-2\".+?<ul>(.+?)</ul>", url_content) if cats: cats = cats.group(1) for cat in re.finditer("<li.*><a href=[\"'](.+?)[\"'].+?>(.+?)</a>", cats): cat_url = cat.group(1) cat_title = cat.group(2) if 'tna/ppv-tna' in cat_url: cat_title = cat_title + ' ( TNA )' elif 'wwe/ppv' in cat_url: cat_title = cat_title + ' ( WWE )' image = os.path.join(IconPath, cat_url[cat_url[0:cat_url.rfind('/')].rfind('/')+1:cat_url.rfind('/')] + '.jpg') addon.add_directory({'mode' : 'Page', 'title': cat_title, 'img' : image, 'url' : cat_url, 'page' : '1', 'sort': 'date', 'sortorder' : 'desc'}, {'title': cat_title}, img=image) xbmcplugin.endOfDirectory(int(sys.argv[1]))
def add_video_item(video_type, section, link, vidtitle, vidname, year='', imdb='', season_num=0, episode_num=0, totalitems=0, favourite=False, img='', add_as_dir=True): meta = get_metadata(video_type, vidtitle, vidname, year, imdb=imdb, season_num=season_num, episode_num=episode_num, img=img) if video_type == VideoType_Movies: contextMenuItems = add_contextmenu(meta_setting, video_type, link, univ_common.str_conv(addon.decode(vidtitle)), meta['title'], favourite, watched=meta['overlay'], imdb=meta['imdb_id'], year=meta['year'], img=img) #contextMenuItems = add_contextmenu(meta_setting, video_type, link, univ_common.str_conv(addon.decode(vidtitle)), vidtitle, favourite, imdb=imdb, year=year, img=img) else: contextMenuItems = add_contextmenu(meta_setting, video_type, link, univ_common.str_conv(addon.decode(vidtitle)), meta['title'], favourite, watched=meta['overlay'], imdb=meta['imdb_id'], season_num=season_num, episode_num=episode_num, img=img) if video_type == VideoType_Movies: infolabels = {'supports_meta' : 'true', 'video_type' : video_type, 'name' : vidtitle, 'imdb_id' : meta['imdb_id'], 'year' : meta['year']} queries = {'url': link, 'video_type': video_type, 'imdb_id': meta['imdb_id'], 'title': vidtitle, 'name': vidname, 'year': meta['year'], 'img': meta['cover_url'], 'fanart': meta['backdrop_url']} if add_as_dir == True: queries['mode'] = 'links' else: queries['play'] = 'true' addon.add_directory(queries, meta, contextMenuItems, context_replace=True, img=img, fanart=meta['backdrop_url'], total_items=totalitems) elif video_type == VideoType_Episode: video_title = '' season_episode = 's' + str(season_num) + 'e' + str(episode_num) meta_season_episode = 'Episode: ' + str(episode_num) fav_season_episode = 'Season: ' + str(season_num) + ' Episode: ' + str(episode_num) if meta_setting: favpretitle = vidtitle + ' - ' + fav_season_episode pretitle = vidtitle + ' - ' + season_episode meta_pretitle = meta_season_episode if meta['title']: fav_video_title = favpretitle + ' - ' + meta['title'] video_title = pretitle + ' - ' + meta['title'] meta['title'] = meta_pretitle + ' - ' + meta['title'] else: fav_video_title = favpretitle video_title = pretitle meta['title'] = meta_pretitle else: fav_video_title = meta['title'] + ' - ' + fav_season_episode video_title = meta['title'] + ' - ' + season_episode meta['title'] = meta_season_episode if favourite: meta['title'] = fav_video_title infolabels = {'supports_meta' : 'true', 'video_type' : video_type, 'name' : vidtitle, 'imdb_id' : meta['imdb_id'], 'season': season_num, 'episode' : episode_num} queries = {'url': link, 'video_type': video_type, 'imdb_id': meta['imdb_id'], 'show' : vidtitle, 'title': video_title, 'name': vidname, 'season': season_num, 'episode' : episode_num, 'img': meta['cover_url'], 'fanart': meta['backdrop_url']} if add_as_dir == True: queries['mode'] = 'links' else: queries['play'] = 'true' #p_url = fav.build_url(queries) #contextMenuItems.insert(1, ('Add to Favorites', fav.add_directory(fav_video_title, p_url, section_title='TV', sub_section_title='Episodes', img=meta['cover_url'], fanart=meta['backdrop_url'], infolabels=infolabels))) addon.add_directory(queries, meta, contextMenuItems, context_replace=True, img=meta['cover_url'], fanart=meta['backdrop_url'], total_items=totalitems)
def GetLinks(url): url = BASEURL + '/' + url movie_content = net.http_GET(url).content movie_content = addon.unescape(movie_content) movie_content = unescape(movie_content) #movie_content = re.sub("\\\"", "\"", movie_content) try: movie_content = movie_content.decode("ISO-8859-1") movie_content= movie_content.encode("UTF-8") except: pass from universal import _common as univ_common movie_content = univ_common.str_conv(addon.decode(movie_content)).replace(' ','').replace(' ','').replace(' ','').replace(' ','').replace(' ','') container_pattern = r'<table[^>]+class="movie_version[ "][^>]*>(.*?)</table>' item_pattern = ( r'quality_(?!sponsored|unknown)([^>]*)></span>.*?' r'url=([^&]+)&(?:amp;)?domain=([^&]+)&(?:amp;)?(.*?)' r'"version_veiws"> ([\d]+) views</') for version in re.finditer(container_pattern, movie_content, re.DOTALL | re.IGNORECASE): for source in re.finditer(item_pattern, version.group(1), re.DOTALL): link_quality, link_url, link_title, link_parts, link_views = source.groups() host = link_title.decode('base-64').lower() hosted_media = urlresolver.HostedMediaFile(host=host, media_id='DUMMY') if hosted_media: #add_video_link(video_type, link_url.decode('base-64'), title, '[COLOR pink]' + title + '[/COLOR] [COLOR red][' + link_quality.upper() + '][/COLOR] [COLOR yellow]: ' + link_title.decode('base-64').upper() + '[/COLOR] (' + link_views + ' views)', img=img, fanart=fanart, totalitems= len(source.groups()) ) add_video_link(video_type, link_url.decode('base-64'), title, '[COLOR pink]' + title + '[/COLOR] [COLOR red][' + link_quality.upper() + '][/COLOR] [COLOR yellow]: ' + link_title.decode('base-64').upper() + '[/COLOR]', img=img, fanart=fanart, totalitems= len(source.groups()) )
def Browse_LatestEpisodes(mmurl): url_content=nURL(mainSite); les=re.search(r"(?s)<h4>Latest Episodes</h4>(.+?)<h4", url_content).group(1); les=_addon.unescape(les); les=unescape(les) from universal import _common les=_common.str_conv(les) for le in re.finditer(r'<li.+?class="(.+?)".+?<a.+?href="(.+?)".+?<img.+? src="(.+?)".+?title">(.+?)</div>', les): le_typ=le.group(1); le_url=le.group(2); le_img=le.group(3); le_ttl=le.group(4) contextLabs={'title':le_ttl,'year':'0000','url':le_url,'img':le_img,'fanart':le_img,'DateAdded':'','type':le_typ}; contextMenuItems=ContextMenu_Episodes(labs=contextLabs) try: _addon.add_directory({'mode':'Hosts','site':site,'section':section,'title':le_ttl,'url':le_url,'fanart':le_img,'img':le_img},{'title':cFL_(le_ttl,colors['6'])},is_folder=True,fanart=le_img,img=le_img,contextmenu_items=contextMenuItems) except: t='' set_view('episodes',int(addst('episode-view'))); eod()
def Browse(url): browse_url = url + '/?' print browse_url if section: browse_url = browse_url + section + '&' browse_url = browse_url + 'p=' + str( int(page) * items_per_page ) content = net.http_GET(browse_url).content content = addon.unescape(content) content = unescape(content) import urllib from universal import _common as univ_common movies_1 = re.search("<ul class=\"thumbnails\">(.*)", content) if movies_1: content = movies_1.group(1) movie_count = 0 movies = re.compile("<li class=\"\".+?<a href=\"(" + BASEURL + "/.+?)\".+?<img.+?src=\"(.+?)\".+?<div class=\"title.+?>(.+?) [\(]{0,1}([0-9]{2,4})").findall(content) for movie_url, movie_img, movie_title, movie_year in movies: if video_type == VideoType_Movies: add_video_item(video_type, video_type, movie_url, univ_common.str_conv(movie_title.strip()), univ_common.str_conv(movie_title.strip()), year=movie_year, totalitems=len(movies), img=movie_img, add_as_dir=True) elif video_type == VideoType_TV: movie_title = re.sub("\(.+?\)", "", movie_title).strip() add_video_directory('tvseasons', video_type, movie_url, univ_common.str_conv(movie_title.strip()), univ_common.str_conv(movie_title.strip()), totalitems=len(movies), img=movie_img) movie_count = movie_count + 1 if movie_count >= items_per_page: addon.add_directory({'mode': mode, 'url' : url, 'title' : title, 'section' : section, 'page' : str(int(page) + 1), 'video_type' : video_type }, {'title': 'Next Page >>'}) content_type = None view_setting_id = 'default-view' if video_type == VideoType_Movies: content_type = 'movies' view_setting_id = 'movie-view' elif video_type == VideoType_TV: content_type = 'tvshows' view_setting_id = 'tvshow-view' setView(content_type, view_setting_id)
def GetLatest(): add_dir_title() url_content = net.http_GET(BASEURL + 'home', headers=headers).content try: url_content = univ_common.str_conv(url_content) except: url_content = net.http_GET(BASEURL, headers=headers).content url_content = univ_common.str_conv(url_content) url_content = re.sub("<!--.+?-->", " ", url_content) soup = BeautifulSoup(url_content, "html5lib") for section in soup.find_all("div", class_="section-box"): latest_title = section.find("span", class_="name").string more_url = section.find("a", class_="more-link")["href"] latest_items = section.find_all("a", class_="clip-link") more_title = latest_title more_title = more_title.replace('Latest', '') more_title = more_title.replace('Shows', '') more_title = more_title.replace('Wrestling', '') more_title = more_title.strip() more_image = os.path.join(IconPath, more_title.lower().replace(' ','-') + '.jpg') addon.add_directory({'mode' : 'DUMMY-DIR'}, {'title': '[COLOR blue]' + latest_title + '[/COLOR]'}, img=more_image) for item in latest_items: item_title = univ_common.str_conv(addon.decode(item["title"])) item_url = item["href"] item_image = item.img["src"] addon.add_directory({'mode' : 'GetLinks', 'url' : item_url, 'title' : item_title, 'img':item_image}, {'title': '.....' + item_title}, img=item_image) addon.add_directory({'mode' : 'Page', 'url' : more_url, 'page' : '1', 'sort': 'date', 'sortorder' : 'desc', 'title' : more_title, 'img' : more_image}, {'title': '[COLOR yellow].....More >>[/COLOR]'}, img=more_image) xbmcplugin.endOfDirectory(int(sys.argv[1]))
def onPlayBackStarted(self): """ Called when playback started. Checks database to see if video has been watched before. If video has been viewed before and it has been viewed for longer than 30 seconds, ask the user if they want to jump to the last viewed place or to start the video over. """ win = xbmcgui.Window(10000) win.setProperty("pbe.playing.playbackstopped", "false") self.addon_id = win.getProperty("pbe.playing.addon_id") self.video_type = win.getProperty("pbe.playing.video_type") self.title = common.str_conv(win.getProperty("pbe.playing.title")) self.season = win.getProperty("pbe.playing.season") self.year = win.getProperty("pbe.playing.year") self.episode = win.getProperty("pbe.playing.episode") self.hash = win.getProperty("pbe.playing.hash") self.imdb_id = win.getProperty("pbe.playing.imdb") common.addon.log( "-" + HELPER + "- -" + "Beginning Playback: addon: %s, title: %s, year: %s, season: %s, episode: %s" % (self.addon_id, self.title, self.year, self.season, self.episode) ) self._totalTime = self.getTotalTime() self._tracker = threading.Thread(target=self._trackPosition) self._tracker.start() self._connect_to_db() sql_select = "SELECT bookmark FROM bookmarks WHERE hash='%s'" % self.hash common.addon.log("-" + HELPER + "- -" + sql_select, 2) self.dbcur.execute(sql_select) bookmark = self.dbcur.fetchone() self._close_db() if bookmark: bookmark = float(bookmark["bookmark"]) if not self._sought and bookmark - 30 > 0: common.addon.log("-" + HELPER + "- -" + "Showing Dialog") question = xbmc.getLocalizedString(12022) % format_time(bookmark) # 12022 = Resume from %s resume = xbmcgui.Dialog() resume = resume.yesno( self.title, "", question, "", xbmc.getLocalizedString(20132), xbmc.getLocalizedString(13404) ) # 20132 = Restart Video 13404 = Resume if resume: self.seekTime(bookmark) self._sought = True
def GetLatest(): url_content = net.http_GET(BASEURL).content les = re.search(r"(?s)<h4>Latest Episodes</h4>(.+?)<h4", url_content).group(1) les = addon.unescape(les) les = unescape(les) from universal import _common les = _common.str_conv(les) for le in re.finditer(r"<li.+?class=\"(.+?)\".+?<a.+?href=\"(.+?)\".+?<img.+? src=\"(.+?)\".+?title\">(.+?)</div>", les): le_typ = le.group(1) le_url = le.group(2) le_img = le.group(3) le_ttl = le.group(4) addon.add_directory({'mode' : 'links', 'title' : le_ttl, 'img' : le_img, 'url' : le_url}, {'title': le_ttl}, img= le_img) xbmcplugin.endOfDirectory(int(sys.argv[1]))
def GetLinks(url): movie_content = net.http_GET(url).content movie_content = addon.unescape(movie_content) movie_content = unescape(movie_content) movie_content = re.sub("\\\"", "\"", movie_content) from universal import _common as univ_common movie_content = univ_common.str_conv(addon.decode(movie_content)) movie_links = re.compile("<a href=\"(" + BASEURL + "/play/[0-9]+?)\".+?<img.+?> (.+?)</a>.+?<td>.+?<td>.+?<td>(.+?)</td>", re.DOTALL).findall(movie_content) for link_url, link_title, link_quality in movie_links: if link_title.startswith("."): link_title = link_title[1:].capitalize() host = link_title.lower() hosted_media = urlresolver.HostedMediaFile(host=host, media_id='DUMMY') if hosted_media: add_video_link(video_type, link_url, title, '[' + link_quality.upper() + '] - ' + link_title, img=img, fanart=fanart, totalitems= len(movie_links) )
def iWatchLINK(mname,url): xbmc.executebuiltin("XBMC.Notification(Please Wait!,Collecting Hosts,1500)") link=main.OPENURL(url) movie_content = main.unescapes(link) movie_content = re.sub("\\\"", "\"", movie_content) movie_content=movie_content.replace('\'','') from universal import _common as univ_common link2 = univ_common.str_conv(addon.decode(movie_content)) main.addLink("[COLOR red]For Download Options, Bring up Context Menu Over Selected Link.[/COLOR]",'','') match=re.compile('<a href="(.+?)".+?<img.+?> (.+?)</a>.+?<td>.+?<td>.+?<td>(.+?)</td>', re.DOTALL).findall(link2) for url, name, qua in match[1:]: name=name.replace(' ','') if name[0:1]=='.': name=name[1:] name=name.split('.')[0] #hosted_media = urlresolver.HostedMediaFile(host=name.lower(), media_id=name.lower()) #if hosted_media: main.addDown2(mname+' [COLOR red]('+qua+')[/COLOR]'+' [COLOR blue]'+name.upper()+'[/COLOR]',url,649,art+'/hosts/'+name.lower()+'.png',art+'/hosts/'+name.lower()+'.png')
def onPlayBackStarted(self): ''' Called when playback started. Checks database to see if video has been watched before. If video has been viewed before and it has been viewed for longer than 30 seconds, ask the user if they want to jump to the last viewed place or to start the video over. ''' win = xbmcgui.Window(10000) win.setProperty('pbe.playing.playbackstopped', 'false') self.addon_id = win.getProperty('pbe.playing.addon_id') self.video_type = win.getProperty('pbe.playing.video_type') self.title = common.str_conv(win.getProperty('pbe.playing.title')) self.season = win.getProperty('pbe.playing.season') self.year = win.getProperty('pbe.playing.year') self.episode = win.getProperty('pbe.playing.episode') self.hash = win.getProperty('pbe.playing.hash') self.imdb_id = win.getProperty('pbe.playing.imdb') common.addon.log('-' + HELPER + '- -' +'Beginning Playback: addon: %s, title: %s, year: %s, season: %s, episode: %s' % ( self.addon_id, self.title, self.year, self.season, self.episode) ) self._totalTime = self.getTotalTime() self._tracker = threading.Thread(target=self._trackPosition) self._tracker.start() self._connect_to_db() sql_select = "SELECT bookmark FROM bookmarks WHERE hash='%s'" % self.hash common.addon.log('-' + HELPER + '- -' +sql_select, 2) self.dbcur.execute(sql_select) bookmark = self.dbcur.fetchone() self._close_db() if bookmark: bookmark = float(bookmark['bookmark']) if not self._sought and bookmark-30 > 0: common.addon.log('-' + HELPER + '- -' +'Showing Dialog') question = xbmc.getLocalizedString(12022) % format_time(bookmark) # 12022 = Resume from %s resume = xbmcgui.Dialog() resume = resume.yesno(self.title, '', question, '', xbmc.getLocalizedString(20132), xbmc.getLocalizedString(13404)) # 20132 = Restart Video 13404 = Resume if resume: self.seekTime(bookmark) self._sought = True
def PANEL_REPLACER(content): panel_exists = True panel_id = 0 while panel_exists == True: panel_name = "panel-id." + str(panel_id) panel_search_pattern = "(?s)\"" + panel_name + "\"\:\[\{(.+?)\}\]" panel_data = re.search(panel_search_pattern, content) if panel_data: panel_data = panel_data.group(1) content = re.sub("begin " + panel_name, "-->" + panel_data + "<!--", content) content = re.sub(panel_search_pattern, "panel used", content) panel_id = panel_id + 1 else: panel_exists = False content = addon.unescape(content) content = main.unescapes(content) content = re.sub("\\\"", "\"", content) from universal import _common as univ_common content = univ_common.str_conv(addon.decode(content)) return content
def GetPage(url, page, sort, sortorder, options): if options: xbmcdlg = xbmcgui.Dialog() dlg_title = '' select_list = None select_list_v = None if options == 'sortby': dlg_title = 'Sort By' select_list = ['Date', 'Views', 'Likes', 'Comments'] select_list_v = ['date', 'views', 'likes', 'comments'] elif options == 'sortorder': dlg_title = 'Sort Order' select_list = ['Ascending', 'Descending'] select_list_v = ['asc', 'desc'] elif options == 'gotopage': dlg_title = 'Goto Page' if select_list: ret = xbmcdlg.select(dlg_title, select_list) if options == 'sortby': sort = select_list_v[ret] elif options == 'sortby': sortorder = select_list_v[ret] else: ret = xbmcdlg.numeric(0, dlg_title, page) if ret != 'cancelled': ret_num = int(ret) if (ret_num > 0 and ret_num != int(page) and ret_num <= int(tp)): page = str(ret_num) else: return add_dir_title() order = '?orderby=' + sort + '&order=' + sortorder page_url = url + 'page/' + page + '/' + order url_content = net.http_GET(page_url, headers=headers).content try: url_content = univ_common.str_conv(url_content) except: url_content = net.http_GET(page_url, headers=headers).content url_content = univ_common.str_conv(url_content) ''' Page, Goto Page, Sort options ''' totl_page = '1' page_of = re.search("<span class='pages'>Page ([0-9]+?) of ([0-9]+?)</span>", url_content) if page_of: totl_page = page_of.group(2) addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : page, 'sort': sort, 'sortorder' : sortorder, 'options' : 'gotopage', 'tp' : totl_page}, {'title': '[COLOR red]Page ' + page + ' of ' + totl_page + '[/COLOR]'}) addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : page, 'sort': sort, 'sortorder' : sortorder, 'options' : 'sortby'}, {'title': '[COLOR blue]Sort By: [/COLOR][COLOR white]' + sort.title() + '[/COLOR]'}) sort_order = 'Descending' if sortorder == 'asc': sort_order = 'Ascending' addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : page, 'sort': sort, 'sortorder' : sortorder, 'options' : 'sortorder'}, {'title': '[COLOR blue]Sort Order: [/COLOR][COLOR white]' + sort_order.title() + '[/COLOR]'}) url_content = re.search("(?s)>(?:Category|Monthly Archives)(.+?)<div id=\"sidebar\" role=\"complementary\">", url_content).group(1) first_page = re.search("class=('first'|\"prev\")", url_content) if first_page: addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : '1', 'sort': sort, 'sortorder' : sortorder, 'tp' : totl_page, 'type':'notsubfolder'}, {'title': '[COLOR yellow]<< First Page[/COLOR]'}) addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : int(page) - 1, 'sort': sort, 'sortorder' : sortorder, 'tp' : totl_page, 'type':'notsubfolder'}, {'title': '[COLOR yellow]< Previous Page[/COLOR]'}) for item in re.finditer(r"(?s)<a class=\"clip-link\".+?title=\"(.+?)\".+?href=\"(.+?)\".+?img src=\"(.+?)\"", url_content): item_title = univ_common.str_conv(addon.decode(item.group(1))) item_url = item.group(2) item_image = item.group(3) addon.add_directory({'mode' : 'GetLinks', 'url' : item_url, 'title' : item_title, 'img':item_image}, {'title': item_title}, img=item_image) last_page = re.search("class=('last'|\"next\")", url_content) if last_page: addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : int(page) + 1, 'sort': sort, 'sortorder' : sortorder, 'tp' : totl_page, 'type':'notsubfolder'}, {'title': '[COLOR yellow]Next Page > [/COLOR]'}) addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : totl_page, 'sort': sort, 'sortorder' : sortorder, 'tp' : totl_page, 'type':'notsubfolder'}, {'title': '[COLOR yellow]Last Page >> [/COLOR]'}) upd_list = False if (options) or (type != 'subfolder'): upd_list = True xbmcplugin.endOfDirectory(int(sys.argv[1]), updateListing=upd_list)
def GetPage(url, page, sort, sortorder, options): if options: xbmcdlg = xbmcgui.Dialog() dlg_title = '' select_list = None select_list_v = None if options == 'sortby': dlg_title = 'Sort By' select_list = ['Date', 'Views', 'Likes', 'Comments'] select_list_v = ['date', 'views', 'likes', 'comments'] elif options == 'sortorder': dlg_title = 'Sort Order' select_list = ['Ascending', 'Descending'] select_list_v = ['asc', 'desc'] elif options == 'gotopage': dlg_title = 'Goto Page' if select_list: ret = xbmcdlg.select(dlg_title, select_list) if options == 'sortby': sort = select_list_v[ret] elif options == 'sortby': sortorder = select_list_v[ret] else: ret = xbmcdlg.numeric(0, dlg_title, page) if ret != 'cancelled': ret_num = int(ret) if (ret_num > 0 and ret_num != int(page) and ret_num <= int(tp)): page = str(ret_num) else: return add_dir_title() order = '?orderby=' + sort + '&order=' + sortorder page_url = url + 'page/' + page + '/' + order url_content = net.http_GET(page_url, headers=headers).content try: url_content = univ_common.str_conv(url_content) except: url_content = net.http_GET(page_url, headers=headers).content url_content = univ_common.str_conv(url_content) soup = BeautifulSoup(url_content, "html5lib") ''' Page, Goto Page, Sort options ''' totl_page = '1' page_of = re.search("<span class='pages'>Page ([0-9]+?) of ([0-9]+?)</span>", url_content) if page_of: totl_page = page_of.group(2) addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : page, 'sort': sort, 'sortorder' : sortorder, 'options' : 'gotopage', 'tp' : totl_page}, {'title': '[COLOR red]Page ' + page + ' of ' + totl_page + '[/COLOR]'}) addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : page, 'sort': sort, 'sortorder' : sortorder, 'options' : 'sortby'}, {'title': '[COLOR blue]Sort By: [/COLOR][COLOR white]' + sort.title() + '[/COLOR]'}) sort_order = 'Descending' if sortorder == 'asc': sort_order = 'Ascending' addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : page, 'sort': sort, 'sortorder' : sortorder, 'options' : 'sortorder'}, {'title': '[COLOR blue]Sort Order: [/COLOR][COLOR white]' + sort_order.title() + '[/COLOR]'}) first_page = soup.find("a", class_="first") if first_page: addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : '1', 'sort': sort, 'sortorder' : sortorder, 'tp' : totl_page, 'type':'notsubfolder'}, {'title': '[COLOR yellow]<< First Page[/COLOR]'}) prev_page = soup.find("a", class_="previouspostslink") if prev_page: addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : int(page) - 1, 'sort': sort, 'sortorder' : sortorder, 'tp' : totl_page, 'type':'notsubfolder'}, {'title': '[COLOR yellow]< Previous Page[/COLOR]'}) for item in soup.find("div", id="content").find_all("a", class_="clip-link"): item_title = univ_common.str_conv(addon.decode(item["title"])) item_url = item["href"] item_image = item.img["src"] addon.add_directory({'mode' : 'GetLinks', 'url' : item_url, 'title' : item_title, 'img':item_image}, {'title': item_title}, img=item_image) last_page = soup.find("a", class_="last") if last_page: addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : int(page) + 1, 'sort': sort, 'sortorder' : sortorder, 'tp' : totl_page, 'type':'notsubfolder'}, {'title': '[COLOR yellow]Next Page > [/COLOR]'}) next_page = soup.find("a", class_="nextpostslink") if next_page: addon.add_directory({'mode' : 'Page', 'title': title, 'img' : img, 'url' : url, 'page' : totl_page, 'sort': sort, 'sortorder' : sortorder, 'tp' : totl_page, 'type':'notsubfolder'}, {'title': '[COLOR yellow]Last Page >> [/COLOR]'}) upd_list = False if (options) or (type != 'subfolder'): upd_list = True xbmcplugin.endOfDirectory(int(sys.argv[1]), updateListing=upd_list)
def add_item(self, title, url, fmtd_title='', level='0', parent_title='', indent_title='', infolabels='', img='', fanart='', is_playable=False, is_folder=False): ''' Add an item to watch history. Args: title (str): title of the item; used to generate title-hash and sorting url (str): the compelte plugin url that would be called when this item is selected Kwargs: fmtd_title (str): title of the item as it will be displayed in the list. if fmtd_title is None: fmtd_title = title level (str): item level in the hierarchy. Used if playable-item's parent is also being added to the favorites. Non-parent's level is '0' Parent's level starts with '1' Should be covnertiable to integer parent_title (str): If the item has a parent, then the title used to identify the parent indent_title (str): Title to be used in parent-indent mode (WIP) If indent_title is None: indent_title = fmtd_title info_labels (hash): Any information that the calling plugin might need when the item is being retreived goes here. This is also used to set support for metadata for the item with watch history. infolabels = { 'supports_meta' : 'true', 'video_type':video_type, 'name':title, 'imdb_id':imdb_id, 'season':season, 'episode':episode, 'year':year } img (str): url or path of the image to be used as thumbnail and icon of the item fanart (str): url or path of the image to be used as fanart of the item is_playable (bool): set the item isPlayable property is_folder (bool): set the item isFolder property ''' if url.find('&watchhistory=true'): url = url.replace('&watchhistory=true', '') elif url.find('?watchhistory=true&'): url = url.replace('?watchhistory=true&', '?') title = common.str_conv(title) if not fmtd_title: fmtd_title = title else: fmtd_title = common.str_conv(fmtd_title) if not indent_title: indent_title = fmtd_title else: indent_title = common.str_conv(indent_title) hash_title = hashlib.md5(title).hexdigest() if parent_title: parent_title = common.str_conv(parent_title) if parent_title: parent_title = hashlib.md5(parent_title).hexdigest() row_exists = True try: if DB == 'mysql': sql_select = "SELECT * FROM watch_history WHERE addon_id = %s AND hash_title = %s" else: sql_select = "SELECT * FROM watch_history WHERE addon_id = ? AND hash_title = ?" common.addon.log( '-' + HELPER + '- -' + '%s : %s, %s' % (sql_select, self.addon_id, hash_title), 2) self.dbcur.execute(sql_select, (self.addon_id, hash_title)) common.addon.log( '-' + HELPER + '- -' + str(self.dbcur.fetchall()[0]), 2) except: row_exists = False sql_update_or_insert = '' if row_exists == True: if DB == 'mysql': sql_update_or_insert = "UPDATE watch_history SET lastwatched = %s WHERE addon_id = %s AND hash_title = %s" else: sql_update_or_insert = "UPDATE watch_history SET lastwatched = ? WHERE addon_id = ? AND hash_title = ?" common.addon.log( '-' + HELPER + '- -' + '%s : %s, %s, %s' % (sql_update_or_insert, 'datetime.datetime.now()', self.addon_id, hash_title), 2) self.dbcur.execute( sql_update_or_insert, (datetime.datetime.now(), self.addon_id, hash_title)) else: if DB == 'mysql': sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" else: sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" if infolabels: infolabels = common.encode_dict(infolabels) is_playable = common.bool2str(is_playable) is_folder = common.bool2str(is_folder) infolabels = str(infolabels) common.addon.log( '-' + HELPER + '- -' + '%s : %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' % (sql_update_or_insert, self.addon_id, hash_title, title, fmtd_title, common.str_conv(url), infolabels, img, fanart, is_playable, is_folder, 'datetime.datetime.now()', level, parent_title, indent_title), 2) self.dbcur.execute( sql_update_or_insert, (self.addon_id, hash_title, title, fmtd_title, url, infolabels, img, fanart, is_playable, is_folder, datetime.datetime.now(), level, parent_title, indent_title)) self.dbcon.commit()
def add_item(self, title, url, fmtd_title = '', level='0', parent_title='', indent_title='', infolabels='', img='', fanart='', is_playable=False, is_folder=False): ''' Add an item to watch history. Args: title (str): title of the item; used to generate title-hash and sorting url (str): the compelte plugin url that would be called when this item is selected Kwargs: fmtd_title (str): title of the item as it will be displayed in the list. if fmtd_title is None: fmtd_title = title level (str): item level in the hierarchy. Used if playable-item's parent is also being added to the favorites. Non-parent's level is '0' Parent's level starts with '1' Should be covnertiable to integer parent_title (str): If the item has a parent, then the title used to identify the parent indent_title (str): Title to be used in parent-indent mode (WIP) If indent_title is None: indent_title = fmtd_title info_labels (hash): Any information that the calling plugin might need when the item is being retreived goes here. This is also used to set support for metadata for the item with watch history. infolabels = { 'supports_meta' : 'true', 'video_type':video_type, 'name':title, 'imdb_id':imdb_id, 'season':season, 'episode':episode, 'year':year } img (str): url or path of the image to be used as thumbnail and icon of the item fanart (str): url or path of the image to be used as fanart of the item is_playable (bool): set the item isPlayable property is_folder (bool): set the item isFolder property ''' if url.find('&watchhistory=true'): url = url.replace('&watchhistory=true', '') elif url.find('?watchhistory=true&'): url = url.replace('?watchhistory=true&', '?') title = common.str_conv(title) if not fmtd_title: fmtd_title = title else: fmtd_title = common.str_conv(fmtd_title) if not indent_title: indent_title = fmtd_title else: indent_title = common.str_conv(indent_title) hash_title = hashlib.md5(title).hexdigest() if parent_title: parent_title = common.str_conv(parent_title) if parent_title: parent_title = hashlib.md5(parent_title).hexdigest() row_exists = True try: if DB == 'mysql': sql_select = "SELECT * FROM watch_history WHERE addon_id = %s AND hash_title = %s" else: sql_select = "SELECT * FROM watch_history WHERE addon_id = ? AND hash_title = ?" common.addon.log('-' + HELPER + '- -' + '%s : %s, %s' %(sql_select, self.addon_id, hash_title), 2 ) self.dbcur.execute(sql_select, (self.addon_id, hash_title)) common.addon.log('-' + HELPER + '- -' + str(self.dbcur.fetchall()[0]), 2) except: row_exists = False sql_update_or_insert = '' if row_exists == True: if DB == 'mysql': sql_update_or_insert = "UPDATE watch_history SET lastwatched = %s WHERE addon_id = %s AND hash_title = %s" else: sql_update_or_insert = "UPDATE watch_history SET lastwatched = ? WHERE addon_id = ? AND hash_title = ?" common.addon.log('-' + HELPER + '- -' + '%s : %s, %s, %s' %(sql_update_or_insert, 'datetime.datetime.now()', self.addon_id, hash_title), 2 ) self.dbcur.execute(sql_update_or_insert, (datetime.datetime.now(), self.addon_id, hash_title)) else: if DB == 'mysql': sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" else: sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" if infolabels: infolabels = common.encode_dict(infolabels) is_playable = common.bool2str(is_playable) is_folder = common.bool2str(is_folder) infolabels = str(infolabels) common.addon.log('-' + HELPER + '- -' + '%s : %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' %(sql_update_or_insert, self.addon_id, hash_title, title, fmtd_title, common.str_conv(url), infolabels, img, fanart, is_playable, is_folder, 'datetime.datetime.now()', level, parent_title, indent_title), 2 ) self.dbcur.execute(sql_update_or_insert, (self.addon_id, hash_title, title, fmtd_title, url, infolabels, img, fanart, is_playable, is_folder, datetime.datetime.now(), level, parent_title, indent_title)) self.dbcon.commit()
def GetLinks(url): from universal import _common as univ_common add_dir_title() url_content = net.http_GET(url, headers=headers).content try: url_content = univ_common.str_conv(url_content) except: url_content = net.http_GET(url, headers=headers).content url_content = univ_common.str_conv(url_content) url_content = re.sub("<!--.+?-->", " ", url_content) super_headers_re = '<h3><span.+?font-size: 40px;.+?>(.+?)</' if 'wwf-attitude-era' in url: if not re.search('<h3><span style="font-size: 30px;', url_content): super_headers_re = '(?s)<div style=\"text-align: center;\"><span.+?>(.+?)</.+?<p>.+?</(p|div)></' super_headers = re.compile(super_headers_re).findall(url_content) super_header_item = 0 super_header_title = '' if super_headers: if len(super_headers) == 1: super_headers = None if super_headers: super_header_title = ' - ' + super_headers[super_header_item] addon.add_directory({'mode' : 'DUMMY-DIR'}, {'title': '[COLOR red]' + super_headers[super_header_item] + '[/COLOR]'}) super_header_item = super_header_item + 1 try: if re.search('"lockerId":', url_content): # page has hidden links ajax_url = BASEURL + 'wp-admin/admin-ajax.php' locker_id = re.compile("\"lockerId\":\"(.+?)\"").findall(url_content)[0] action = 'opanda_loader' hash = re.compile("\"contentHash\":\"(.+?)\"").findall(url_content)[0] hidden_items = net.http_POST(ajax_url, {'lockerId': locker_id, 'action': action, 'hash': hash}, headers=headers).content soup = BeautifulSoup(hidden_items, "html5lib") for hidden_item in soup.find_all(True): if hidden_item.name == "span": hi_title = hidden_item.string hi_title_super = hi_title if super_headers: hi_title_super = '.....' + hi_title addon.add_directory({'mode' : 'DUMMY-DIR'}, {'title': '[COLOR blue]' + hi_title_super + '[/COLOR]'}) elif hidden_item.name == "a": hi_link_title = hidden_item.string hi_link_url = hidden_item["href"] hi_link_title_super = hi_link_title if super_headers: hi_link_title_super = '.....' + hi_link_title contextMenuItems = [] queries = {'mode' : 'GetMedia', 'url' : hi_link_url, 'title' : title + super_header_title + ' - ' + hi_link_title, 'historytitle' : title, 'historylink': sys.argv[0]+sys.argv[2], 'img':img} contextMenuItems.insert(0, ('Queue Item', playbackengine.QueueItem(addon_id, title + super_header_title + ' - ' + hi_link_title, addon.build_plugin_url( queries ) ) ) ) addon.add_directory(queries, {'title': '.....' + hi_link_title_super},contextMenuItems, context_replace=False, img=img) except: pass regular_item_re = "(?s)<div style=\"text-align: center;\"><span.+?>(.+?)</.+?<p>(.+?)</(p|div)>" if 'wwf-attitude-era' in url: if not re.search('<h3><span style="font-size: 30px;', url_content): regular_item_re = "(?s)<h3><span.+?font-size: 40px;.+?>(.+?)</.+?<p>(.+?)</(p|div)>" else: #<h3><span style="font-size: 40px; color: #2F4F4F;">Pay-Per-View 1999</span></h3> ppv_item = re.search("(<h3><span.+?font-size: 40px;.+?>Pay-Per-View.+?</)", url_content) if ppv_item: ppv_item = ppv_item.group(1) ppv_content = re.search("(?s)" + ppv_item + "(.+?)</div>", url_content).group(1) ppv_content = re.sub("</p>", "", ppv_content) ppv_new = ppv_item + '<h3><span style="font-size: 30px;">PPV Events</span></h3>' + ppv_content url_content = re.sub(ppv_item, ppv_new, url_content) regular_item_re = "(?s)<h3><span.+?font-size: 30px;.+?>(.+?)</.+?<p>(.+?)</(p|div)>" for regular_item in re.finditer(regular_item_re,url_content): ri_title = regular_item.group(1) ri_links = regular_item.group(2) ri_title_super = ri_title if super_headers: ri_title_super = '.....' + ri_title addon.add_directory({'mode' : 'DUMMY-DIR'}, {'title': '[COLOR blue]' + ri_title_super + '[/COLOR]'}) for ri_link in re.finditer("(?s)<a.+?href=\"(.+?)\".+?>(.+?)</", ri_links): ri_link_title = ri_link.group(2) ri_link_title = univ_common.str_conv(addon.unescape(ri_link_title)) ri_link_url = ri_link.group(1) ri_link_title_super = ri_link_title if super_headers: ri_link_title_super = '.....' + ri_link_title contextMenuItems = [] queries = {'mode' : 'GetMedia', 'url' : ri_link_url, 'title' : title + super_header_title + ' - ' + ri_link_title, 'historytitle' : title, 'historylink': sys.argv[0]+sys.argv[2], 'img':img} contextMenuItems.insert(0, ('Queue Item', playbackengine.QueueItem(addon_id, title + super_header_title + ' - ' + ri_link_title, addon.build_plugin_url( queries ) ) ) ) addon.add_directory(queries, {'title': '.....' + ri_link_title_super},contextMenuItems, context_replace=False, img=img) if super_headers: end_item = "h3>" if 'Pay-Per-View' in super_header_title: end_item = "dummy" elif 'wwf-attitude-era' in url: if re.search('<h3><span style="font-size: 30px;', url_content): end_item = "p" if re.search('href="' + ri_link_url.replace('?', '\?') + '" target="_blank">' + ri_link_title + '</a></p>\n<' + end_item, url_content): super_header_title = ' - ' + super_headers[super_header_item] addon.add_directory({'mode' : 'DUMMY-DIR'}, {'title': '[COLOR red]' + super_headers[super_header_item] + '[/COLOR]'}) super_header_item = super_header_item + 1 xbmcplugin.endOfDirectory(int(sys.argv[1]))