def AddUtubeSearch(self): c = self.conn.cursor() searchquery = KeyBoard('Enter Search Query') queryresults = youtube_requests.get_search(searchquery, search_type='channel', order='relevance', safe_search='none', addon_id=addon_id) c.execute("SELECT channel_id FROM youtube_channels") channel_ids = [i[0] for i in c.fetchall()] self.sel_menu_control = self.getControl(self.SELECT_MENU) for res in queryresults: s = res.get('snippet') if s: cid = s.get('channelId') if cid not in channel_ids: liz = xbmcgui.ListItem(s.get('title')) liz.setProperties({ 'func': 'self.AddUtubeChannel', 'channel_id': cid }) liz.setArt({ 'thumb': s.get('thumbnails').get('default').get('url') }) self.sel_menu_control.addItem(liz) self.setControlLabel(self.SELECT_MENU_LABEL, 'Click on channel to Add') self.setControlVisible(self.SELECT_MENU_GROUP, True) self.setFocusId(self.SELECT_MENU)
def __init__(self, listitem, order, *args, **kwargs): super(WindowYoutubeList, self).__init__() self.channelbanner = listitem.getArt('banner') self.query = kwargs.get('searchQuery', '') self.content = youtube_requests.get_search( self.query, search_type='video', channel_id=listitem.getProperty('youtube_id'), order=order, safe_search='none', addon_id=addon_id)
def _mgreekz_top10(self): from youtube_requests import get_search html = client.request(self.mgreekz_url) spotify_playlist_url = client.parseDOM(html, 'iframe', ret='src')[0] spotify_html = client.request(spotify_playlist_url) spotify_object = client.parseDOM(spotify_html, 'script', attrs={'id': 'resource', 'type': 'application/json'})[0] json_object = json.loads(spotify_object) comment = plot = json_object.get('description') tracks = json_object.get('tracks').get('items') for track in tracks: song = track.get('track') title = song.get('name') artists = on_label = [i['name'] for i in song.get('artists')] if control.setting('audio_only') == 'true' and control.condVisibility('Window.IsVisible(music)'): artists = ' / '.join(artists) search = get_search(q=title + ' ' + 'official', search_type='video')[0] vid = search['id']['videoId'] link = yt_url + vid image = thumb_maker(link.rpartition('/' if 'youtu.be' in link else '=')[2]) self.list.append( { 'label': title + ' - ' + ' & '.join(on_label), 'url': link, 'album': 'Mad Greek Top 10', 'image': image, 'artist': artists, 'comment': comment, 'plot': plot, 'title': title } ) return self.list
def source_maker(url): if 'episode' in url: html = client.request(url=url.partition('?')[0], post=url.partition('?')[2]) else: html = client.request(url) try: html = html.decode('utf-8') except Exception: pass if 'episode' in url: episodes = re.findall(r'''(?:<a.+?/a>|<p.+?/p>)''', html) hl = [] links = [] for episode in episodes: if '<p style="margin-top:0px; margin-bottom:4px;">' in episode: host = client.parseDOM(episode, 'p')[0].split('<')[0] pts = client.parseDOM(episode, 'a') lks = client.parseDOM(episode, 'a', ret='href') for p in pts: hl.append(u''.join([host, control.lang(30225), p])) for l in lks: links.append(l) else: pts = client.parseDOM(episode, 'a') lks = client.parseDOM(episode, 'a', ret='href') for p in pts: hl.append(p) for l in lks: links.append(l) links = [urljoin(GM_BASE, link) for link in links] hosts = [ host.replace(u'προβολή στο ', control.lang(30015)) for host in hl ] data = {'links': links, 'hosts': hosts} if '<p class="text-muted text-justify">' in html: plot = client.parseDOM(html, 'p')[0] data.update({'plot': plot}) return data elif 'view' in url: link = client.parseDOM(html, 'a', ret='href', attrs={"class": "btn btn-primary"})[0] return { 'links': [link], 'hosts': [''.join([control.lang(30015), 'Youtube'])] } elif 'music' in url: keys_registration() title = re.search(r'''search\(['"](.+?)['"]\)''', html).group(1) link = get_search(q=title, search_type='video', addon_id=control.addonInfo('id'))[0]['id']['videoId'] link = YT_URL + link return { 'links': [link], 'hosts': [''.join([control.lang(30015), 'Youtube'])] } else: try: info = client.parseDOM(html, 'h4', attrs={'style': 'text-indent:10px;'}) if ',' in info[1]: genre = info[1].lstrip(u'Είδος:').split(',') genre = random.choice(genre) genre = genre.strip() else: genre = info[1].lstrip(u'Είδος:').strip() except: genre = control.lang(30147) div_tags = parsers.itertags(html, 'div') buttons = [ i.text for i in list(div_tags) if 'margin: 0px 0px 10px 10px;' in i.attributes.get('style', '') ] links = [] hl = [] for button in buttons: if 'btn btn-primary dropdown-toggle' in button: h = client.stripTags(client.parseDOM(button, 'button')[0]).strip() parts = client.parseDOM(button, 'li') for part in parts: p = client.parseDOM(part, 'a')[0] link = client.parseDOM(part, 'a', ret='href')[0] hl.append(', '.join([h, p])) links.append(link) else: h = client.parseDOM(button, 'a')[0] link = client.parseDOM(button, 'a', ret='href')[0] hl.append(h) links.append(link) links = [urljoin(GM_BASE, link) for link in links] hosts = [ host.replace(u'προβολή στο ', control.lang(30015)).replace( u'προβολή σε ', control.lang(30015)).replace(u'μέρος ', control.lang(30225)) for host in hl ] data = {'links': links, 'hosts': hosts, 'genre': genre} if 'text-align: justify' in html: plot = client.parseDOM(html, 'p', attrs={'style': 'text-align: justify'})[0] elif 'text-justify' in html: plot = client.parseDOM(html, 'p', attrs={'class': 'text-justify'})[0] else: plot = control.lang(30085) data.update({'plot': plot}) imdb_code = re.search(r'imdb.+?/title/([\w]+?)/', html) if imdb_code: code = imdb_code.group(1) data.update({'code': code}) return data
def _top20(self, url): from youtube_requests import get_search cookie = client.request(url, close=False, output='cookie') html = client.request(url, cookie=cookie) if url == self.rythmos_top20_url: attributes = {'class': 'va-title'} elif url == self.plus_url: attributes = {'class': 'element element-itemname first last'} elif url == self.radiopolis_url_gr or url == self.radiopolis_url_other: attributes = {'class': 'thetopdata'} items = client.parseDOM( html, 'td' if 'radiopolis' in url else 'div', attrs=attributes ) year = str(datetime.now().year) for item in items: if url == self.rythmos_top20_url: label = client.parseDOM(item, 'span', attrs={'class': 'toptitle'})[0] label = client.replaceHTMLCodes(label) label = re.sub('\s? ?-\s? ?', ' - ', label) image = client.parseDOM(item, 'img', ret='src')[0] image = image.replace(' ', '%20') title = label.partition(' - ')[2] if control.setting('audio_only') == 'true' and control.condVisibility('Window.IsVisible(music)'): artist = label.partition(' - ')[0] else: artist = [label.partition(' - ')[0]] elif url == self.plus_url: label = item.partition('.')[2].strip() title = label.partition('-')[2] if control.setting('audio_only') == 'true' and control.condVisibility('Window.IsVisible(music)'): artist = label.partition('-')[0] else: artist = [label.partition('-')[0]] elif url == self.radiopolis_url_gr or url == self.radiopolis_url_other: a_href = client.parseDOM(item, 'a') a_href = ' - '.join(a_href) if len(a_href) == 2 else a_href[0] label = client.stripTags(a_href.replace('\"', '').replace('&', '&').replace('\n', ' - ')) title = label.partition(' - ')[2] if control.setting('audio_only') == 'true' and control.condVisibility('Window.IsVisible(music)'): artist = label.partition(' - ')[0] else: artist = [label.partition(' - ')[0]] if any([url == self.rythmos_top20_url, url == self.plus_url]): search = get_search(q=title + ' ' + 'official', search_type='video')[0] description = search['snippet']['description'] year = search['snippet']['publishedAt'][:4] vid = search['id']['videoId'] image = search['snippet']['thumbnails']['default']['url'] link = yt_url + vid elif url == self.radiopolis_url_gr or url == self.radiopolis_url_other: links = client.parseDOM(item, 'a', ret='href') link = links[1] if len(links) == 2 else links[0] image = thumb_maker(link.rpartition('/' if 'youtu.be' in link else '=')[2]) description = None self.list.append( { 'label': label, 'url': link, 'image': image, 'title': title, 'artist': artist, 'plot': description, 'year': int(year) } ) return self.list