def getTVDB(imdb): try: if not imdb.endswith('?'): imdb = imdb + '?' url = 'http://api.themoviedb.org/3/find/%sapi_key=57983e31fb435df4df77afb854740ea9&external_source=imdb_id' % imdb html = quicknet.getURL(url, maxSec=5*86400, agent='Firefox') jsn = json.loads(html) thumbnail = BLANK fanart = FANART movies = jsn['movie_results'] tvs = jsn['tv_results'] source = None if len(movies) > 0: source = movies[0] elif len(tvs) > 0: source = tvs[0] if source: try: thumbnail = 'http://image.tmdb.org/t/p/w342' + source['poster_path'] except: pass try: fanart = 'http://image.tmdb.org/t/p/w780' + source['backdrop_path'] except: pass return thumbnail, fanart except: pass return BLANK, FANART
def Search(): kb = xbmc.Keyboard('', 'Search BBC Podcasts', False) kb.doModal() if not kb.isConfirmed(): return search = kb.getText() if search == '': return url = 'http://www.bbc.co.uk/podcasts/search.json?q=' + search try: import json as simplejson search = quicknet.getURL(url, 3600) # 1 hr jsn = simplejson.loads(search) for item in jsn: try: title = item['title'] url = item['link'] + '.rss' description = item['description'].replace('<span class="pc-quickfind-match">', '').replace('</span>', '') thumb = fixImage(item['image'], '256x256') fanart = fixImage(item['image'], '1280x720') addSearchResult(title, url, thumb, fanart, description) except: pass except: pass
def recommendKey(keyword): from metahandler import metahandlers grabber = metahandlers.MetaData() url = 'http://m.imdb.com/find?q=%s' % keyword.replace(' ', '+') #use mobile site as less data html = quicknet.getURL(url, maxSec=86400, agent='Apple-iPhone/') items = re.compile('<div class="title">.+?<a href="/title/(.+?)/">(.+?)</a>(.+?)</div>').findall(html) infolabels = {} for item in items: imdb = item[0] name = item[1] if 'video game' in item[2].lower(): continue label = name + ' ' + item[2].strip() thumbnail = BLANK fanart = FANART if METARECOMMEND: #thumbnail, fanart = getTVDB(imdb) infolabels = getMeta(grabber, name, 'movie', year=None, imdb=imdb) thumbnail = infolabels['cover_url'] fanart = infolabels['fanart'] addDir(label, _SUPERSEARCH, thumbnail=thumbnail, isFolder=True, menu=getMovieMenu(infolabels), fanart=fanart, keyword=name, imdb=imdb, infolabels=infolabels, totalItems=len(items))
def recommendIMDB(imdb, keyword): from metahandler import metahandlers grabber = metahandlers.MetaData() url = 'http://imdb.com/title/%s' % imdb html = quicknet.getURL(url, maxSec=86400, agent='Firefox') items = re.compile('<div class="rec-title">.+?<a href="/title/(.+?)/?ref_=tt_rec_tt" ><b>(.+?)</b>').findall(html) if len(items) == 0: return recommendKey(keyword) infolabels = {} for item in items: imdb = item[0] name = item[1] thumbnail = BLANK fanart = FANART if METARECOMMEND: #thumbnail, fanart = getTVDB(imdb) infolabels = getMeta(grabber, '', 'movie', year=None, imdb=imdb) thumbnail = infolabels['cover_url'] fanart = infolabels['fanart'] addDir(name, _SUPERSEARCH, thumbnail=thumbnail, isFolder=True, menu=getMovieMenu(infolabels), fanart=fanart, keyword=name, imdb=imdb, infolabels=infolabels, totalItems=len(items))
def GetPodcastURL(url): try: id = url.rsplit('/', 1)[-1] html = quicknet.getURL(url, 86400) #url = re.compile('(.+?).mp3" download=".+?%s.mp3">' % id).search(html).group(1) + '.mp3' #return 'http:' + url.rsplit('http:')[-1] html = html.split('http:') streams = [] for item in html: if '%s.mp3' % id in item: try: search = re.compile( '(.+?).mp3" download=".+?%s.mp3">(.+?)<' % id).search(item) url = 'http:%s.mp3' % search.group(1) desc = search.group(2).strip() bitrate = retrieveNumber(desc) streams.append([bitrate, url, desc]) except: pass if len(streams) == 0: return None if len(streams) == 1: return streams[0][1] streams.sort() try: STREAM = int(ADDON.getSetting('STREAM')) except: STREAM = -1 if STREAM == 0: return streams[-1][1] if STREAM == 1: return streams[0][1] options = [] [options.append(stream[2]) for stream in streams] choice = xbmcgui.Dialog().select(GETTEXT(30010), options) if choice < 0: return None return streams[choice][1] return url except: pass return None
def Search(): kb = xbmc.Keyboard('', 'Search BBC Podcasts', False) kb.doModal() if not kb.isConfirmed(): return search = kb.getText() if search == '': return url = 'http://www.bbc.co.uk/podcasts/search.json?q=' + search try: import json as simplejson search = quicknet.getURL(url, 3600) # 1 hr jsn = simplejson.loads(search) for item in jsn: try: title = item['title'] url = item['link'] + '.rss' description = item['description'].replace( '<span class="pc-quickfind-match">', '').replace('</span>', '') thumb = fixImage(item['image'], '256x256') fanart = fixImage(item['image'], '1280x720') addSearchResult(title, url, thumb, fanart, description) except: pass except: pass
def GetHTML(url, useCache = True, referer=None, agent=None): if useCache: html = quicknet.getURL(url, 1800, referer=referer, agent=agent) else: html = quicknet.getURLNoCache(url, referer=referer, agent=agent) html = html.replace('\n', '') return html
def GetPodcastURL(url): try: id = url.rsplit('/', 1)[-1] html = quicknet.getURL(url, 86400) #url = re.compile('(.+?).mp3" download=".+?%s.mp3">' % id).search(html).group(1) + '.mp3' #return 'http:' + url.rsplit('http:')[-1] html = html.split('http:') streams = [] for item in html: if '%s.mp3' % id in item: try: search = re.compile('(.+?).mp3" download=".+?%s.mp3">(.+?)<' % id).search(item) url = 'http:%s.mp3' % search.group(1) desc = search.group(2).strip() bitrate = retrieveNumber(desc) streams.append([bitrate, url, desc]) except: pass if len(streams) == 0: return None if len(streams) == 1: return streams[0][1] streams.sort() try: STREAM = int(ADDON.getSetting('STREAM')) except: STREAM = -1 if STREAM == 0: return streams[-1][1] if STREAM == 1: return streams[0][1] options = [] [options.append(stream[2]) for stream in streams] choice = xbmcgui.Dialog().select(GETTEXT(30010), options) if choice < 0: return None return streams[choice][1] return url except: pass return None
def getHTML(url, useCache=True): import quicknet agent = getUserAgent() if useCache: html = quicknet.getURL(url, 86400, agent=agent) else: html = quicknet.getURLNoCache(url, agent=agent) return html
def GetOPML(): opml = ElementTree.fromstring(quicknet.getURL(URL, 3600)) # 1 hr try: head = opml.find('head') date = head.findtext('dateModified').split(' ') except: pass return opml
def GetCountries(): html = quicknet.getURL(URL, maxSec=60*15) items = re.compile(REGEX).findall(html) names = [] countries = [] for item in items: vpn = MyVPN(item) if vpn.isOkay and vpn.country not in names: names.append(vpn.country) countries.append([vpn.country, vpn.abrv, vpn.icon]) countries.sort() return countries
def GetCountries(): html = quicknet.getURL(URL, maxSec=60 * 15) items = re.compile(REGEX).findall(html) names = [] countries = [] for item in items: vpn = MyVPN(item) if vpn.isOkay and vpn.country not in names: names.append(vpn.country) countries.append([vpn.country, vpn.abrv, vpn.icon]) countries.sort() return countries
def GetCities(abrv): abrv = abrv.upper() html = quicknet.getURL(URL, maxSec=60*15) items = re.compile(REGEX).findall(html) cities = [] for item in items: vpn = MyVPN(item) if vpn.abrv == abrv: if vpn.isOkay: cities.append([vpn.city, vpn.icon, vpn.capacity, vpn.ip]) cities.sort() return cities
def GetCities(abrv): html = quicknet.getURL(URL, maxSec=60 * 15) items = re.compile(REGEX).findall(html) cities = [] for item in items: vpn = MyVPN(item) if vpn.abrv == abrv: vpn = MyVPN(item) if vpn.isOkay: cities.append([vpn.city, vpn.icon, vpn.capacity, vpn.ip]) cities.sort() return cities
def IsPlayingRAM(): try: if not xbmc.Player().isPlayingAudio(): return False pl = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)[0] resp = quicknet.getURL(URL, 1800) if pl.getfilename()[:-1] in resp: return True except: pass return False
def LoadShow(url, genre, keyname): xml = quicknet.getURL(url, 3600) # 1 hr xml = ElementTree.fromstring(xml) channel = xml.find('channel') title = channel.findtext('title') imageT = channel.find('image') image = imageT.findtext('url') for item in channel.findall('item'): name = item.findtext('title') desc = item.findtext('description') url = item.findtext('link') content = item.find(".//{http://search.yahoo.com/mrss/}content") duration = find(lambda item: item[0] == 'duration', content.items()) addPodcast(name, url, genre, keyname, title, duration, image, desc)
def IsPlayingRAM(): try: if not xbmc.Player().isPlayingAudio(): return False resp = quicknet.getURL(URL, 1800) pl = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)[0] filename = pl.getfilename() if filename[:-1] in resp: return True if filename == URL_320: return True except: pass return False
def recommendKey(keyword): from metahandler import metahandlers grabber = metahandlers.MetaData() url = 'http://m.imdb.com/find?q=%s' % keyword.replace( ' ', '+') #use mobile site as less data html = quicknet.getURL(url, maxSec=86400, agent='Apple-iPhone/') items = re.compile( '<div class="title">.+?<a href="/title/(.+?)/">(.+?)</a>(.+?)</div>' ).findall(html) infolabels = {} for item in items: imdb = item[0] name = item[1] if 'video game' in item[2].lower(): continue label = name + ' ' + item[2].strip() thumbnail = BLANK fanart = FANART if METARECOMMEND: #thumbnail, fanart = getTVDB(imdb) infolabels = getMeta(grabber, name, 'movie', year=None, imdb=imdb) thumbnail = infolabels['cover_url'] fanart = infolabels['fanart'] addDir(label, _SUPERSEARCH, thumbnail=thumbnail, isFolder=True, menu=getMovieMenu(infolabels), fanart=fanart, keyword=name, imdb=imdb, infolabels=infolabels, totalItems=len(items))
def getTVDB(imdb): try: if not imdb.endswith('?'): imdb = imdb + '?' url = 'http://api.themoviedb.org/3/find/%sapi_key=57983e31fb435df4df77afb854740ea9&external_source=imdb_id' % imdb html = quicknet.getURL(url, maxSec=5 * 86400, agent='Firefox') jsn = json.loads(html) thumbnail = BLANK fanart = FANART movies = jsn['movie_results'] tvs = jsn['tv_results'] source = None if len(movies) > 0: source = movies[0] elif len(tvs) > 0: source = tvs[0] if source: try: thumbnail = 'http://image.tmdb.org/t/p/w342' + source[ 'poster_path'] except: pass try: fanart = 'http://image.tmdb.org/t/p/w780' + source[ 'backdrop_path'] except: pass return thumbnail, fanart except: pass return BLANK, FANART
def recommendIMDB(imdb, keyword): from metahandler import metahandlers grabber = metahandlers.MetaData() url = 'http://imdb.com/title/%s' % imdb html = quicknet.getURL(url, maxSec=86400, agent='Firefox') items = re.compile( '<div class="rec-title">.+?<a href="/title/(.+?)/?ref_=tt_rec_tt" ><b>(.+?)</b>' ).findall(html) if len(items) == 0: return recommendKey(keyword) infolabels = {} for item in items: imdb = item[0] name = item[1] thumbnail = BLANK fanart = FANART if METARECOMMEND: #thumbnail, fanart = getTVDB(imdb) infolabels = getMeta(grabber, '', 'movie', year=None, imdb=imdb) thumbnail = infolabels['cover_url'] fanart = infolabels['fanart'] addDir(name, _SUPERSEARCH, thumbnail=thumbnail, isFolder=True, menu=getMovieMenu(infolabels), fanart=fanart, keyword=name, imdb=imdb, infolabels=infolabels, totalItems=len(items))
def RequestLetter(letter): if not IsPlaying(GETTEXT(30030)): return if letter == '0-9': url = 'http://ramfm.org/momentum/cyan/playlist0.php' else: url = 'http://ramfm.org/momentum/cyan/playlist%s.php' % letter response = quicknet.getURL(url, 1800) hide = ADDON.getSetting('HIDE').lower() == 'true' images = {} tracks = [] items = response.split('<!-- start')[1:] for item in items: item = item.replace(' (& ', ' (& ') while ' ' in item: item = item.replace(' ', ' ') item = item.replace(' ', ' ') mode = MODE_FREE if '<i>song recently played</i>' in item: mode = MODE_IGNORE if hide else MODE_SONG if '<i>artist recently played</i>' in item: mode = MODE_IGNORE if hide else MODE_ARTIST title = None if mode == MODE_FREE: match = re.compile('.+?<a href="javascript:request\((.+?)\)" title="(.+?)">.+?<h2>(.+?)</h2>.+?-->').findall(item)[0] info = match[0] title = match[1] artist = match[2].split('-', 1)[0].strip() image = '' available = True if mode == MODE_ARTIST or mode == MODE_SONG: match = re.compile('.+?title="(.+?)">.+?<p>(.+?)</p></header></a></section><!-- end song recently played / artists recently played -->').findall(item)[0] info = match[0] title = match[1].rsplit('(', 1)[0].strip() artist = match[1].split('-', 1)[0].strip() image = '' available = False if not title: continue if image != 'na.gif': images[artist] = image tracks.append([artist, title, image, info, available]) titles = [''] tracks.sort() for track in tracks: artist = track[0] title = track[1] image = track[2] info = track[3] available = track[4] if title in titles: continue titles.append(title) if image == 'na.gif': try: image = images[artist] except: pass if available: addAvailable(title, artist, image, info) else: addUnavailable(title, artist, image, info)
def GetHTML(url): return quicknet.getURL(url, maxSec=7*86400)
def GetHTML(url): return quicknet.getURL(url, maxSec=7 * 86400)