def headers_get(self): print self.base_url html = koding.Open_URL(url=self.base_url,timeout=20,cookiejar=self.cookieJar) match = re.compile('<div class="header-menu-item">.+?<a href="(.+?)">(.+?)</a>',re.DOTALL).findall(html) for header_url,header_name in match: header_url = header_url.lstrip('/') header_url = self.base_url+header_url html2 = koding.Open_URL(url=header_url,timeout=20,cookiejar=self.cookieJar) if not '<center>There are no events</center>' in html2: self.Dir.append({'header_name':header_name,'header_url':header_url}) print self.Dir
def channel_info(self, channel_url): if channel_url.endswith('/'): about_url = channel_url + 'about' if not channel_url.endswith('/'): about_url = channel_url + '/about' html = koding.Open_URL(about_url, cookiejar=self.CookieJar, timeout=20) match = re.compile('<title>(.+?)</title>.+?', re.DOTALL).findall(html) match2 = re.compile('<link itemprop="thumbnailUrl" href="(.+?)">', re.DOTALL).findall(html) match3 = re.compile('background-image: url\((.+?)\)', re.DOTALL).findall(html) match4 = re.compile( '<div class="about-description branded-page-box-padding" >.+?<pre>(.+?)</pre>.+?</div>', re.DOTALL).findall(html) for title in match: title = ' '.join(title.split()) for icon in match2: icon = icon for artwork in match3: artwork = artwork.split('=')[0] artwork = 'https:' + artwork if len(match4) >= 1: for description in match4: description = ' '.join(description.split()) if not len(match4) >= 1: description = '' self.CHANNEL_INFO.append({ 'title': title, 'description': description, 'icon': icon, 'artwork': artwork, 'channel_url': channel_url })
def video_single(self, url): html = koding.Open_URL(url, cookiejar=self.CookieJar, timeout=20) match = re.compile( '<span id="eow-title" class="watch-title" dir="ltr" title="(.+?)"', re.DOTALL).findall(html) match2 = re.compile('<p id="eow-description" class="" >(.+?)</p>', re.DOTALL).findall(html) match3 = re.compile('<meta itemprop="datePublished" content="(.+?)">', re.DOTALL).findall(html) koding.dolog(match, my_debug=True) for title in match: title = title for description in match2: match4 = re.compile('(<.*?>)', re.DOTALL).findall(str(description)) for unwanted in match4: if len(match4) >= 1: description = (description).replace((unwanted), '') else: description = description for date in match3: date = date vid_id = url.split('v=')[1] playlink = 'plugin://plugin.video.youtube/play/?video_id=%s' % vid_id icon = 'https://i.ytimg.com/vi/%s/hqdefault.jpg' % vid_id self.CHANNEL_VIDEO.append({ 'title': title, 'playlink': playlink, 'icon': icon, 'date': date, 'description': description })
def channel_video(self, channel_url): if channel_url.endswith('/'): video_url = channel_url + 'videos' if not channel_url.endswith('/'): video_url = channel_url + '/videos' html = koding.Open_URL(video_url, cookiejar=self.CookieJar, timeout=20) match = re.compile( '<div class="yt-lockup-content">.+?title="(.+?)".+?href="(.+?)"', re.DOTALL).findall(html) for title, vid_id in match: page_url = 'https://www.youtube.com' + vid_id title = (title).replace('"', '"').replace("'", "'") try: title = HTMLParser().unescape(title) except: pass vid_id = (vid_id).replace('/watch?v=', '') icon = 'https://i.ytimg.com/vi/%s/hqdefault.jpg' % vid_id playlink = 'plugin://plugin.video.youtube/play/?video_id=%s' % vid_id html2 = koding.Open_URL(page_url, cookiejar=self.CookieJar, timeout=20) match2 = re.compile( '<strong class="watch-time-text">Published on (.+?)</strong>.+?<p id="eow-description" class="" >(.+?)</p></div>', re.DOTALL).findall(html2) for date, description in match2: description = (description).replace('<br />', ' ') match3 = re.compile('(<.*?>)', re.DOTALL).findall(str(description)) for unwanted in match3: if len(match3) >= 1: description = (description).replace((unwanted), '') else: description = description koding.dolog(title) self.CHANNEL_VIDEO.append({ 'title': title, 'playlink': playlink, 'icon': icon, 'date': date, 'description': description })
def channel_search(self, channel, search_item): if not channel.endswith('/'): channel = channel + '/' url = channel + 'search?query=%s' % (search_item.lower()) html = koding.Open_URL(url, cookiejar=self.CookieJar, timeout=20) match = re.compile( '<h3 class="yt-lockup-title ">.+? title="(.+?)".+?href="(.+?)".+?<div class="yt-lockup-description yt-ui-ellipsis yt-ui-ellipsis-2" dir="ltr">(.+?)</div>', re.DOTALL).findall(html) for title, url2, description in match: try: title = HTMLParser().unescape(title) except: pass title = (title).replace('&', '&') page_url = 'https://www.youtube.com%s' % url2 playlink = url2.replace('/watch?v=', '') artwork = 'https://i.ytimg.com/vi/%s/hqdefault.jpg' % playlink playlink = 'plugin://plugin.video.youtube/play/?video_id=%s' % playlink description = (description).replace("'", "'") match3 = re.compile('(<.*?>)', re.DOTALL).findall(str(description)) for unwanted in match3: if len(match3) >= 1: description = (description).replace((unwanted), '') else: description = description html2 = koding.Open_URL(page_url, cookiejar=self.CookieJar, timeout=20) match2 = re.compile('itemprop="datePublished" content="(.+?)"', re.DOTALL).findall(html2) for date in match2: date = dparser.parse(date, fuzzy=True) date = date.strftime('%Y-%m-%d') self.CHANNEL_SEARCH.append({ 'date': date, 'title': title, 'playlink': playlink, 'artwork': artwork, 'description': description })
def channel_playlist_video(self, playlist_url): html = koding.Open_URL(playlist_url, cookiejar=self.CookieJar, timeout=20) match = re.compile( '<tr class="pl-video yt-uix-tile(.+?)<span class="video-thumb yt-thumb yt-thumb-72"', re.DOTALL).findall(html) for block in match: match2 = re.compile('data-video-id="(.+?)"', re.DOTALL).findall(str(block)) match3 = re.compile('data-title="(.+?)"', re.DOTALL).findall(str(block)) for vid_id in match2: playlink = 'plugin://plugin.video.youtube/play/?video_id=%s' % vid_id icon = 'https://i.ytimg.com/vi/%s/hqdefault.jpg' % vid_id url = 'https://www.youtube.com/watch?v=%s' % vid_id html2 = koding.Open_URL(url, cookiejar=self.CookieJar, timeout=20) match4 = re.compile( '<strong class="watch-time-text">Published on (.+?)</strong>.+?<p id="eow-description" class="" >(.+?)</div>', re.DOTALL).findall(html2) for date, description in match4: description = (description).replace('<br />', ' ') match5 = re.compile('(<.*?>)', re.DOTALL).findall(str(description)) for unwanted in match5: if len(match3) >= 1: description = (description).replace((unwanted), '') else: description = description for title in match3: title = title self.CHANNEL_VIDEO.append({ 'title': title, 'playlink': playlink, 'icon': icon, 'date': date, 'description': description })
def getmatch_and_streams(self,header_url): html = koding.Open_URL(url=header_url,timeout=20,cookiejar=self.cookieJar) match = re.compile('<tbody>(.+?)</tbody>',re.DOTALL).findall(html) for block in match: match2 = re.compile('<tr>(.+?)</div>',re.DOTALL).findall(str(block)) for block2 in match2: match3 = re.compile("<span class='dt.+?>(.+?)</span><h4 id='eventname'><a href=.+?>(.+?)</a></h4>",re.DOTALL).findall(str(block2)) for event_time,event_name in match3: match4 = re.compile("<a href='(http.+?)'.+?>(.+?)</a",re.DOTALL).findall(str(block2)) for playlink,playname in match4: #print event_name,event_time,playname,playlink playlink = self.findStream(playlink) if playlink != None: if playlink not in self.PlayLink: self.PlayLink.append(playlink) self.Events.append({'event_time':event_time,'event_name':event_name,'playname':playname,'playlink':playlink}) #print event_time,event_name,playlink,playname print self.Events koding.dolog('Return from streamshunter scrape=%s %s'%(header_url,self.Events),line_info=True)
def xml_item_count(source, block, tag_to_count): ''' source == route to file can either be a url or special path block == master tag tag_to_count == tag you wish to count returns a int value of count ''' count = 0 if source.startswith('http'): source = koding.Open_URL(url=source,cookiejar=source) elif source.startswith('special'): source = koding.Physical_Path(source) source = koding.Text_File(source,'r') else: message = 'xml %s source not correct unable to count'%source koding.dolog(message,line_info=True) xbmc_executebuiltin.Notify(message=message) source_details = koding.Parse_XML(source, block, tag_to_count) for items in source_details: count += 1 return count
def channel_playlist(self, channel_url): if channel_url.endswith('/'): playlist_url = channel_url + 'playlists' if not channel_url.endswith('/'): playlist_url = channel_url + '/playlists' html = koding.Open_URL(playlist_url, cookiejar=self.CookieJar, timeout=20) match = re.compile('<div class="yt-lockup-content">(.+?)</div>', re.DOTALL).findall(html) for block in match: Match = re.compile( '<h3 class="yt-lockup-title ">.+?title="(.+?)".+?href="(.+?)"', re.DOTALL).findall(str(block)) for playlist_name, playlist_url in Match: playlist_url = 'https://www.youtube.com' + playlist_url self.CHANNEL_PLAYLIST.append({ 'playlist_name': playlist_name, 'playlist_url': playlist_url })
def search(self, search_item): url = self.baseURL + self.searchURL + search_item.replace(' ', '+') html = koding.Open_URL(url, cookiejar=self.CookieJar, timeout=20) match = re.compile( '<h3 class="yt-lockup-title ">(.+?)</span></li></ul></button>', re.DOTALL).findall(html) for block in match: match2 = re.compile('<a href="(.+?)".+?title="(.+?)".+?Play now', re.DOTALL).findall(str(block)) for vid_id, title in match2: try: title = HTMLParser().unescape(title) except: pass if vid_id.startswith('/watch?v='): vid_id = vid_id.split('v=')[1] playlink = self.playLINK + vid_id icon = self.artWORK % vid_id self.SEARCH_VIDEO.append({ 'playlink': playlink, 'title': title, 'icon': icon })
def process_item(self, item_xml): try: is_widget = __builtin__.JEN_WIDGET except: is_widget = False item = JenItem(item_xml) enable_gifs = xbmcaddon.Addon().getSetting('enable_gifs') == "true" if item.item_string.startswith("<item>"): title = item["title"] if title == "": title = item["name"] try: title = xbmcaddon.Addon().getLocalizedString(int(title)) except ValueError: pass is_playable = True mode = "get_sources" link = item_xml elif item.item_string.startswith("<dir>"): title = item["name"] if title == "": title = item["title"] try: title = xbmcaddon.Addon().getLocalizedString(int(title)) except ValueError: pass if item["link"].startswith("message"): is_playable = True mode = "message" link = item["link"].replace("message(", "")[:-1] if link.startswith("http"): text = koding.Open_URL(replace_url(link)) link = text else: is_playable = False mode = "get_list" link = item["link"] elif item.item_string.startswith("<plugin>"): link = item["link"] title = item["name"] if title == "": title = item["title"] try: title = xbmcaddon.Addon().getLocalizedString(int(title)) except ValueError: pass if link.endswith("openSettings"): is_playable = True link = "" mode = "Settings" elif link.endswith("developer"): is_playable = False link = '{"file_name":"testings.xml"}' mode = "Testings" path = xbmcaddon.Addon().getAddonInfo('profile') profile_path = xbmc.translatePath(path).decode('utf-8') test_file = os.path.join(profile_path, "testings.xml") if not os.path.exists(test_file): return else: if "youtube" in link and ("user" in link or "playlist" in link): is_playable = True mode = 'get_sources' link = item_xml else: is_playable = True mode = 'get_sources' link = item_xml else: xbmc.log("other: " + repr(item), xbmc.LOGDEBUG) raise Exception() # filter out "unreleased" if title == "" or " /title" in title or "/ title" in title: return if is_widget: if mode == "message": return context = get_context_items(item) content = item["content"] if content == "boxset": content = "set" if content != '': self.content = content imdb = item["imdb"] season = item["season"] or '0' episode = item["episode"] or '0' year = item["year"] or '0' fanart = None if enable_gifs: fan_url = item.get("animated_fanart", "") if fan_url and fan_url != "0": fanart = replace_url(fan_url) if not fanart: fanart = replace_url(item.get("fanart", self.list_fanart), replace_gif=False) thumbnail = None if enable_gifs: thumb_url = item.get("animated_thumbnail", "") if thumb_url and thumb_url != "0": thumbnail = replace_url(thumb_url) if not thumbnail: thumbnail = replace_url(item.get("thumbnail", self.list_image), replace_gif=False) premiered = item.get("premiered", "") if premiered: try: today_tt = datetime.date.today().timetuple() premiered_tt = time.strptime(premiered, "%Y-%m-%d") if today_tt < premiered_tt: title = "[COLORyellow]" + title + "[/COLOR]" except: xbmc.log("wrong premiered format") pass result_item = { 'label': title, 'icon': thumbnail, 'fanart': fanart, 'mode': mode, 'url': link, 'folder': not is_playable, 'imdb': imdb, 'content': content, 'season': season, 'episode': episode, 'info': {}, 'year': year, 'context': context } if fanart: result_item["properties"] = {'fanart_image': fanart} result_item['fanart_small'] = fanart if content in ['movie', 'episode']: # only add watched data for applicable items result_item['info']['watched'] = 0 return result_item
# -*- coding: utf-8 -*-
def Main_Menu_Check(): # Standard social sharing style menus if mode == 'std': folders = Folder_Check() if sys.argv[1] == "live_tv" and folders == 0 and not tvgskip: choice = dialog.select( sys.argv[1].replace('_', ' ').upper() + ' Menu', [ '[COLOR=gold]Add[/COLOR] to Live TV', '[COLOR=gold]Add / Remove[/COLOR] Sub-menus' ]) if choice == 0: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=live_tv",return)' ) if choice == 1: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=live_tv_submenu",return)' ) elif sys.argv[1] == "live_tv" and folders > 0 and not tvgskip: choice = dialog.select( sys.argv[1].replace('_', ' ').upper() + ' Menu', [ '[COLOR=gold]Add[/COLOR] to Live TV', '[COLOR=gold]Remove[/COLOR] from Live TV', '[COLOR=gold]Add / Remove[/COLOR] Sub-menus', '[COLOR=gold]Share[/COLOR] Live TV Item' ]) if choice == 0: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=live_tv",return)' ) if choice == 1: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=from_the_live_tv_menu",return)' ) if choice == 2: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=live_tv_submenu",return)' ) if choice == 3: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.super.favourites/?folder=HOME_LIVE_TV",return)' ) # EDIT Menu elif sys.argv[1] == "mainmenu": choice = dialog.select(String(30280), [ String(30281), String(30282), String(30292), String(30300), String(30506) ]) if choice >= 0: if choice == 0: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=main_menu_install&url=add",return)' ) xbmc.executebuiltin('Container.Refresh') if choice == 1: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=main_menu_install&url=remove",return)' ) xbmc.executebuiltin('Container.Refresh') if choice == 2: Configure_Menus() if choice == 3: Configure_Menus('SUBMENU_') if choice == 4: Reset_Factory('ALL') # SOCIAL SHARES - If content exists add menu for adding, removing and sharing elif (sys.argv[1] != "mainmenu") and (folders > 0) and ( not sys.argv[1].endswith('_SF')): cleanname = sys.argv[1].replace('_', ' ') choice = dialog.select(String(30283), [ String(30284) % sys.argv[1].replace('_', ' '), String(30285) % sys.argv[1].replace('_', ' '), String(30286), String(30287) % cleanname ]) if choice == 0: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=' + sys.argv[1] + '",return)') if choice == 1: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=from_the_' + sys.argv[1] + '_menu",return)') if choice == 2: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=' + sys.argv[1] + '_submenu",return)') if choice == 3: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.super.favourites/?folder=HOME_' + sys.argv[1].replace(' ', '_').upper() + '",return)') # SOCIAL SHARES - If no content exists add menu for adding and sharing only elif (sys.argv[1] != "mainmenu") and (folders == 0) and ( not sys.argv[1].endswith('_SF')): cleanname = sys.argv[1].replace('_', ' ') choice = dialog.select( String(30283), [String(30284) % sys.argv[1].replace('_', ' '), String(30291)]) if choice == 0: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=' + sys.argv[1] + '",return)') if choice == 1: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.tbs/?description&mode=search_content_main&url=' + sys.argv[1] + '_submenu",return)') else: xbmc.executebuiltin( 'ActivateWindow(programs,"plugin://plugin.program.super.favourites/?folder=HOME_' + sys.argv[1].replace(' ', '_').upper() + '",return)') # If we're opening the EPG Tools menu elif mode == 'listings': custom_url = koding.Addon_Setting(setting='custom.url', addon_id='script.trtv') if 'http' in custom_url: countries = [ 'Afghanistan', 'Albania', 'Algeria', 'Angola', 'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Belarus', 'Belgium', 'Bolivia', 'Bosnia', 'Brazil', 'Bulgaria', 'Cambodia', 'Cameroon', 'Canada', 'Chile', 'China', 'Colombia', 'Costa Rica', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Estonia', 'Ethiopia', 'Finland', 'France', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Greece', 'Guatemala', 'Guinea', 'Haiti', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Ivory Coast', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kosovo', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Liberia', 'Libya', 'Liechstenstein', 'Lithuania', 'Luxembourg', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Mali', 'Malta', 'Mauritius', 'Mexico', 'Moldova', 'Mongolia', 'Montenegro', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nepal', 'Netherlands', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Norway', 'Oman', 'Pakistan', 'Palestine', 'Panama', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Romania', 'Russia', 'Rwanda', 'Saudi Arabia', 'Senegal', 'Serbia', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Somalia', 'South Africa', 'South Korea', 'South Sudan', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Togo', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Uganda', 'Ukraine', 'United Arab Emireates', 'United Kingdom', 'United States', 'Uruguay', 'Uzbekistan', 'Venezuela', 'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe' ] # content = koding.Open_URL('https://friendpaste.com/5Xu6ETfd0vjj8lvpvQ390b/raw') content = koding.Open_URL(custom_url) raw_list = koding.Find_In_Text(content, 'name="', '\n\n') final_list = [] my_list = [] Clear_Providers() xbmc.executebuiltin( 'RunScript(special://home/addons/script.trtv/deleteDB.py,wipeEPG)' ) for item in raw_list: name, url, country, offset = item.split('\n') name = name.replace('"', '').strip() url = url.replace('url="', '').replace('"', '').strip() country = country.replace('country="', '').replace('"', '').strip() offset = offset.replace('offset="', '').replace('"', '').strip() final_list.append('[COLOR=dodgerblue]%s:[/COLOR] %s' % (country, name)) my_list.append([name, url, country, offset]) # Select main provider dialog.ok(String(30264).upper(), String(30265)) choice = dialog.select(String(30264), final_list) counter = 1 if choice >= 0: koding.Addon_Setting(setting='offset%s' % counter, value=my_list[choice][3], addon_id='script.trtv') koding.Addon_Setting(setting='xmlpath%s.url' % counter, value=my_list[choice][1], addon_id='script.trtv') koding.Addon_Setting(setting='xmlpath%s.type' % counter, value='URL', addon_id='script.trtv') if my_list[choice][2] in countries: koding.Addon_Setting(setting='country%s' % counter, value=my_list[choice][2], addon_id='script.trtv') koding.Addon_Setting(setting='usecountry%s' % counter, value='true', addon_id='script.trtv') else: koding.Addon_Setting(setting='usecountry%s' % counter, value='false', addon_id='script.trtv') del final_list[choice] del my_list[choice] counter += 1 # If still items in list offer to add more providers my_choice = 1 while my_choice: if len(final_list) > 1: my_choice = dialog.yesno( String(30264).upper(), String(30266)) if not my_choice: break choice = dialog.select(String(30264), final_list) koding.Addon_Setting(setting='offset%s' % counter, value=my_list[choice][3], addon_id='script.trtv') koding.Addon_Setting(setting='xmlpath%s.url' % counter, value=my_list[choice][1], addon_id='script.trtv') koding.Addon_Setting(setting='xmlpath%s.type' % counter, value='URL', addon_id='script.trtv') if my_list[choice][2] in countries: koding.Addon_Setting(setting='country%s' % counter, value=my_list[choice][2], addon_id='script.trtv') koding.Addon_Setting(setting='usecountry%s' % counter, value='true', addon_id='script.trtv') else: koding.Addon_Setting(setting='usecountry%s' % counter, value='false', addon_id='script.trtv') del final_list[choice] del my_list[choice] counter += 1