def itertags_wrapper(html, tag, attrs=None, ret=False): try: result = list(itertags(html, tag)) if isinstance(attrs, dict): attrs = list(iteritems(attrs)) result = [ i for i in result if any([ a for a in attrs if any([ a[0] == k and re.match(a[1], v) for k, v in iteritems(i.attributes) ]) ]) ] if ret: # noinspection PyTypeChecker result = [i.attributes[ret] for i in result if ret in i.attributes] except Exception: result = [] return result
def teams_index(self): index_items = self.index() if index_items is None: return if control.setting('sport') == '0': integer = 30020 self.list = index_items['teams_football'] else: self.list = index_items['teams_basket'] integer = 30021 for i in self.list: i.update({'action': 'videos'}) bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({'cm': [{'title': 30501, 'query': {'action': 'addBookmark', 'url': json.dumps(bookmark)}}]}) selector = { 'title': control.lang(30019).format(control.lang(integer)), 'action': 'switch', 'isFolder': 'False', 'isPlayable': 'False' } self.list.insert(0, selector) directory.add(self.list)
def add(url, table=control.bookmarksFile): try: data = json.loads(url) dbid = hashlib.md5() for i in data['bookmark']: dbid.update(str(i)) for i in data['action']: dbid.update(str(i)) dbid = str(dbid.hexdigest()) item = dict((k,v) for k, v in iteritems(data) if not k == 'bookmark') item = repr(item) control.makeFile(control.dataPath) dbcon = database.connect(table) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS bookmark (""dbid TEXT, ""item TEXT, ""UNIQUE(dbid)"");") dbcur.execute("DELETE FROM bookmark WHERE dbid = '{}'".format(dbid)) dbcur.execute("INSERT INTO bookmark Values (?, ?)", (dbid, item)) dbcon.commit() except Exception: pass
def bookmarks(): self_list = bm.get() if not self_list: na = [{'title': control.lang(30007), 'action': None}] directory.add(na) return for i in self_list: bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['delbookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30502, 'query': { 'action': 'deleteBookmark', 'url': json.dumps(bookmark) } }] }) self_list.sort(key=lambda k: k['title'].lower()) directory.add(self_list, infotype='music')
def podcasts(self, url=None): if url is None: url = self.podcasts_link self.list = cache.get(self.pod_listing, 24, url) if self.list is None: return for i in self.list: i.update({'action': 'episodes'}) bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({ 'cm': [{ 'title': 32501, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) directory.add(self.list, content='music')
def shows(self, url): self.list = cache.get(self.generic_listing, 24, url) if self.list is None: return for i in self.list: i.update({'action': 'episodes'}) bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({ 'cm': [{ 'title': 32501, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) directory.add(self.list, content='videos')
def bookmarks(self): self.list = bookmarks.get() if not self.list: na = [{'title': control.lang(30058), 'action': None}] directory.add(na) return for i in self.list: bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['delbookmark'] = i['url'] i.update({'cm': [{'title': 30502, 'query': {'action': 'deleteBookmark', 'url': json.dumps(bookmark)}}]}) control.sortmethods('title') if control.setting('bookmarks_clear_boolean') == 'true': clear_menu = { 'title': control.lang(30059), 'action': 'clear_bookmarks' } self.list.insert(0, clear_menu) directory.add(self.list, content='videos')
def radios(url): self_list = radios_list(url) if self_list is None: return if url == ALL_LINK: self_list.extend(_devpicks()) for i in self_list: i.update({'action': 'play', 'isFolder': 'False'}) bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30501, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) control.sortmethods('title') directory.add(self_list, infotype='music')
def bookmarks(self): self.list = bookmarks.get() if not self.list: na = [{'title': control.lang(30018), 'action': None}] directory.add(na) return for i in self.list: bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['delbookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30502, 'query': { 'action': 'deleteBookmark', 'url': json.dumps(bookmark) } }] }) self.list = sorted(self.list, key=lambda k: k['title'].lower()) directory.add(self.list, content='videos')
def archive(self): self.list = cache.get( youtube.youtube(key=self.yt_key).playlists, 12, self.yt_channel) if self.list is None: return for i in self.list: i['title'] = client.replaceHTMLCodes(i['title']) i.update({'action': 'episodes'}) bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({ 'cm': [{ 'title': 32501, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) control.sortmethods('title') directory.add(self.list, content='videos')
def events(self, url): self.list = cache.get(self.event_list, 12, url) if self.list is None: log_debug( 'Events section failed to load, try resetting indexer methods') return for item in self.list: bookmark = dict( (k, v) for k, v in iteritems(item) if not k == 'next') bookmark['bookmark'] = item['url'] bookmark_cm = { 'title': 30080, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } } item.update({ 'cm': [bookmark_cm], 'action': 'play', 'isFolder': 'False' }) directory.add(self.list)
def bookmarks(self): self.list = bookmarks.get() if not self.list: na = [{'title': 30016, 'action': None, 'icon': 'open-box.png'}] directory.add(na) return for item in self.list: bookmark = dict( (k, v) for k, v in iteritems(item) if not k == 'next') bookmark['delbookmark'] = item['url'] item.update({ 'cm': [{ 'title': 30014, 'query': { 'action': 'deleteBookmark', 'url': json.dumps(bookmark) } }] }) self.list = sorted(self.list, key=lambda k: k['title'].lower()) directory.add(self.list)
def persons_index(self, url, post, get_list=True): if CACHE_DEBUG: self.list = self.persons_listing(url, post) else: self.list = cache.get(self.persons_listing, 48, url, post) if self.list is None: return for item in self.list: item.update({'action': 'listing', 'icon': iconname('user')}) bookmark = dict( (k, v) for k, v in iteritems(item) if not k == 'next') bookmark['bookmark'] = item['url'] bookmark_cm = { 'title': 30080, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } } refresh_cm = {'title': 30054, 'query': {'action': 'refresh'}} item.update({'cm': [bookmark_cm, refresh_cm]}) if get_list: return self.list else: directory.add(self.list)
def live(): self_list = list_live_items() if self_list is None: return self_list = [dict(t) for t in {tuple(d.items()) for d in self_list}] for item in self_list: item.update({'action': 'play', 'isFolder': 'False'}) bookmark = dict((k, v) for k, v in iteritems(item) if not k == 'next') bookmark['delbookmark'] = item['url'] item.update({ 'cm': [{ 'title': 30004, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) control.sortmethods() control.sortmethods('title') directory.add(self_list, content='videos')
def bookmarks(): self_list = _bookmarks.get() if not self_list: na = [{'title': control.lang(30007), 'action': None}] directory.add(na) return for i in self_list: bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['delbookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30006, 'query': { 'action': 'deleteBookmark', 'url': json.dumps(bookmark) } }] }) control.sortmethods() control.sortmethods('title') directory.add(self_list, content='videos')
def index(self, url): if self.basecy_link in url: self.list = self.index_cy(url) elif self.basegr_link in url: self.list = self.index_gr(url) if not self.list: return for i in self.list: if 'action' not in i: i.update({'action': 'episodes'}) if 'next' in i: i.update({'nextaction': 'index'}) for i in self.list: bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({'cm': [{'title': 30501, 'query': {'action': 'addBookmark', 'url': json.dumps(bookmark)}}]}) if self.basegr_link in url: control.sortmethods('title') control.sortmethods() directory.add(self.list, content='videos')
def search(): input_str = control.inputDialog() if not input_str: return items = radios_list(ALL_LINK) + _devpicks() if is_py3: titles = [strip_accents(i['title']) for i in items] matches = [ titles.index(t) for t, s in process.extract( strip_accents(input_str), titles, limit=10) if s >= 70 ] else: titles = [ strip_accents(i['title']).encode('unicode-escape') for i in items ] matches = [ titles.index(t) for t, s in process.extract(strip_accents( input_str).encode('unicode-escape'), titles, limit=10) if s >= 70 ] data = [] for m in matches: data.append(items[m]) if not data: control.infoDialog(30010) return else: for i in data: i.update({'action': 'play', 'isFolder': 'False'}) bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30501, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) control.sortmethods('title') directory.add(data, infotype='music')
def events(self, url): self.list = self.event_list(url) for item in self.list: bookmark = dict((k, v) for k, v in iteritems(item) if not k == 'next') bookmark['bookmark'] = item['url'] bookmark_cm = {'title': 30080, 'query': {'action': 'addBookmark', 'url': json.dumps(bookmark)}} item.update({'cm': [bookmark_cm], 'action': 'play', 'isFolder': 'False'}) directory.add(self.list)
def listing(self, url): if control.setting('debug') == 'false': self.list = cache.get(self._listing, 6, url) else: self.list = self._listing(url) if self.list is None: return for i in self.list: if 'paidikes-tainies' in i['url'] or 'archeio' in i['url']: i.update({'action': 'play', 'isFolder': 'False'}) elif i.get('playable') == 'false': i.update({'action': 'listing'}) else: i.update({'action': 'play', 'isFolder': 'False'}) try: del i['playable'] except KeyError: pass bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] bookmark_cm = {'title': 30501, 'query': {'action': 'addBookmark', 'url': json.dumps(bookmark)}} if 'enimerosi-24' in url or 'meta_url' not in i: i.update({'cm': [bookmark_cm]}) else: info_cm = {'title': 30043, 'query': {'action': 'info', 'url': i['meta_url']}} i.update({'cm': [bookmark_cm, info_cm]}) if control.setting('pagination') == 'true': for i in self.list: i.update({'nextaction': 'listing', 'nextlabel': 30500, 'nexticon': control.addonmedia('next.jpg')}) if 'tainies' in url or 'seires' in url or 'docs' in url or 'pedika' in url: control.sortmethods() control.sortmethods('title') control.sortmethods('production_code') if 'tainies' in url: content = 'movies' elif 'category' in url or 'arxeio' in url and not 'enimerosi-24' in url: content = 'tvshows' else: content = 'videos' directory.add(self.list, content=content)
def __init__(self): URLopener.__init__(self) headers = [('User-Agent', self.version), ('Accept', '*/*'), ('Referer', referer)] if kwargs: headers.extend(iteritems(kwargs)) self.addheaders = headers
def bookmarks(self): self.data = bookmarks.get() if not self.data: log_debug('Bookmarks list is empty') na = [{'title': 30033, 'action': None, 'icon': iconname('empty')}] directory.add(na) else: for i in self.data: if i['url'].startswith( (movies_link, theater_link, shortfilms_link)): if control.setting('action_type') == '1': try: del i['isFolder'] except: pass action = 'directory' elif control.setting( 'action_type') == '2' and control.setting( 'auto_play') == 'false': try: del i['isFolder'] except: pass action = i['action'] else: action = i['action'] else: action = i['action'] i['action'] = action item = dict((k, v) for k, v in iteritems(i) if not k == 'next') item['delbookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30081, 'query': { 'action': 'deleteBookmark', 'url': json.dumps(item) } }] }) self.list = sorted(self.data, key=lambda k: k['title'].lower()) directory.add(self.list, argv=self.argv)
def playlists(): self_list = yt_playlists() for p in self_list: p.update({'action': 'youtu'}) bookmark = dict((k, v) for k, v in iteritems(p) if not k == 'next') bookmark['bookmark'] = p['url'] bm_cm = {'title': 30006, 'query': {'action': 'addBookmark', 'url': json.dumps(bookmark)}} refresh = {'title': 30008, 'query': {'action': 'refresh'}} cache_clear = {'title': 30005, 'query': {'action': 'cache_clear'}} p.update({'cm': [refresh, cache_clear, bm_cm]}) directory.add(self_list)
def artist_index(self, url): self.list = cache.get(self.music_list, 48, url) if self.list is None: log_debug('Artist\'s section failed to load') return for item in self.list: bookmark = dict((k, v) for k, v in iteritems(item) if not k == 'next') bookmark['bookmark'] = item['url'] bookmark_cm = {'title': 30080, 'query': {'action': 'addBookmark', 'url': json.dumps(bookmark)}} item.update({'cm': [bookmark_cm], 'action': 'album_index'}) directory.add(self.list, argv=self.argv)
def videos(url): self_list = video_list(url) for i in self_list: i.update( { 'action': 'play', 'isFolder': 'False', 'nextaction': 'videos', 'nexticon': control.addonmedia('next.jpg'), 'nextlabel': 30015 } ) bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({'cm': [{'title': 30501, 'query': {'action': 'addBookmark', 'url': json.dumps(bookmark)}}]}) directory.add(self_list)
def listing(url): self_list = recursive_list_items(url) for i in self_list: bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30501, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) directory.add(self_list, content='videos')
def bm_list(): bm = bookmarks.get() na = [{'title': 30012, 'action': None, 'icon': 'not-found.jpg'}] if not bm: directory.add(na) return na for item in bm: bookmark = dict((k, v) for k, v in iteritems(item) if not k == 'next') bookmark['delbookmark'] = item['url'] item.update({'cm': [{'title': 30007, 'query': {'action': 'deleteBookmark', 'url': json.dumps(bookmark)}}]}) self_list = sorted(bm, key=lambda k: k['title'].lower()) directory.add(self_list)
def search(self): search_str = control.dialog.input(control.addonInfo('name')) search_str = cleantitle.strip_accents(search_str.decode('utf-8')) if not search_str: return self.list = self.video_list() try: self.list = [ item for item in self.list if search_str.lower() in cleantitle.strip_accents( item['title'].decode('utf-8')).lower() ] except Exception: self.list = [ item for item in self.list if search_str.lower() in cleantitle.strip_accents(item['title']).lower() ] if not self.list: return for item in self.list: item['title'] = cleantitle.replaceHTMLCodes(item['title']) bookmark = dict( (k, v) for k, v in iteritems(item) if not k == 'next') bookmark['bookmark'] = item['url'] bm_cm = { 'title': 30011, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } } cache_clear = {'title': 30015, 'query': {'action': 'cache_clear'}} item.update({'cm': [cache_clear, bm_cm]}) self.list = sorted(self.list, key=lambda k: k['title'].lower()) if control.setting('force_view') == 'true': control.set_view_mode('50') directory.add(self.list)
def __get_dom_elements(item, name, attrs): if not attrs: pattern = r'(<%s(?:\s[^>]*>|/?>))' % name this_list = re.findall(pattern, item, re.M | re.S | re.I) else: last_list = None for key, value in iteritems(attrs): value_is_regex = isinstance(value, re_type) value_is_str = isinstance(value, basestring) pattern = r'''(<{tag}[^>]*\s{key}=(?P<delim>['"])(.*?)(?P=delim)[^>]*>)'''.format( tag=name, key=key) re_list = re.findall(pattern, item, re.M | re.S | re.I) if value_is_regex: this_list = [r[0] for r in re_list if re.match(value, r[2])] else: temp_value = [value] if value_is_str else value this_list = [ r[0] for r in re_list if set(temp_value) <= set(r[2].split(' ')) ] if not this_list: has_space = (value_is_regex and ' ' in value.pattern) or (value_is_str and ' ' in value) if not has_space: pattern = r'''(<{tag}[^>]*\s{key}=((?:[^\s>]|/>)*)[^>]*>)'''.format( tag=name, key=key) re_list = re.findall(pattern, item, re.M | re.S | re.I) if value_is_regex: this_list = [ r[0] for r in re_list if re.match(value, r[1]) ] else: this_list = [r[0] for r in re_list if value == r[1]] if last_list is None: last_list = this_list else: last_list = [item for item in this_list if item in last_list] this_list = last_list return this_list
def index(self): if control.setting('debug') == 'false': self.list = cache.get(self.index_listing, 48) else: self.list = self.index_listing() if self.list is None: return for i in self.list: i.update({'action': 'listing'}) for i in self.list: bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({'cm': [{'title': 30006, 'query': {'action': 'addBookmark', 'url': json.dumps(bookmark)}}]}) directory.add(self.list, content='videos')
def dev_picks(): self_list = _devpicks() if self_list is None: return for i in self_list: bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30501, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) directory.add(self_list, infotype='music')