diff --git a/channels/animeunity.py b/channels/animeunity.py index 070621f8..e2da2421 100644 --- a/channels/animeunity.py +++ b/channels/animeunity.py @@ -46,7 +46,7 @@ def menu(item): if item.contentType == 'tvshow': itemlist += [item.clone(title=support.typo('In Corso','bold'), args=InCorso), item.clone(title=support.typo('Terminato','bold'), args=Terminato)] - itemlist +=[item.clone(title=support.typo('Cerca...','bold'), action='search', thumbnail=support.thumb(thumb='search.png'))] + itemlist +=[item.clone(title=support.typo('Cerca...','bold'), action='search', thumbnail=support.thumb('search'))] return itemlist @@ -152,11 +152,11 @@ def peliculas(item): payload = json.dumps(item.args) records = requests.post(host + '/archivio/get-animes', headers=headers, data=payload).json()['records'] - js = [] - for record in records: - js += record - - for it in js: + # js = [] + # support.log(records) + # for record in records: + # js += record + for it in records: lang = support.match(it['title'], patron=r'\(([It][Tt][Aa])\)').match title = support.re.sub(r'\s*\([^\)]+\)', '', it['title']) diff --git a/channels/animeworld.py b/channels/animeworld.py index 4ca639f7..4c7045df 100644 --- a/channels/animeworld.py +++ b/channels/animeworld.py @@ -88,11 +88,9 @@ def menu(item): action = 'submenu' data = get_data(item) patronMenu=r']+>\s*(?P[A-Za-z0-9]+)\s*<span.[^>]+>(?P<other>.*?)</ul>' - - def itemlistHook(itemlist): - item.title = support.typo('Tutti','bold') - item.action = 'peliculas' - itemlist.insert(0, item) + def ItemItemlistHook(item, itemlist): + itemlist.insert(0, item.clone(title=support.typo('Tutti','bold'), action='peliculas')) + itemlist.append(item.clone(title=support.typo('Cerca...','bold'), action='search', search=True, thumbnail=support.thumb('search.png'))) return itemlist return locals() @@ -126,8 +124,11 @@ def newest(categoria): def search(item, texto): support.log(texto) - item.args = 'noorder' - item.url = host + '/search?keyword=' + texto + if item.search: + item.url = host + '/filter?dub=' + item.args + '&keyword=' + texto + '&sort=' + else: + item.args = 'noorder' + item.url = host + '/search?keyword=' + texto item.contentType = 'tvshow' try: return peliculas(item) diff --git a/channels/metalvideo.py b/channels/metalvideo.py index 253ab0ae..8164dc36 100644 --- a/channels/metalvideo.py +++ b/channels/metalvideo.py @@ -24,7 +24,7 @@ def mainlist(item): patronBlock = r'<ul class="dropdown-menu(?P<block>.*?)</ul> </div' patron = r'<a href="(?P<url>[^"]+)"(?: class="")?>(?P<title>[^<]+)<' def itemHook(item): - item.thumbnail = support.thumb(thumb='music.png') + item.thumbnail = support.thumb('music') item.contentType = 'music' return item def itemlistHook(itemlist): @@ -36,7 +36,7 @@ def mainlist(item): contentType='music', url=item.url, action='search', - thumbnail=support.thumb(thumb='search.png'))) + thumbnail=support.thumb('search'))) support.channel_config(item, itemlist) return itemlist diff --git a/channels/serietvu.py b/channels/serietvu.py index 5a82e68e..c1fec70e 100644 --- a/channels/serietvu.py +++ b/channels/serietvu.py @@ -126,6 +126,6 @@ def findvideos(item): contentType='tvshow', url=url_serie, action='episodios', - thumbnail = support.thumb(thumb='tvshow.png'))) + thumbnail = support.thumb('tvshow'))) return itemlist diff --git a/channels/toonitalia.py b/channels/toonitalia.py index 5f0cbca8..d2b88667 100644 --- a/channels/toonitalia.py +++ b/channels/toonitalia.py @@ -103,11 +103,12 @@ def peliculas(item): @support.scrape def episodios(item): anime = True + # debug=True data = support.match(item, headers=headers).data if 'https://vcrypt.net' in data: - patron = r'(?: /> |<p>)(?P<title>[^<]+)<a (?P<url>.*?)(?:<br|</p)' + patron = r'(?: /> |<p>)(?P<episode>\d+.\d+)?(?: – )?(?P<title>[^<]+)<a (?P<url>.*?)(?:<br|</p)' else: - patron = r'<br />\s*<a href="(?P<url>[^"]+)" target="_blank" rel="noopener[^>]+>(?P<title>[^<]+)</a>' + patron = r'<br />\s*<a href="(?P<url>[^"]+)" target="_blank" rel="noopener[^>]+>(?P<episode>\d+.\d+)?(?: – )?(?P<title>[^<]+)</a>' def itemHook(item): item.title = support.re.sub(r'\[B\]|\[/B\]', '', item.title) diff --git a/channels/tunein.py b/channels/tunein.py index 10f161fe..c3a9bbbb 100644 --- a/channels/tunein.py +++ b/channels/tunein.py @@ -22,12 +22,12 @@ def mainlist(item): action = 'radio' patron = r'text="(?P<title>[^"]+)" URL="(?P<url>[^"]+)"' def itemHook(item): - item.thumbnail = support.thumb(thumb='music.png') + item.thumbnail = support.thumb('music') item.contentType = 'music' return item def itemlistHook(itemlist): itemlist.append( - item.clone(title=support.typo('Cerca...', 'bold color kod'), action='search', thumbnail=support.thumb(thumb='search.png'))) + item.clone(title=support.typo('Cerca...', 'bold color kod'), action='search', thumbnail=support.thumb('search'))) support.channel_config(item, itemlist) return itemlist return locals() diff --git a/channelselector.py b/channelselector.py index 4bcc9aae..886e8c4d 100644 --- a/channelselector.py +++ b/channelselector.py @@ -4,8 +4,7 @@ import glob, os from core import channeltools from core.item import Item -from platformcode.unify import thumb_dict -from platformcode import config, logger, unify +from platformcode import config, logger addon = config.__settings__ downloadenabled = addon.getSetting('downloadenabled') @@ -102,6 +101,7 @@ def getchanneltypes(view="thumb_"): def filterchannels(category, view="thumb_"): + from core import channeltools logger.info('Filter Channels ' + category) channelslist = [] @@ -275,110 +275,3 @@ def auto_filter(auto_lang=False): lang = 'all' return lang - - -def thumb(item_or_itemlist=None, genre=False, live=False, thumb=''): - if live: - if type(item_or_itemlist) == list: - for item in item_or_itemlist: - item.thumbnail = "https://raw.githubusercontent.com/kodiondemand/media/master/live/" + item.fulltitle.lower().replace(' ','_') + '.png' - else: - item_or_itemlist.thumbnail = "https://raw.githubusercontent.com/kodiondemand/media/master/live/" + item.fulltitle.lower().replace(' ','_') + '.png' - return item_or_itemlist - - import re - icon_dict = {'movie':['film', 'movie'], - 'tvshow':['serie','tv','episodi','episodio','fiction', 'show'], - 'documentary':['documentari','documentario', 'documentary', 'documentaristico'], - 'teenager':['ragazzi','teenager', 'teen'], - 'learning':['learning'], - 'all':['tutti', 'all'], - 'news':['novità', "novita'", 'aggiornamenti', 'nuovi', 'nuove', 'new', 'newest', 'news', 'ultimi'], - 'now_playing':['cinema', 'in sala'], - 'anime':['anime'], - 'genres':['genere', 'generi', 'categorie', 'categoria', 'category'], - 'animation': ['animazione', 'cartoni', 'cartoon', 'animation'], - 'action':['azione', 'arti marziali', 'action'], - 'adventure': ['avventura', 'adventure'], - 'biographical':['biografico', 'biographical'], - 'comedy':['comico', 'commedia', 'demenziale', 'comedy', 'brillante'], - 'adult':['erotico', 'hentai', 'harem', 'ecchi', 'adult'], - 'drama':['drammatico', 'drama', 'dramma'], - 'syfy':['fantascienza', 'science fiction', 'syfy', 'sci'], - 'fantasy':['fantasy', 'magia', 'magic', 'fantastico'], - 'crime':['gangster','poliziesco', 'crime', 'crimine'], - 'grotesque':['grottesco', 'grotesque'], - 'war':['guerra', 'war'], - 'children':['bambini', 'kids'], - 'horror':['horror'], - 'music':['musical', 'musica', 'music', 'musicale'], - 'mistery':['mistero', 'giallo', 'mystery'], - 'noir':['noir'], - 'popular' : ['popolari','popolare', 'più visti'], - 'thriller':['thriller'], - 'top_rated' : ['fortunato', 'votati', 'lucky', 'top'], - 'on_the_air' : ['corso', 'onda', 'diretta', 'dirette'], - 'western':['western'], - 'vos':['sub','sub-ita'], - 'romance':['romantico','sentimentale', 'romance', 'soap'], - 'family':['famiglia','famiglie', 'family', 'historical'], - 'historical':['storico', 'history', 'storia'], - 'az':['lettera','lista','alfabetico','a-z', 'alphabetical'], - 'year':['anno', 'anni', 'year'], - 'update':['replay', 'update'], - 'videolibrary':['teche'], - 'autoplay':[config.get_localized_string(60071)] - } - - suffix_dict = {'_hd':['hd','altadefinizione','alta definizione'], - '_4k':['4K'], - '_az':['lettera','lista','alfabetico','a-z', 'alphabetical'], - '_year':['anno', 'anni', 'year'], - '_genre':['genere', 'generi', 'categorie', 'categoria']} - - search = ['cerca', 'search'] - - search_suffix ={'_movie':['film', 'movie'], - '_tvshow':['serie','tv', 'fiction']} - - def autoselect_thumb(item, genre): - if genre == False: - for thumb, titles in icon_dict.items(): - if any( word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in search): - thumb = 'search' - for suffix, titles in search_suffix.items(): - if any( word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in titles ): - thumb = thumb + suffix - item.thumbnail = get_thumb(thumb + '.png') - elif any( word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in titles ): - if thumb == 'movie' or thumb == 'tvshow': - for suffix, titles in suffix_dict.items(): - if any( word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in titles ): - thumb = thumb + suffix - item.thumbnail = get_thumb(thumb + '.png') - else: item.thumbnail = get_thumb(thumb + '.png') - else: - thumb = item.thumbnail - - else: - for thumb, titles in icon_dict.items(): - if any(word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in titles ): - item.thumbnail = get_thumb(thumb + '.png') - else: - thumb = item.thumbnail - - item.title = re.sub(r'\s*\{[^\}]+\}','',item.title) - return item - if item_or_itemlist: - if type(item_or_itemlist) == list: - for item in item_or_itemlist: - autoselect_thumb(item, genre) - return item_or_itemlist - - else: - return autoselect_thumb(item_or_itemlist, genre) - - elif thumb: - return get_thumb(thumb) - else: - return get_thumb('next.png') diff --git a/core/support.py b/core/support.py index 95622ae7..7a270d10 100755 --- a/core/support.py +++ b/core/support.py @@ -1,33 +1,26 @@ # -*- coding: utf-8 -*- # ----------------------------------------------------------- # support functions that are needed by many channels, to no repeat the same code -import base64 -import inspect -import os -import re -import sys -from time import time +import base64, inspect, os, re, sys PY3 = False if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int if PY3: from concurrent import futures -else: - from concurrent_py2 import futures - -try: import urllib.request as urllib import urllib.parse as urlparse from urllib.parse import urlencode -except ImportError: +else: + from concurrent_py2 import futures import urllib, urlparse from urllib import urlencode -from channelselector import thumb +from time import time from core import httptools, scrapertools, servertools, tmdb, channeltools from core.item import Item from lib import unshortenit -from platformcode import logger, config +from platformcode import config +from platformcode.logger import log from specials import autoplay def hdpass_get_servers(item): @@ -39,28 +32,20 @@ def hdpass_get_servers(item): for mir_url, srv in scrapertools.find_multiple_matches(mir, patron_option): mir_url = scrapertools.decodeHtmlentities(mir_url) log(mir_url) - it = item.clone(action="play", - quality=quality, - title=srv, - server=srv, - url= mir_url) - if not servertools.get_server_parameters(srv.lower()): # do not exists or it's empty - it = hdpass_get_url(it)[0] + it = item.clone(action="play", quality=quality, title=srv, server=srv, url= mir_url) + if not servertools.get_server_parameters(srv.lower()): it = hdpass_get_url(it)[0] # do not exists or it's empty ret.append(it) return ret # Carica la pagina itemlist = [] - if 'hdpass' in item.url or 'hdplayer' in item.url: - url = item.url + if 'hdpass' in item.url or 'hdplayer' in item.url: url = item.url else: data = httptools.downloadpage(item.url, CF=False).data.replace('\n', '') patron = r'<iframe(?: id="[^"]+")? width="[^"]+" height="[^"]+" src="([^"]+)"[^>]+><\/iframe>' url = scrapertools.find_single_match(data, patron) url = url.replace("&download=1", "") - if 'hdpass' not in url and 'hdplayer' not in url: - return itemlist - if not url.startswith('http'): - url = 'https:' + url + if 'hdpass' not in url and 'hdplayer' not in url: return itemlist + if not url.startswith('http'): url = 'https:' + url data = httptools.downloadpage(url, CF=False).data patron_res = '<div class="buttons-bar resolutions-bar">(.*?)<div class="buttons-bar' @@ -68,7 +53,6 @@ def hdpass_get_servers(item): patron_option = r'<a href="([^"]+?)"[^>]+>([^<]+?)</a' res = scrapertools.find_single_match(data, patron_res) - # dbg() with futures.ThreadPoolExecutor() as executor: thL = [] @@ -78,15 +62,14 @@ def hdpass_get_servers(item): for res in futures.as_completed(thL): if res.result(): itemlist.extend(res.result()) - return server(item, itemlist=itemlist) + + return server(item, itemlist=itemlist) def hdpass_get_url(item): data = httptools.downloadpage(item.url, CF=False).data src = scrapertools.find_single_match(data, r'<iframe allowfullscreen custom-src="([^"]+)') - if src: - item.url = base64.b64decode(src) - else: - item.url = scrapertools.find_single_match(data, r'<iframe allowfullscreen src="([^"]+)') + if src: item.url = base64.b64decode(src) + else: item.url = scrapertools.find_single_match(data, r'<iframe allowfullscreen src="([^"]+)') item.url, c = unshortenit.unshorten_only(item.url) return [item] @@ -97,8 +80,7 @@ def color(text, color): def search(channel, item, texto): log(item.url + " search " + texto) - if 'findhost' in dir(channel): - channel.findhost() + if 'findhost' in dir(channel): channel.findhost() item.url = channel.host + "/?s=" + texto try: return channel.peliculas(item) @@ -152,10 +134,8 @@ def scrapeLang(scraped, lang, longtitle): language = '' if scraped['lang']: - if 'ita' in scraped['lang'].lower(): - language = 'ITA' - if 'sub' in scraped['lang'].lower(): - language = 'Sub-' + language + if 'ita' in scraped['lang'].lower(): language = 'ITA' + if 'sub' in scraped['lang'].lower(): language = 'Sub-' + language if not language: language = lang if language: longtitle += typo(language, '_ [] color kod') @@ -812,7 +792,6 @@ def menu(func): channel_config(item, itemlist) # Apply auto Thumbnails at the menus - from channelselector import thumb thumb(itemlist) log(item.channel + ' end') return itemlist @@ -1047,7 +1026,7 @@ def download(itemlist, item, typography='', function_level=1, function=''): from_action=from_action, contentTitle=contentTitle, path=item.path, - thumbnail=thumb(thumb='downloads.png'), + thumbnail=thumb('downloads'), downloadItemlist=downloadItemlist )) if from_action == 'episodios': @@ -1064,7 +1043,7 @@ def download(itemlist, item, typography='', function_level=1, function=''): from_action=from_action, contentTitle=contentTitle, download='season', - thumbnail=thumb(thumb='downloads.png'), + thumbnail=thumb('downloads'), downloadItemlist=downloadItemlist )) @@ -1104,7 +1083,6 @@ def videolibrary(itemlist, item, typography='', function_level=1, function=''): if (function == 'findvideos' and contentType == 'movie') \ or (function == 'episodios' and contentType != 'movie'): if config.get_videolibrary_support() and len(itemlist) > 0: - from channelselector import get_thumb itemlist.append( Item(channel=item.channel, title=title, @@ -1118,7 +1096,7 @@ def videolibrary(itemlist, item, typography='', function_level=1, function=''): from_action=item.action, extra=extra, path=item.path, - thumbnail=get_thumb('add_to_videolibrary.png') + thumbnail=thumb('add_to_videolibrary') )) return itemlist @@ -1249,35 +1227,15 @@ def filterLang(item, itemlist): itemlist = filtertools.get_links(itemlist, item, list_language) return itemlist -# def aplay(item, itemlist, list_servers='', list_quality=''): -# if inspect.stack()[1][3] == 'mainlist': -# autoplay.init(item.channel, list_servers, list_quality) -# autoplay.show_option(item.channel, itemlist) -# else: -# autoplay.start(itemlist, item) - - -def log(*args): - # Function to simplify the log - # Automatically returns File Name and Function Name - string = '' - for arg in args: - string += ' '+str(arg) - frame = inspect.stack()[1] - filename = frame[0].f_code.co_filename - filename = os.path.basename(filename) - logger.info("[" + filename + "] - [" + inspect.stack()[1][3] + "] " + string) - def channel_config(item, itemlist): - from channelselector import get_thumb itemlist.append( Item(channel='setting', action="channel_config", title=typo(config.get_localized_string(60587), 'color kod bold'), config=item.channel, folder=False, - thumbnail=get_thumb('setting_0.png')) + thumbnail=thumb('setting_0')) ) @@ -1286,6 +1244,7 @@ def extract_wrapped(decorated): closure = (c.cell_contents for c in decorated.__closure__) return next((c for c in closure if isinstance(c, FunctionType)), None) + def addQualityTag(item, itemlist, data, patron): if itemlist: defQualVideo = { @@ -1376,4 +1335,115 @@ def get_jwplayer_mediaurl(data, srvName, onlyHttp=False): video_urls.append(['.' + url.split('.')[-1] + ' [' + quality + '] [' + srvName + ']', url if not onlyHttp else url.replace('https://', 'http://')]) video_urls.sort(key=lambda x: x[0].split()[1]) - return video_urls \ No newline at end of file + return video_urls + + +def thumb(item_itemlist_string=None, genre=False, live=False): + from channelselector import get_thumb + if live: + if type(item_itemlist_string) == list: + for item in item_itemlist_string: + item.thumbnail = "https://raw.githubusercontent.com/kodiondemand/media/master/live/" + item.fulltitle.lower().replace(' ','_') + '.png' + else: + item_itemlist_string.thumbnail = "https://raw.githubusercontent.com/kodiondemand/media/master/live/" + item.fulltitle.lower().replace(' ','_') + '.png' + return item_itemlist_string + + import re + icon_dict = {'movie':['film', 'movie'], + 'tvshow':['serie','tv','episodi','episodio','fiction', 'show'], + 'documentary':['documentari','documentario', 'documentary', 'documentaristico'], + 'teenager':['ragazzi','teenager', 'teen'], + 'learning':['learning'], + 'all':['tutti', 'all'], + 'news':['novità', "novita'", 'aggiornamenti', 'nuovi', 'nuove', 'new', 'newest', 'news', 'ultimi'], + 'now_playing':['cinema', 'in sala'], + 'anime':['anime'], + 'genres':['genere', 'generi', 'categorie', 'categoria', 'category'], + 'animation': ['animazione', 'cartoni', 'cartoon', 'animation'], + 'action':['azione', 'arti marziali', 'action'], + 'adventure': ['avventura', 'adventure'], + 'biographical':['biografico', 'biographical'], + 'comedy':['comico', 'commedia', 'demenziale', 'comedy', 'brillante'], + 'adult':['erotico', 'hentai', 'harem', 'ecchi', 'adult'], + 'drama':['drammatico', 'drama', 'dramma'], + 'syfy':['fantascienza', 'science fiction', 'syfy', 'sci'], + 'fantasy':['fantasy', 'magia', 'magic', 'fantastico'], + 'crime':['gangster','poliziesco', 'crime', 'crimine'], + 'grotesque':['grottesco', 'grotesque'], + 'war':['guerra', 'war'], + 'children':['bambini', 'kids'], + 'horror':['horror'], + 'music':['musical', 'musica', 'music', 'musicale'], + 'mistery':['mistero', 'giallo', 'mystery'], + 'noir':['noir'], + 'popular' : ['popolari','popolare', 'più visti'], + 'thriller':['thriller'], + 'top_rated' : ['fortunato', 'votati', 'lucky', 'top'], + 'on_the_air' : ['corso', 'onda', 'diretta', 'dirette'], + 'western':['western'], + 'vos':['sub','sub-ita'], + 'romance':['romantico','sentimentale', 'romance', 'soap'], + 'family':['famiglia','famiglie', 'family', 'historical'], + 'historical':['storico', 'history', 'storia'], + 'az':['lettera','lista','alfabetico','a-z', 'alphabetical'], + 'year':['anno', 'anni', 'year'], + 'update':['replay', 'update'], + 'videolibrary':['teche'], + 'autoplay':[config.get_localized_string(60071)] + } + + suffix_dict = {'_hd':['hd','altadefinizione','alta definizione'], + '_4k':['4K'], + '_az':['lettera','lista','alfabetico','a-z', 'alphabetical'], + '_year':['anno', 'anni', 'year'], + '_genre':['genere', 'generi', 'categorie', 'categoria']} + + search = ['cerca', 'search'] + + search_suffix ={'_movie':['film', 'movie'], + '_tvshow':['serie','tv', 'fiction']} + + def autoselect_thumb(item, genre): + if genre == False: + for thumb, titles in icon_dict.items(): + if any(word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in search): + thumb = 'search' + for suffix, titles in search_suffix.items(): + if any(word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in titles ): + thumb = thumb + suffix + item.thumbnail = get_thumb(thumb + '.png') + elif any(word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in titles ): + if thumb == 'movie' or thumb == 'tvshow': + for suffix, titles in suffix_dict.items(): + if any(word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in titles ): + thumb = thumb + suffix + item.thumbnail = get_thumb(thumb + '.png') + else: item.thumbnail = get_thumb(thumb + '.png') + else: + thumb = item.thumbnail + + else: + for thumb, titles in icon_dict.items(): + if any(word in re.split(r'\.|\{|\}|\[|\]|\(|\)| ',item.title.lower()) for word in titles ): + item.thumbnail = get_thumb(thumb + '.png') + else: + thumb = item.thumbnail + + item.title = re.sub(r'\s*\{[^\}]+\}','',item.title) + return item + + if item_itemlist_string: + if type(item_itemlist_string) == list: + for item in item_itemlist_string: + autoselect_thumb(item, genre) + return item_itemlist_string + + elif type(item_itemlist_string) == str: + filename, file_extension = os.path.splitext(item_itemlist_string) + if not file_extension: item_itemlist_string += '.png' + return get_thumb(item_itemlist_string) + else: + return autoselect_thumb(item_itemlist_string, genre) + + else: + return get_thumb('next.png') \ No newline at end of file diff --git a/platformcode/logger.py b/platformcode/logger.py index 785dd5cf..ab7a7a2d 100644 --- a/platformcode/logger.py +++ b/platformcode/logger.py @@ -102,6 +102,18 @@ def error(texto=""): xbmc.log(texto, xbmc.LOGERROR) +def log(*args): + # Function to simplify the log + # Automatically returns File Name and Function Name + import os + string = '' + for arg in args: string += ' '+str(arg) + frame = inspect.stack()[1] + filename = frame[0].f_code.co_filename + filename = os.path.basename(filename) + info("[" + filename + "] - [" + inspect.stack()[1][3] + "] " + string) + + class WebErrorException(Exception): def __init__(self, *args, **kwargs): Exception.__init__(self, *args, **kwargs) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index f6a9433d..5e7f686b 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -6071,6 +6071,10 @@ msgctxt "#70817" msgid "La Serie "%s" non è gestita da KoD, Vuoi cercarla?" msgstr "" +msgctxt "#70818" +msgid "YouTube is installed on your device, but is not active. Do you want to activate it?" +msgstr "" + # DNS start [ settings and declaration ] msgctxt "#707401" msgid "Enable DNS check alert" diff --git a/resources/language/resource.language.it_it/strings.po b/resources/language/resource.language.it_it/strings.po index a4e88eaa..90e9007f 100644 --- a/resources/language/resource.language.it_it/strings.po +++ b/resources/language/resource.language.it_it/strings.po @@ -6071,6 +6071,10 @@ msgctxt "#70817" msgid "La Serie "%s" non è gestita da KoD, Vuoi cercarla?" msgstr "La Serie "%s" non è gestita da KoD, Vuoi cercarla?" +msgctxt "#70818" +msgid "YouTube is installed on your device, but is not active. Do you want to activate it?" +msgstr "YouTube è installato sul tuo dispositivo, ma non è attivo. Vuoi Attivarlo?" + # DNS start [ settings and declaration ] msgctxt "#707401" msgid "Enable DNS check alert" diff --git a/servers/youtube.py b/servers/youtube.py index 531a2df2..f0250994 100644 --- a/servers/youtube.py +++ b/servers/youtube.py @@ -1,91 +1,9 @@ # s-*- coding: utf-8 -*- -import sys -PY3 = False -if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int - -if PY3: - #from future import standard_library - #standard_library.install_aliases() - import urllib.parse as urllib # Es muy lento en PY2. En PY3 es nativo - import urllib.parse as urlparse -else: - import urllib # Usamos el nativo de PY2 que es más rápido - import urlparse - -import re - -from core import httptools -from core import jsontools as json -from core import scrapertools -from platformcode import config, logger - - -itag_list = {1: "video", - 5: "flv 240p", - 6: "flv 270p", - 17: "3gp 144p", - 18: "mp4 360p", - 22: "mp4 720p", - 34: "flv 360p", - 35: "flv 480p", - 36: "3gp 180p", - 37: "mp4 1080p", - 38: "mp4 3072p", - 43: "webm 360p", - 44: "webm 480p", - 45: "webm 720p", - 46: "webm 1080p", - 82: "mp4 360p 3D", - 83: "mp4 480p 3D", - 84: "mp4 720p 3D", - 85: "mp4 1080p 3D", - 92: "hls 240p 3D", - 93: "hls 360p 3D", - 94: "hls 480p 3D", - 95: "hls 720p 3D", - 96: "hls 1080p", - 100: "webm 360p 3D", - 101: "webm 480p 3D", - 102: "webm 720p 3D", - 132: "hls 240p", - 133: "mp4 240p", - 134: "mp4 360p", - 135: "mp4 480p", - 136: "mp4 720p", - 137: "mp4 1080p", - 138: "mp4 2160p", - 160: "mp4 144p", - 167: "webm 360p", - 168: "webm 480p", - 169: "webm 1080p", - 219: "webm 144p", - 242: "webm 240p", - 243: "webm 360p", - 244: "webm 480p", - 245: "webm 480p", - 246: "webm 480p", - 247: "webm 720p", - 248: "webm 1080p", - 266: "mp4 2160p", - 271: "webm 1440p", - 272: "webm 4320p", - 278: "webm 144p", - 298: "mp4 720p", - 299: "mp4 1080p", - 302: "webm 720p", - 303: "webm 1080p", - 308: "webm 1440p", - 313: "webm 2160p", - 315: "webm 2160p", - 330: "webm 144p hdr", - 331: "webm 240p hdr", - 332: "webm 360p hdr", - 333: "webm 480p hdr", - 334: "webm 720p hdr", - 335: "webm 1080p hdr", - 336: "webm 1440p hdr"} +from core import httptools, scrapertools, filetools +from platformcode import config, logger, platformtools +name = 'plugin.video.youtube' def test_video_exists(page_url): logger.info("(page_url='%s')" % page_url) @@ -93,137 +11,37 @@ def test_video_exists(page_url): data = httptools.downloadpage(page_url).data if "File was deleted" in data or "Video non disponibile" in data: - return False, config.get_localized_string(70449) % "Youtube" + return False, config.get_localized_string(70449) % "YouTube" return True, "" def get_video_url(page_url, premium=False, user="", password="", video_password=""): + import xbmc from xbmcaddon import Addon logger.info("(page_url='%s')" % page_url) + video_urls = [] if not page_url.startswith("http"): page_url = "http://www.youtube.com/watch?v=%s" % page_url logger.info(" page_url->'%s'" % page_url) video_id = scrapertools.find_single_match(page_url, '(?:v=|embed/)([A-z0-9_-]{11})') + # from core.support import dbg;dbg() try: - __settings__ = Addon('plugin.video.youtube') - if not __settings__.getSetting('kodion.video.quality.mpd'): + __settings__ = Addon(name) + if __settings__.getSetting('kodion.video.quality.mpd') == 'false': __settings__.setSetting('kodion.video.quality.mpd', 'true') - video_urls = [[ 'con YouTube', 'plugin://plugin.video.youtube/play/?video_id=' + video_id ]] + video_urls = [['con YouTube', 'plugin://plugin.video.youtube/play/?video_id=' + video_id ]] except: - video_urls = extract_videos(video_id) - - return sorted(video_urls, reverse=True) - - -def remove_additional_ending_delimiter(data): - pos = data.find("};") - if pos != -1: - data = data[:pos + 1] - return data - - -def normalize_url(url): - if url[0:2] == "//": - url = "http:" + url - return url - - -def extract_flashvars(data): - assets = 0 - flashvars = {} - found = False - - for line in data.split("\n"): - if line.strip().find(";ytplayer.config = ") > 0: - found = True - p1 = line.find(";ytplayer.config = ") + len(";ytplayer.config = ") - 1 - p2 = line.rfind(";") - if p1 <= 0 or p2 <= 0: - continue - data = line[p1 + 1:p2] - break - data = remove_additional_ending_delimiter(data) - - if found: - data = json.load(data) - if assets: - flashvars = data["assets"] + if filetools.exists(xbmc.translatePath('special://profile/addon_data/' + name)): + if platformtools.dialog_yesno(config.get_localized_string(70784), config.get_localized_string(70818)): + xbmc.executeJSONRPC('{"jsonrpc": "2.0", "id":1, "method": "Addons.SetAddonEnabled", "params": { "addonid": "' + name + '", "enabled": true }}') + else: return [['','']] else: - flashvars = data["args"] + xbmc.executebuiltin('InstallAddon(' + name + ')', wait=True) + try: Addon(name) + except: return [['','']] - for k in ["html", "css", "js"]: - if k in flashvars: - flashvars[k] = normalize_url(flashvars[k]) + return get_video_url(page_url) + return video_urls - return flashvars - - -def get_signature(youtube_page_data): - - from lib.jsinterpreter import JSInterpreter - - urljs = scrapertools.find_single_match(youtube_page_data, '"assets":.*?"js":\s*"([^"]+)"') - urljs = urljs.replace("\\", "") - if urljs: - if not re.search(r'https?://', urljs): - urljs = urlparse.urljoin("https://www.youtube.com", urljs) - data_js = httptools.downloadpage(urljs).data - - pattern = r'(?P<fname>\w+)=function\(\w+\){(\w)=\2\.split\(""\);.*?return\s+\2\.join\(""\)}' - - funcname = re.search(pattern, data_js).group('fname') - - jsi = JSInterpreter(data_js) - js_signature = jsi.extract_function(funcname) - - return js_signature - - -def extract_videos(video_id): - - - url = 'https://www.youtube.com/get_video_info?video_id=%s&eurl=https://youtube.googleapis.com/v/%s&ssl_stream=1' % \ - (video_id, video_id) - data = httptools.downloadpage(url).data - - video_urls = [] - params = dict(urlparse.parse_qsl(data)) - - if params.get('hlsvp'): - video_urls.append(["(LIVE .m3u8) [youtube]", params['hlsvp']]) - return video_urls - - if config.is_xbmc(): - import xbmc - xbmc_version = config.get_platform(True)['num_version'] - if xbmc_version >= 17 and xbmc.getCondVisibility('System.HasAddon(inputstream.adaptive)') \ - and params.get('dashmpd'): - if params.get('use_cipher_signature', '') != 'True': - video_urls.append(['mpd HD [youtube]', params['dashmpd'], 0, '', True]) - - youtube_page_data = httptools.downloadpage("https://www.youtube.com/watch?v=%s" % video_id).data - - params = extract_flashvars(youtube_page_data) - - if params.get('player_response'): - params = json.load(params.get('player_response')) - data_flashvars = params["streamingData"] - for s_data in data_flashvars: - if s_data in ["adaptiveFormats", "formats"]: - for opt in data_flashvars[s_data]: - opt = dict(opt) - if "audioQuality" not in opt: - continue - if "cipher" in opt: - signature = get_signature(youtube_page_data) - cipher = dict(urlparse.parse_qsl(urllib.unquote(opt["cipher"]))) - url = re.search('url=(.*)', opt["cipher"]).group(1) - s = cipher.get('s') - url = "%s&sig=%s" % (urllib.unquote(url), signature([s])) - video_urls.append(["%s" % itag_list.get(opt["itag"], "video"), url]) - elif opt["itag"] in itag_list: - video_urls.append(["%s" % itag_list.get(opt["itag"], "video"), opt["url"]]) - - return video_urls \ No newline at end of file diff --git a/specials/autorenumber.py b/specials/autorenumber.py index cf9342f6..2086d9ea 100644 --- a/specials/autorenumber.py +++ b/specials/autorenumber.py @@ -53,15 +53,19 @@ def renumber(itemlist, item='', typography=''): dict_series = load(itemlist[0]) if len(itemlist) > 0 else {} if item: + # from core.support import dbg;dbg() item.channel = item.from_channel if item.from_channel else item.channel title = item.fulltitle.rstrip() - if item.channel in item.channel_prefs and TAG_TVSHOW_RENUMERATE in item.channel_prefs[item.channel] and title not in dict_series: + already_renumbered = scrapertools.find_single_match(itemlist[0].title, r'(\d+\D\d+)') + if already_renumbered : + return itemlist + elif item.channel in item.channel_prefs and TAG_TVSHOW_RENUMERATE in item.channel_prefs[item.channel] and title not in dict_series: from core.videolibrarytools import check_renumber_options from specials.videolibrary import update_videolibrary check_renumber_options(item) update_videolibrary(item) - if inspect.stack()[2][3] == 'find_episodes': + elif inspect.stack()[2][3] == 'find_episodes': return itemlist elif title in dict_series and TAG_ID in dict_series[title]: @@ -337,6 +341,16 @@ def manual_renumeration(item, modify=False): return json.loads(base64.b64decode(EpisodeDict)) +def delete_renumeration(item): + log() + if item.from_channel: item.channel = item.from_channel + title = item.fulltitle.rstrip() + + dict_series = load(item) + if title in dict_series: del dict_series[title] + write(item, dict_series) + + def make_list(itemlist, item, typography, dict_series, ID, Season, Episode, Mode, title): log() exist = True @@ -515,9 +529,11 @@ def context(exist): def select_type(item): - select = platformtools.dialog_select(config.get_localized_string(70730),[typo(config.get_localized_string(70731),'bold'), typo(config.get_localized_string(70732),'bold')]) + select = platformtools.dialog_select(config.get_localized_string(70730),[typo(config.get_localized_string(70731),'bold'), typo(config.get_localized_string(70732),'bold'), typo(config.get_localized_string(707433),'bold')]) if select == 0: semiautomatic_config_item(item) - else: manual_renumeration(item) + elif select == 1: manual_renumeration(item) + elif select == 2: return delete_renumeration(item) + else: return def filename(item): diff --git a/specials/filmontv.py b/specials/filmontv.py index cf5f8a34..1900558c 100644 --- a/specials/filmontv.py +++ b/specials/filmontv.py @@ -17,10 +17,10 @@ blacklisted_genres = ['attualita', 'scienza', 'religione', 'cucina', 'notiziario def mainlist(item): support.log() - itemlist = [Item(title=support.typo('Film in onda oggi', 'bold'), channel=item.channel, action='category', contentType='movie', thumbnail=support.thumb(thumb='movie.png')), - Item(title=support.typo('Serie Tv in onda oggi', 'bold'), channel=item.channel, action='peliculas', contentType='tvshow', thumbnail=support.thumb(thumb='tvshow.png')), - Item(title=support.typo('Guida tv per canale', 'bold'), channel=item.channel, action='listaCanali', thumbnail=support.thumb(thumb='on_the_air.png')), - Item(title=support.typo('Canali live', 'bold'), channel=item.channel, action='live', thumbnail=support.thumb(thumb='tvshow_on_the_air.png'))] + itemlist = [Item(title=support.typo('Film in onda oggi', 'bold'), channel=item.channel, action='category', contentType='movie', thumbnail=support.thumb('movie')), + Item(title=support.typo('Serie Tv in onda oggi', 'bold'), channel=item.channel, action='peliculas', contentType='tvshow', thumbnail=support.thumb('tvshow')), + Item(title=support.typo('Guida tv per canale', 'bold'), channel=item.channel, action='listaCanali', thumbnail=support.thumb('on_the_air')), + Item(title=support.typo('Canali live', 'bold'), channel=item.channel, action='live', thumbnail=support.thumb('tvshow_on_the_air'))] return itemlist diff --git a/specials/videolibrary.py b/specials/videolibrary.py index d88d85a7..069f9b65 100644 --- a/specials/videolibrary.py +++ b/specials/videolibrary.py @@ -1132,7 +1132,7 @@ def add_download_items(item, itemlist): from_action="findvideos", contentTitle=item.contentTitle, path=item.path, - thumbnail=thumb(thumb='downloads.png'), + thumbnail=thumb('downloads'), parent=item.tourl()) if item.action == 'findvideos': if item.contentType == 'episode':