def district_list(self): try: try: result = client.request(self.district_link).decode('windows-1253') except AttributeError: result = client.request(self.district_link) radios = parseDOM(result, 'td') radios = [r for r in radios if r] except Exception: return for radio in radios: title = parseDOM(radio, 'a')[0] href = parseDOM(radio, 'a', ret='href')[0] html = client.request(href) link = parseDOM(html, 'iframe', ret='src')[0] embed = client.request(link) url = re.search(r'mp3: [\'"](.+?)[\'"]', embed).group(1).replace('https', 'http') image = parseDOM(html, 'img', ret='src')[0] self.list.append( {'title': title, 'image': image, 'url': url} ) return self.list
def _plot(url): load = client.request(url.partition('?')[0], post=url.partition('?')[2], timeout=20) description = parseDOM(load, 'div', {'class': 'video-description'})[-1] paragraphs = [client.stripTags(p) for p in parseDOM(description, 'p')] plot = client.replaceHTMLCodes('[CR]'.join(paragraphs)) return plot
def _radio_loop(station): title = parseDOM(station, 'a')[0] href = parseDOM(station, 'a', ret='href')[0] html = client.request(href, as_bytes=True) html = html.decode('windows-1253') link = parseDOM(html, 'iframe', ret='src')[0] embed = client.request(link) url = re.search(r'mp3: [\'"](.+?)[\'"]', embed).group(1).replace('https', 'http') image = parseDOM(html, 'img', ret='src')[0] data = {'title': title, 'image': image, 'url': url} return data
def district_list(): result = client.request(DISTRICT_LINK, as_bytes=True) result = result.decode('windows-1253') _radios = parseDOM(result, 'td') stations = [r for r in _radios if r] self_list = [] with concurrent_futures.ThreadPoolExecutor(5) as executor: threads = [ executor.submit(_radio_loop, station) for station in stations ] for future in concurrent_futures.as_completed(threads): item = future.result() if not item: continue self_list.append(item) return self_list
def recent_list(self): result = client.request(self.recent_link) items = parseDOM(result, 'item') for item in items: title = client.replaceHTMLCodes(parseDOM(item, 'title')[0]) url = parseDOM(item, 'link')[0] image = parseDOM(item, 'img', ret='src')[0] self.list.append({'title': title, 'url': url, 'image': image}) return self.list
def index_listing(): html = client.request(INDEX_LINK) li = parseDOM(html, 'li') li.extend(parseDOM(html, 'li', attrs={'class': 'hideli'})) items = [i for i in li if 'title' in i] self_list = [] for item in items: title = client.replaceHTMLCodes(parseDOM(item, 'a')[0]) url = parseDOM(item, 'a', ret='href')[0] self_list.append({'title': title, 'url': url}) self_list.sort(key=lambda k: k['title'].lower()) return self_list
def index_listing(self): html = client.request(self.index_link) div = parseDOM(html, 'div', attrs={'class': 'wpb_wrapper'})[0] li = parseDOM(div, 'li') li.extend(parseDOM(div, 'li', attrs={'class': 'hideli'})) items = [i for i in li if 'category' in i and 'title' in i] for item in items: title = client.replaceHTMLCodes(parseDOM(item, 'a')[0]) url = parseDOM(item, 'a', ret='href')[0] self.list.append({'title': title, 'url': url}) self.list = sorted(self.list, key=lambda k: k['title'].lower()) return self.list
def loop(self, item, header, count, next_url=None): data_id = item.attributes['data-id'] img = item.attributes['style'] image = re.search(r'url\((.+)\)', img).group(1) url = [i for i in itertags_wrapper(item.text, 'a', ret='href') if 'https' in i][0] meta_url = '?'.join([self.ajax_url, self.load_search.format(data_id=data_id)]) if 'inside-page-thumb-titles' in item.text and control.setting('metadata') == 'false': fanart = None plot = None title = parseDOM(item.text, 'div', attrs={'class': 'inside-page-thumb-titles'})[0] title = client.replaceHTMLCodes(parseDOM(title, 'a')[0]) else: load = client.request(self.ajax_url, post=self.load_search.format(data_id=data_id), timeout=20) title = parseDOM(load, 'p', {'class': 'video-title'})[0].strip() title = client.replaceHTMLCodes(title) description = parseDOM(load, 'div', {'class': 'video-description'})[-1] paragraphs = [client.stripTags(p) for p in parseDOM(description, 'p')] plot = client.replaceHTMLCodes('[CR]'.join(paragraphs)) f = parseDOM(load, 'div', attrs={'class': 'cover'}, ret='style')[0] fanart = re.search(r'url\((.+)\)', f).group(1) data = {'title': title, 'image': image, 'url': url, 'code': count, 'meta_url': meta_url} if next_url: data.update({'next': next_url}) if header in [ u'ΞΕΝΕΣ ΣΕΙΡΕΣ ΠΛΗΡΕΙΣ', u'ΨΥΧΑΓΩΓΙΑ', u'ΣΥΝΕΝΤΕΥΞΕΙΣ', u'ΕΛΛΗΝΙΚΑ ΝΤΟΚΙΜΑΝΤΕΡ', u'ΞΕΝΑ ΝΤΟΚΙΜΑΝΤΕΡ', u'ΠΑΙΔΙΚΑ', u'Η ΕΡΤ ΘΥΜΑΤΑΙ', u'ΑΘΛΗΤΙΚΑ', u'ΞΕΝΕΣ ΣΕΙΡΕΣ CATCH-UP', u'WEB ΣΕΙΡΕΣ', u'ΝΕΕΣ ΕΛΛΗΝΙΚΕΣ ΣΕΙΡΕΣ' ] and not 'archeio' in url and header is not None: data.update({'playable': 'false'}) if fanart: data.update({'fanart': fanart}) if plot: data.update({'plot': plot}) self.list.append(data)
def resolve(self, url): _url = url if 'radiostreaming' in url: return url elif 'youtube' in url or len(url) == 11: if url.startswith('plugin://'): url = url[-11:] return self.yt_session(url) else: html = client.request(url) if 'iframe' in html: iframe = parseDOM(html, 'iframe', ret='src')[0] else: availability = parseDOM(html, 'strong')[-1] control.okDialog(control.name(), availability) return 'https://static.adman.gr/inpage/blank.mp4' if 'youtube' in iframe: return self.resolve(iframe) else: result = client.request(iframe) urls = re.findall(r'(?:var )?(?:HLSLink|stream)(?:ww)?\s+=\s+[\'"](.+?)[\'"]', result) if urls: if control.setting('debug') == 'false': geo = cache.get(self._geo_detect, 192) else: geo = self._geo_detect() if len(urls) >= 2: if _url.endswith('-live/'): if not geo: return urls[-1] else: return urls[0] else: url = [i for i in urls if 'dvrorigingr' in i][0] try: video_ok = client.request(url, timeout=3) except Exception: video_ok = None if video_ok: return url else: url = [i for i in urls if 'dvrorigin' in i][0] return url else: if 'youtube' in urls[0]: return self.resolve(urls[0]) else: return urls[0] else: iframes = parseDOM(result, 'iframe', ret='src') try: return self.resolve(iframes[-1]) except YouTubeException: return self.resolve(iframes[0])
def _listing(self, url): if self.ajax_url in url: result = client.request(url.partition('?')[0], post=url.partition('?')[2]) else: result = client.request(url) try: header = parseDOM(result, 'h2')[0] except IndexError: header = None next_url = None override = False if self.base_link + '/?s=' in url or control.setting('pagination') == 'true': override = True threads_1 = [] threads_2 = [] # Nest the function to work on either of the two cases def _exec(_items, _next_url=None): if control.setting('threading') == 'true': for count, _item in list(enumerate(_items, start=1)): threads_2.append(workers.Thread(self.loop(_item, header, count, _next_url))) [i.start() for i in threads_2] [i.join() for i in threads_2] else: for count, _item in list(enumerate(_items, start=1)): self.loop(_item, header, count, _next_url) if 'enimerosi-24' not in url and self.ajax_url not in url: ajaxes = [i for i in parseDOM(result, 'script', attrs={'type': 'text/javascript'}) if 'ajaxurl' in i] ajax1 = json.loads(re.search(r'var loadmore_params = ({.+})', ajaxes[-1]).group(1)) ajax2 = json.loads(re.search(r'var cactus = ({.+})', ajaxes[0]).group(1)) ajax = self._ajax_merge(ajax1, ajax2) pages = int(ajax['max_page']) posts = ajax['posts'] try: posts = posts.encode('utf-8') except Exception: pass if control.setting('threading') == 'true' and not override: for i in range(0, pages + 1): threads_1.append( workers.Thread( self.thread(self.ajax_url, post=self.load_more.format(query=quote(posts), page=str(i))) ) ) [i.start() for i in threads_1] [i.join() for i in threads_1] else: for i in range(0, pages + 1): a = client.request(self.ajax_url, post=self.load_more.format(query=quote(posts), page=str(i))) self.data.append(a) if i == 0 and override: next_url = '?'.join([self.ajax_url, self.load_more.format(query=quote(posts), page='1')]) break html = '\n'.join(self.data) items = itertags_wrapper(html, 'div', attrs={'class': 'item item-\d+'}) if len(items) < 20: next_url = None _exec(items, next_url) elif self.ajax_url in url: items = itertags_wrapper(result, 'div', attrs={'class': 'item item-\d+'}) parsed = dict(parse_qsl(url.partition('?')[2])) next_page = int(parsed['page']) + 1 parsed['page'] = next_page if len(items) >= 20: next_url = '?'.join([url.partition('?')[0], urlencode(parsed)]) _exec(items, next_url) else: items = itertags_wrapper(result, 'div', attrs={'class': 'item item-\d+'}) for item in items: text = item.text img = item.attributes['style'] image = re.search(r'url\((.+)\)', img).group(1) title = client.replaceHTMLCodes(parseDOM(text, 'a')[0].strip()) url = parseDOM(text, 'a', ret='href')[0] self.list.append({'title': title, 'image': image, 'url': url}) return self.list