Test Nuovo launcher
This commit is contained in:
@@ -74,20 +74,15 @@ def search(item, text):
|
||||
def peliculas(item):
|
||||
search = item.search
|
||||
anime = True
|
||||
# debug = True
|
||||
if 'movie' in item.url:
|
||||
action = 'findvideos'
|
||||
else:
|
||||
action = 'check'
|
||||
action = 'check'
|
||||
|
||||
# if not item.args:
|
||||
# pagination = ''
|
||||
# patron = r'<a\s*href="(?P<url>[^"]+)"\s*title="(?P<title>[^"]+)">'
|
||||
# else:
|
||||
patron = r'<a href="(?P<url>[^"]+)"[^>]+>\s*<img src="(?P<thumb>[^"]+)" alt="(?P<title>.*?)(?: Sub| sub| SUB|")'
|
||||
|
||||
if search:
|
||||
patron = r'<a href="(?P<url>[^"]+)"\s*title="(?P<title>.*?)(?: Sub| sub| SUB|")'
|
||||
|
||||
if item.args == 'newest': item.action = 'findvideos'
|
||||
|
||||
|
||||
patronNext = '<li class="page-item disabled">(?:[^>]+>){4}<a class="page-link" href="([^"]+)'
|
||||
|
||||
def itemHook(item):
|
||||
@@ -100,7 +95,7 @@ def peliculas(item):
|
||||
|
||||
|
||||
def check(item):
|
||||
m = support.match(item, headers=headers, patron=r'Tipologia[^>]+><a href="([^"]+)"')
|
||||
m = support.match(item, headers=headers, patron=r'Tipologia[^>]+>\s*<a href="([^"]+)"')
|
||||
item.data = m.data
|
||||
if 'movie' in m.match:
|
||||
item.contentType = 'movie'
|
||||
@@ -112,6 +107,7 @@ def check(item):
|
||||
@support.scrape
|
||||
def episodios(item):
|
||||
anime = True
|
||||
pagination = 50
|
||||
data = item.data
|
||||
|
||||
if '<h6>Streaming</h6>' in data:
|
||||
@@ -130,30 +126,37 @@ def episodios(item):
|
||||
def findvideos(item):
|
||||
support.info(item)
|
||||
itemlist = []
|
||||
|
||||
if 'adf.ly' in item.url:
|
||||
from servers.decrypters import adfly
|
||||
url = adfly.get_long_url(item.url)
|
||||
|
||||
elif 'bit.ly' in item.url:
|
||||
url = support.httptools.downloadpage(item.url, only_headers=True, follow_redirects=False).headers.get("location")
|
||||
|
||||
if item.data:
|
||||
url = support.match(item.data, patron=r'<a\s*href="([^"]+)"\s*title="[^"]+"\s*class="btn btn-dark mb-1">').match
|
||||
else:
|
||||
url = host
|
||||
for u in item.url.split('/'):
|
||||
if u and 'animeforce' not in u and 'http' not in u:
|
||||
url += '/' + u
|
||||
url = item.url
|
||||
|
||||
if 'php?' in url:
|
||||
url = support.httptools.downloadpage(url, only_headers=True, follow_redirects=False).headers.get("location")
|
||||
url = support.match(url, patron=r'class="button"><a href=(?:")?([^" ]+)', headers=headers).match
|
||||
else:
|
||||
if item.data: url = item.data
|
||||
url = support.match(url, patron=r'data-href="([^"]+)" target').match
|
||||
if not url: url = support.match(url, patron=[r'<source src=(?:")?([^" ]+)',r'name="_wp_http_referer" value="([^"]+)"']).match
|
||||
if url.startswith('//'): url = 'https:' + url
|
||||
elif url.startswith('/'): url = 'https:/' + url
|
||||
if 'vvvvid' in url: itemlist.append(item.clone(action="play", title='VVVVID', url=url, server='vvvvid'))
|
||||
else: itemlist.append(item.clone(action="play", title=support.config.get_localized_string(30137), url=url, server='directo'))
|
||||
# if 'adf.ly' in item.url:
|
||||
# from servers.decrypters import adfly
|
||||
# url = adfly.get_long_url(item.url)
|
||||
|
||||
# elif 'bit.ly' in item.url:
|
||||
# url = support.httptools.downloadpage(item.url, only_headers=True, follow_redirects=False).headers.get("location")
|
||||
|
||||
# else:
|
||||
# url = host
|
||||
# for u in item.url.split('/'):
|
||||
# if u and 'animeforce' not in u and 'http' not in u:
|
||||
# url += '/' + u
|
||||
|
||||
|
||||
# if 'php?' in url:
|
||||
# url = support.httptools.downloadpage(url, only_headers=True, follow_redirects=False).headers.get("location")
|
||||
# url = support.match(url, patron=r'class="button"><a href=(?:")?([^" ]+)', headers=headers).match
|
||||
# else:
|
||||
# if item.data: url = item.data
|
||||
# if item.contentType == 'movie': url = support.match()
|
||||
# url = support.match(url, patron=r'data-href="([^"]+)" target').match
|
||||
# if not url: url = support.match(url, patron=[r'<source src=(?:")?([^" ]+)',r'name="_wp_http_referer" value="([^"]+)"']).match
|
||||
# if url.startswith('//'): url = 'https:' + url
|
||||
# elif url.startswith('/'): url = 'https:/' + url
|
||||
url = support.match(url, patron=r'data-href="([^"]+)" target').match
|
||||
if 'vvvvid' in url: itemlist.append(item.clone(action="play", title='VVVVID', url=url, server='vvvvid'))
|
||||
else: itemlist.append(item.clone(action="play", title=support.config.get_localized_string(30137), url=url, server='directo'))
|
||||
|
||||
return support.server(item, itemlist=itemlist)
|
||||
|
||||
@@ -54,7 +54,7 @@ def search(item, texto):
|
||||
|
||||
item.url = host + "/?s=" + texto
|
||||
try:
|
||||
item.contentType = 'undefined'
|
||||
item.args = 'search'
|
||||
return peliculas(item)
|
||||
|
||||
# Continua la ricerca in caso di errore
|
||||
@@ -78,11 +78,11 @@ def newest(categoria):
|
||||
|
||||
@support.scrape
|
||||
def peliculas(item):
|
||||
if item.contentType == 'undefined':
|
||||
action = 'check'
|
||||
action = 'check'
|
||||
item.contentType == 'undefined'
|
||||
if item.args == 'search':
|
||||
patron = r'<a href="(?P<url>[^"]+)" title="Permalink to\s*(?P<title>[^"]+) \((?P<year>[0-9]+)[^<]*\)[^"]*"[^>]+>\s*<img[^s]+src="(?P<thumb>[^"]+)".*?<div class="calitate">\s*<p>(?P<quality>[^<]+)<\/p>'
|
||||
else:
|
||||
action = 'findvideos' if item.contentType == 'movie' else 'episodios'
|
||||
patronNext = r'<a class="nextpostslink" rel="next" href="([^"]+)">'
|
||||
patron = r'<div class="mediaWrap mediaWrapAlt">\s*<a href="(?P<url>[^"]+)"(?:[^>]+)?>?\s*(?:<img[^s]+src="(?P<thumb>[^"]+)"[^>]+>\s*)?<\/a>[^>]+>[^>]+>[^>]+>(?P<title>[^<]+?)(?P<lang>[sS][uU][bB]\-[iI][tT][aA]+)?(?:[ ]?\((?P<year>\d{4})-?(?:\d{4})?)\).[^<]+[^>]+><\/a>[^>]+>[^>]+>[^>]+>[^>]+>[^>]+>\s*(?P<quality>[a-zA-Z-0-9\.]+)?'
|
||||
patronBlock = r'<div id="main_col">(?P<block>.*?)<!\-\- main_col \-\->'
|
||||
@@ -139,14 +139,14 @@ def check(item):
|
||||
if 'sub' in check.lower():
|
||||
item.contentLanguage = 'Sub-ITA'
|
||||
logger.debug("CHECK : ", check)
|
||||
if 'anime' in check.lower():
|
||||
item.contentType = 'tvshow'
|
||||
logger.debug('select = ### è una anime ###')
|
||||
try:
|
||||
return episodios(item)
|
||||
except:
|
||||
pass
|
||||
elif 'serie' in check.lower():
|
||||
# if 'anime' in check.lower():
|
||||
# item.contentType = 'tvshow'
|
||||
# logger.debug('select = ### è una anime ###')
|
||||
# try:
|
||||
# return episodios(item)
|
||||
# except:
|
||||
# pass
|
||||
if 'serie' in check.lower():
|
||||
item.contentType = 'tvshow'
|
||||
return episodios(item)
|
||||
else:
|
||||
|
||||
@@ -974,7 +974,7 @@ def add_movie(item):
|
||||
@param item: item to be saved.
|
||||
"""
|
||||
logger.debug()
|
||||
from platformcode.launcher import set_search_temp; set_search_temp(item)
|
||||
# from platformcode.launcher import set_search_temp; set_search_temp(item)
|
||||
item.contentType = 'movie'
|
||||
|
||||
# To disambiguate titles, TMDB is caused to ask for the really desired title
|
||||
@@ -1023,7 +1023,7 @@ def add_tvshow(item, channel=None, itemlist=[]):
|
||||
|
||||
logger.debug("show=#" + item.show + "#")
|
||||
item.contentType = 'tvshow'
|
||||
from platformcode.launcher import set_search_temp; set_search_temp(item)
|
||||
# from platformcode.launcher import set_search_temp; set_search_temp(item)
|
||||
|
||||
if item.channel == "downloads":
|
||||
itemlist = [item.clone()]
|
||||
|
||||
@@ -2,27 +2,20 @@
|
||||
# ------------------------------------------------------------
|
||||
# XBMC Launcher (xbmc / kodi)
|
||||
# ------------------------------------------------------------
|
||||
import datetime
|
||||
import json
|
||||
import sys, os
|
||||
|
||||
import requests
|
||||
|
||||
PY3 = False
|
||||
if sys.version_info[0] >= 3:PY3 = True; unicode = str; unichr = chr; long = int
|
||||
|
||||
import sys
|
||||
from core.item import Item
|
||||
from core import filetools, jsontools
|
||||
from platformcode import config, logger, platformtools, xbmc_videolibrary
|
||||
from core import filetools
|
||||
from platformcode import config, logger, platformtools
|
||||
from platformcode.logger import WebErrorException
|
||||
temp_search_file = config.get_temp_file('temp-search')
|
||||
|
||||
|
||||
def start():
|
||||
""" First function that is executed when entering the plugin.
|
||||
'''
|
||||
First function that is executed when entering the plugin.
|
||||
Within this function all calls should go to
|
||||
functions that we want to execute as soon as we open the plugin.
|
||||
"""
|
||||
'''
|
||||
logger.debug()
|
||||
|
||||
if not config.dev_mode():
|
||||
@@ -31,7 +24,7 @@ def start():
|
||||
changelog = fileC.read()
|
||||
if changelog.strip():
|
||||
platformtools.dialog_ok('Kodi on Demand', 'Aggiornamenti applicati:\n' + changelog)
|
||||
os.remove(config.changelogFile)
|
||||
filetools.remove(config.changelogFile)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -39,116 +32,58 @@ def start():
|
||||
def run(item=None):
|
||||
logger.debug()
|
||||
|
||||
if not item:
|
||||
# Extract item from sys.argv
|
||||
if sys.argv[2]:
|
||||
sp = sys.argv[2].split('&')
|
||||
url = sp[0]
|
||||
item = Item().fromurl(url)
|
||||
if len(sp) > 1:
|
||||
for e in sp[1:]:
|
||||
key, val = e.split('=')
|
||||
item.__setattr__(key, val)
|
||||
# If no item, this is mainlist
|
||||
else:
|
||||
item = Item(channel="channelselector", action="getmainlist", viewmode="movie")
|
||||
if not config.get_setting('show_once'):
|
||||
if not config.get_all_settings_addon():
|
||||
logger.error('corrupted settings.xml!!')
|
||||
settings_xml = os.path.join(config.get_data_path(), "settings.xml")
|
||||
settings_bak = os.path.join(config.get_data_path(), "settings.bak")
|
||||
if filetools.exists(settings_bak):
|
||||
filetools.copy(settings_bak, settings_xml, True)
|
||||
logger.info('restored settings.xml from backup')
|
||||
else:
|
||||
filetools.write(settings_xml, '<settings version="2">\n</settings>') # resetted settings
|
||||
else:
|
||||
from platformcode import xbmc_videolibrary
|
||||
xbmc_videolibrary.ask_set_content(silent=False)
|
||||
config.set_setting('show_once', True)
|
||||
# Extract item from sys.argv
|
||||
if not item: item = makeItem()
|
||||
|
||||
logger.info(item.tostring())
|
||||
# Load or Repare Settings
|
||||
if not config.get_setting('show_once'): showOnce()
|
||||
|
||||
reload = False
|
||||
from core import db
|
||||
if db['OnPlay'].get('addon', False):
|
||||
reload = True
|
||||
db['OnPlay']['addon'] = False
|
||||
db.close()
|
||||
# Acrions
|
||||
logger.debug(item.tostring())
|
||||
|
||||
try:
|
||||
# Active tmdb
|
||||
if not config.get_setting('tmdb_active'):
|
||||
config.set_setting('tmdb_active', True)
|
||||
|
||||
# If item has no action, stops here
|
||||
if item.action == "":
|
||||
logger.debug("Item without action")
|
||||
if item.action == '':
|
||||
logger.debug('Item without action')
|
||||
return
|
||||
|
||||
# Action for main menu in channelselector
|
||||
elif item.action == "getmainlist":
|
||||
# Channel Selector
|
||||
if item.channel == 'channelselector':
|
||||
itemlist = []
|
||||
import channelselector
|
||||
|
||||
itemlist = channelselector.getmainlist()
|
||||
|
||||
if item.action == 'getmainlist': # Action for main menu in channelselector
|
||||
itemlist = channelselector.getmainlist()
|
||||
elif item.action == 'getchanneltypes': # Action for channel types on channelselector: movies, series, etc.
|
||||
itemlist = channelselector.getchanneltypes()
|
||||
elif item.action == 'filterchannels': # Action for channel listing on channelselector
|
||||
itemlist = channelselector.filterchannels(item.channel_type)
|
||||
platformtools.render_items(itemlist, item)
|
||||
|
||||
# Action for channel types on channelselector: movies, series, etc.
|
||||
elif item.action == "getchanneltypes":
|
||||
import channelselector
|
||||
itemlist = channelselector.getchanneltypes()
|
||||
|
||||
platformtools.render_items(itemlist, item)
|
||||
|
||||
# Action for channel listing on channelselector
|
||||
elif item.action == "filterchannels":
|
||||
import channelselector
|
||||
itemlist = channelselector.filterchannels(item.channel_type)
|
||||
|
||||
platformtools.render_items(itemlist, item)
|
||||
|
||||
# Special action for playing a video from the library
|
||||
elif item.action == "play_from_library":
|
||||
play_from_library(item)
|
||||
return
|
||||
elif item.action == 'play_from_library':
|
||||
return playFromLibrary(item)
|
||||
|
||||
elif item.action == "keymap":
|
||||
from platformcode import keymaptools
|
||||
if item.open:
|
||||
return keymaptools.open_shortcut_menu()
|
||||
else:
|
||||
return keymaptools.set_key()
|
||||
# Special play action
|
||||
elif item.action == 'play': play(item)
|
||||
|
||||
elif item.channel == "infoplus":
|
||||
from platformcode import infoplus
|
||||
return infoplus.Main(item)
|
||||
# Special findvideos Action
|
||||
elif item.action == 'findvideos': findvideos(item)
|
||||
|
||||
elif item.channel == "backup":
|
||||
from platformcode import backup
|
||||
return getattr(backup, item.action)(item)
|
||||
# Special action for searching, first asks for the words then call the "search" function
|
||||
elif item.action == 'search': search(item)
|
||||
|
||||
elif item.channel == "elementum_download":
|
||||
from platformcode import elementum_download
|
||||
return getattr(elementum_download, item.action)(item)
|
||||
######## Following shares must be improved ########
|
||||
|
||||
elif item.channel == "shortcuts":
|
||||
from platformcode import shortcuts
|
||||
return getattr(shortcuts, item.action)(item)
|
||||
|
||||
elif item.channel == "autorenumber":
|
||||
from platformcode import autorenumber
|
||||
return getattr(autorenumber, item.action)(item)
|
||||
|
||||
elif item.action == "delete_key":
|
||||
from platformcode import keymaptools
|
||||
return keymaptools.delete_key()
|
||||
|
||||
elif item.action == "script":
|
||||
from core import tmdb
|
||||
tmdb.clean_cache()
|
||||
platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(60011), time=2000, sound=False)
|
||||
# Special itemInfo Action
|
||||
elif item.action == "itemInfo":
|
||||
platformtools.dialog_textviewer('Item info', item.parent)
|
||||
|
||||
# Special action for open item.url in browser
|
||||
elif item.action == "open_browser":
|
||||
import webbrowser
|
||||
if not webbrowser.open(item.url):
|
||||
@@ -157,6 +92,8 @@ def run(item=None):
|
||||
xbmc.executebuiltin('StartAndroidActivity("", "android.intent.action.VIEW", "", "%s")' % item.url)
|
||||
else:
|
||||
platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(70740) % "\n".join([item.url[j:j+57] for j in range(0, len(item.url), 57)]))
|
||||
|
||||
# Special gotopage Action
|
||||
elif item.action == "gotopage":
|
||||
page = platformtools.dialog_numeric(0, config.get_localized_string(70513))
|
||||
if page:
|
||||
@@ -169,148 +106,52 @@ def run(item=None):
|
||||
item.url = re.sub('([=/])[0-9]+(/?)$', '\g<1>' + page + '\g<2>', item.url)
|
||||
xbmc.executebuiltin("Container.Update(%s?%s)" % (sys.argv[0], item.tourl()))
|
||||
|
||||
elif reload and item.channel == 'filmontv' and item.action == 'new_search':
|
||||
import xbmc
|
||||
platformtools.fakeVideo()
|
||||
return xbmc.executebuiltin("Container.Update(" + sys.argv[0] + "?" + item.tourl() + ")")
|
||||
else:
|
||||
# Checks if channel exists
|
||||
if os.path.isfile(os.path.join(config.get_runtime_path(), 'channels', item.channel + ".py")):
|
||||
CHANNELS = 'channels'
|
||||
# Special action for adding a movie to the library
|
||||
elif item.action == "add_pelicula_to_library":
|
||||
from core import videolibrarytools
|
||||
videolibrarytools.add_movie(item)
|
||||
|
||||
# Special action for adding a serie to the library
|
||||
elif item.action == "add_serie_to_library":
|
||||
channel = importChannel(item)
|
||||
from core import videolibrarytools
|
||||
videolibrarytools.add_tvshow(item, channel)
|
||||
|
||||
# Special action for adding a undefined to the library
|
||||
elif item.action == "add_to_library":
|
||||
channel = importChannel(item)
|
||||
from core import videolibrarytools
|
||||
videolibrarytools.add_to_videolibrary(item, channel)
|
||||
|
||||
# Special action for downloading all episodes from a serie
|
||||
elif item.action == "download_all_episodes":
|
||||
from specials import downloads
|
||||
item.action = item.extra
|
||||
del item.extra
|
||||
downloads.save_download(item)
|
||||
|
||||
# keymaptools special actions
|
||||
elif item.action == "keymap":
|
||||
from platformcode import keymaptools
|
||||
if item.open:
|
||||
return keymaptools.open_shortcut_menu()
|
||||
else:
|
||||
CHANNELS = 'specials'
|
||||
return keymaptools.set_key()
|
||||
elif item.action == "delete_key":
|
||||
from platformcode import keymaptools
|
||||
return keymaptools.delete_key()
|
||||
|
||||
channel_file = os.path.join(config.get_runtime_path(), CHANNELS, item.channel + ".py")
|
||||
# delete tmdb cache
|
||||
elif item.action == "script":
|
||||
from core import tmdb
|
||||
tmdb.clean_cache()
|
||||
platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(60011), time=2000, sound=False)
|
||||
|
||||
logger.debug("channel_file= " + channel_file + ' - ' + CHANNELS + ' - ' + item.channel)
|
||||
################################################
|
||||
|
||||
channel = None
|
||||
# For all other actions
|
||||
else: actions(item)
|
||||
|
||||
if os.path.exists(channel_file):
|
||||
try:
|
||||
channel = __import__('%s.%s' % (CHANNELS, item.channel), None, None, ['%s.%s' % (CHANNELS, item.channel)])
|
||||
except ImportError:
|
||||
exec("import " + CHANNELS + "." + item.channel + " as channel")
|
||||
|
||||
logger.info("Running channel %s | %s" % (channel.__name__, channel.__file__))
|
||||
|
||||
# Special play action
|
||||
if item.action == "play":
|
||||
# from core.support import dbg;dbg()
|
||||
# define la info para trakt
|
||||
try:
|
||||
from core import trakt_tools
|
||||
trakt_tools.set_trakt_info(item)
|
||||
except:
|
||||
pass
|
||||
logger.debug("item.action=%s" % item.action.upper())
|
||||
# logger.debug("item_toPlay: " + "\n" + item.tostring('\n'))
|
||||
|
||||
# First checks if channel has a "play" function
|
||||
if hasattr(channel, 'play'):
|
||||
logger.debug("Executing channel 'play' method")
|
||||
itemlist = channel.play(item)
|
||||
b_favourite = item.isFavourite
|
||||
# Play should return a list of playable URLS
|
||||
if len(itemlist) > 0 and isinstance(itemlist[0], Item):
|
||||
item = itemlist[0]
|
||||
if b_favourite:
|
||||
item.isFavourite = True
|
||||
platformtools.play_video(item)
|
||||
|
||||
# Permitir varias calidades desde play en el Channel
|
||||
elif len(itemlist) > 0 and isinstance(itemlist[0], list):
|
||||
item.video_urls = itemlist
|
||||
platformtools.play_video(item)
|
||||
|
||||
# If not, shows user an error message
|
||||
else:
|
||||
platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(60339))
|
||||
|
||||
# If player don't have a "play" function, not uses the standard play from platformtools
|
||||
else:
|
||||
logger.debug("Executing core 'play' method")
|
||||
platformtools.play_video(item)
|
||||
|
||||
# Special action for findvideos, where the plugin looks for known urls
|
||||
elif item.action == "findvideos":
|
||||
findvideos(item)
|
||||
# platformtools.render_items(itemlist, item)
|
||||
|
||||
# Special action for adding a movie to the library
|
||||
elif item.action == "add_pelicula_to_library":
|
||||
from core import videolibrarytools
|
||||
videolibrarytools.add_movie(item)
|
||||
|
||||
# Special action for adding a serie to the library
|
||||
elif item.action == "add_serie_to_library":
|
||||
from core import videolibrarytools
|
||||
videolibrarytools.add_tvshow(item, channel)
|
||||
|
||||
# Special action for adding a undefined to the library
|
||||
elif item.action == "add_to_library":
|
||||
from core import videolibrarytools
|
||||
videolibrarytools.add_to_videolibrary(item, channel)
|
||||
|
||||
# Special action for downloading all episodes from a serie
|
||||
elif item.action == "download_all_episodes":
|
||||
from specials import downloads
|
||||
item.action = item.extra
|
||||
del item.extra
|
||||
downloads.save_download(item)
|
||||
|
||||
# Special action for searching, first asks for the words then call the "search" function
|
||||
elif item.action == "search":
|
||||
if filetools.isfile(temp_search_file) and config.get_setting('videolibrary_kodi'):
|
||||
itemlist = []
|
||||
f = filetools.read(temp_search_file)
|
||||
strList = f.split(',')
|
||||
if strList[0] == '[V]' and strList[1] == item.channel:
|
||||
for it in strList:
|
||||
if it and it not in ['[V]', item.channel]:
|
||||
itemlist.append(Item().fromurl(it))
|
||||
filetools.write(temp_search_file, f[4:])
|
||||
return platformtools.render_items(itemlist, item)
|
||||
else:
|
||||
filetools.remove(temp_search_file)
|
||||
|
||||
logger.debug("item.action=%s" % item.action.upper())
|
||||
from core import channeltools
|
||||
|
||||
if config.get_setting('last_search'):
|
||||
last_search = channeltools.get_channel_setting('Last_searched', 'search', '')
|
||||
else:
|
||||
last_search = ''
|
||||
|
||||
search_text = platformtools.dialog_input(last_search)
|
||||
|
||||
if search_text is not None:
|
||||
channeltools.set_channel_setting('Last_searched', search_text, 'search')
|
||||
itemlist = new_search(item.clone(text=search_text), channel)
|
||||
else:
|
||||
return
|
||||
|
||||
platformtools.render_items(itemlist, item)
|
||||
|
||||
# For all other actions
|
||||
else:
|
||||
|
||||
logger.debug("Executing channel '%s' method" % item.action)
|
||||
itemlist = getattr(channel, item.action)(item)
|
||||
if config.get_setting('trakt_sync'):
|
||||
from core import trakt_tools
|
||||
token_auth = config.get_setting("token_trakt", "trakt")
|
||||
if not token_auth:
|
||||
trakt_tools.auth_trakt()
|
||||
else:
|
||||
import xbmc
|
||||
if not xbmc.getCondVisibility('System.HasAddon(script.trakt)') and config.get_setting('install_trakt'):
|
||||
trakt_tools.ask_install_script()
|
||||
itemlist = trakt_tools.trakt_check(itemlist)
|
||||
else:
|
||||
config.set_setting('install_trakt', True)
|
||||
|
||||
platformtools.render_items(itemlist, item)
|
||||
|
||||
|
||||
except WebErrorException as e:
|
||||
@@ -322,24 +163,25 @@ def run(item=None):
|
||||
platformtools.dialog_ok(
|
||||
config.get_localized_string(59985) % e.channel,
|
||||
config.get_localized_string(60013) % e.url)
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
from core import scrapertools
|
||||
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
patron = 'File "' + os.path.join(config.get_runtime_path(), "channels", "").replace("\\", "\\\\") + r'([^.]+)\.py"'
|
||||
patron = r'File "{}([^.]+)\.py"'.format(filetools.join(config.get_runtime_path(), 'channels', '').replace('\\', '\\\\'))
|
||||
Channel = scrapertools.find_single_match(traceback.format_exc(), patron)
|
||||
|
||||
if Channel or e.__class__ == logger.ChannelScraperException:
|
||||
if item.url:
|
||||
if platformtools.dialog_yesno(config.get_localized_string(60087) % Channel, config.get_localized_string(60014), nolabel='ok', yeslabel=config.get_localized_string(70739)):
|
||||
run(Item(action="open_browser", url=item.url))
|
||||
run(Item(action='open_browser', url=item.url))
|
||||
else:
|
||||
platformtools.dialog_ok(config.get_localized_string(60087) % Channel, config.get_localized_string(60014))
|
||||
else:
|
||||
if platformtools.dialog_yesno(config.get_localized_string(60038), config.get_localized_string(60015)):
|
||||
platformtools.itemlist_update(Item(channel="setting", action="report_menu"), True)
|
||||
platformtools.itemlist_update(Item(channel='setting', action='report_menu'), True)
|
||||
finally:
|
||||
# db need to be closed when not used, it will cause freezes
|
||||
from core import db
|
||||
@@ -357,95 +199,102 @@ def new_search(item, channel=None):
|
||||
writelist = item.channel
|
||||
for it in itemlist:
|
||||
writelist += ',' + it.tourl()
|
||||
filetools.write(temp_search_file, writelist)
|
||||
# filetools.write(temp_search_file, writelist)
|
||||
return itemlist
|
||||
|
||||
def set_search_temp(item):
|
||||
if filetools.isfile(temp_search_file) and config.get_setting('videolibrary_kodi'):
|
||||
f = '[V],' + filetools.read(temp_search_file)
|
||||
filetools.write(temp_search_file, f)
|
||||
|
||||
def reorder_itemlist(itemlist):
|
||||
def limitItemlist(itemlist):
|
||||
logger.debug()
|
||||
# logger.debug("Inlet itemlist size: %i" % len(itemlist))
|
||||
|
||||
new_list = []
|
||||
mod_list = []
|
||||
not_mod_list = []
|
||||
|
||||
modified = 0
|
||||
not_modified = 0
|
||||
|
||||
to_change = [[config.get_localized_string(60335), '[V]'], [config.get_localized_string(60336), '[D]']]
|
||||
|
||||
for item in itemlist:
|
||||
if not PY3:
|
||||
old_title = unicode(item.title, "utf8").lower().encode("utf8")
|
||||
else:
|
||||
old_title = item.title.lower()
|
||||
for before, after in to_change:
|
||||
if before in item.title:
|
||||
item.title = item.title.replace(before, after)
|
||||
break
|
||||
|
||||
if not PY3:
|
||||
new_title = unicode(item.title, "utf8").lower().encode("utf8")
|
||||
else:
|
||||
new_title = item.title.lower()
|
||||
if old_title != new_title:
|
||||
mod_list.append(item)
|
||||
modified += 1
|
||||
else:
|
||||
not_mod_list.append(item)
|
||||
not_modified += 1
|
||||
|
||||
# logger.debug("OLD: %s | NEW: %s" % (old_title, new_title))
|
||||
|
||||
new_list.extend(mod_list)
|
||||
new_list.extend(not_mod_list)
|
||||
|
||||
logger.debug("Modified Titles:%i |Unmodified:%i" % (modified, not_modified))
|
||||
|
||||
if len(new_list) == 0:
|
||||
new_list = itemlist
|
||||
|
||||
# logger.debug("Outlet itemlist size: %i" % len(new_list))
|
||||
return new_list
|
||||
|
||||
|
||||
def limit_itemlist(itemlist):
|
||||
logger.debug()
|
||||
# logger.debug("Inlet itemlist size: %i" % len(itemlist))
|
||||
|
||||
try:
|
||||
opt = config.get_setting("max_links", "videolibrary")
|
||||
if opt == 0:
|
||||
value = config.get_setting('max_links', 'videolibrary')
|
||||
if value == 0:
|
||||
new_list = itemlist
|
||||
else:
|
||||
i_max = 30 * opt
|
||||
new_list = itemlist[:i_max]
|
||||
|
||||
# logger.debug("Outlet itemlist size: %i" % len(new_list))
|
||||
new_list = itemlist[:value]
|
||||
return new_list
|
||||
except:
|
||||
return itemlist
|
||||
|
||||
|
||||
def findvideos(item):
|
||||
from core import db
|
||||
db['controls']['reopen'] = False
|
||||
db.close()
|
||||
logger.debug('Executing channel', item.channel, 'method', item.action)
|
||||
channel = platformtools.channelImport(item.channel)
|
||||
if not channel:
|
||||
logger.debug('Channel', item.channel, 'not exist!')
|
||||
return
|
||||
from core import servertools
|
||||
def makeItem():
|
||||
logger.debug()
|
||||
if sys.argv[2]:
|
||||
sp = sys.argv[2].split('&')
|
||||
url = sp[0]
|
||||
item = Item().fromurl(url)
|
||||
if len(sp) > 1:
|
||||
for e in sp[1:]:
|
||||
key, val = e.split('=')
|
||||
if val.lower() == 'false': val = False
|
||||
elif val.lower() == 'true': val = True
|
||||
item.__setattr__(key, val)
|
||||
# If no item, this is mainlist
|
||||
else:
|
||||
item = Item(channel='channelselector', action='getmainlist', viewmode='movie')
|
||||
|
||||
p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(60683))
|
||||
p_dialog.update(0)
|
||||
return item
|
||||
|
||||
|
||||
def showOnce():
|
||||
if not config.get_all_settings_addon():
|
||||
logger.error('corrupted settings.xml!!')
|
||||
settings_xml = filetools.join(config.get_data_path(), 'settings.xml')
|
||||
settings_bak = filetools.join(config.get_data_path(), 'settings.bak')
|
||||
if filetools.exists(settings_bak):
|
||||
filetools.copy(settings_bak, settings_xml, True)
|
||||
logger.info('restored settings.xml from backup')
|
||||
else:
|
||||
filetools.write(settings_xml, '<settings version="2">\n</settings>') # resetted settings
|
||||
else:
|
||||
from platformcode import xbmc_videolibrary
|
||||
xbmc_videolibrary.ask_set_content(silent=False)
|
||||
config.set_setting('show_once', True)
|
||||
|
||||
|
||||
def play(item):
|
||||
channel = importChannel(item)
|
||||
|
||||
# define info for trakt
|
||||
try:
|
||||
from core import trakt_tools
|
||||
trakt_tools.set_trakt_info(item)
|
||||
except:
|
||||
pass
|
||||
logger.debug('item.action=', item.action.upper())
|
||||
|
||||
# First checks if channel has a "play" function
|
||||
if hasattr(channel, 'play'):
|
||||
logger.debug('Executing channel "play" method')
|
||||
itemlist = channel.play(item)
|
||||
# Play should return a list of playable URLS
|
||||
if len(itemlist) > 0 and isinstance(itemlist[0], Item):
|
||||
item = itemlist[0]
|
||||
platformtools.play_video(item)
|
||||
|
||||
# Allow several qualities from Play in El Channel
|
||||
elif len(itemlist) > 0 and isinstance(itemlist[0], list):
|
||||
item.video_urls = itemlist
|
||||
platformtools.play_video(item)
|
||||
|
||||
# If not, shows user an error message
|
||||
else:
|
||||
platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(60339))
|
||||
|
||||
# If player don't have a "play" function, not uses the standard play from platformtools
|
||||
else:
|
||||
logger.debug('Executing core "play" method')
|
||||
platformtools.play_video(item)
|
||||
|
||||
|
||||
def findvideos(item, itemlist=[]):
|
||||
if not itemlist:
|
||||
logger.debug('Executing channel', item.channel, 'method', item.action)
|
||||
channel = importChannel(item)
|
||||
from core import servertools
|
||||
|
||||
p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(60683))
|
||||
p_dialog.update(0)
|
||||
|
||||
# First checks if channel has a "findvideos" function
|
||||
if hasattr(channel, 'findvideos'):
|
||||
itemlist = getattr(channel, item.action)(item)
|
||||
@@ -455,35 +304,85 @@ def findvideos(item):
|
||||
logger.debug('No channel "findvideos" method, executing core method')
|
||||
itemlist = servertools.find_video_items(item)
|
||||
|
||||
itemlist = limit_itemlist(itemlist)
|
||||
except:
|
||||
itemlist = []
|
||||
itemlist = limitItemlist(itemlist)
|
||||
|
||||
p_dialog.update(100)
|
||||
p_dialog.close()
|
||||
p_dialog.update(100)
|
||||
p_dialog.close()
|
||||
|
||||
serverlist = [s for s in itemlist if s.server]
|
||||
|
||||
if itemlist and not serverlist:
|
||||
platformtools.render_items(itemlist, item)
|
||||
if not serverlist:
|
||||
platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(60347))
|
||||
elif len(serverlist) == 1:
|
||||
run(serverlist[0].clone(no_return=True))
|
||||
# If there is only one server play it immediately
|
||||
play(itemlist[0].clone(no_return=True))
|
||||
else:
|
||||
platformtools.serverWindow(item, itemlist)
|
||||
|
||||
def play_from_library(item):
|
||||
"""
|
||||
The .strm files when played from kodi, this expects it to be a "playable" file so it cannot contain
|
||||
more items, at most a selection dialog can be placed.
|
||||
We solve this by "cheating kodi" and making him believe that something has been reproduced, so later by
|
||||
"Container.Update ()" we load the strm as if an item from inside the addon were treated, removing all
|
||||
the limitations and allowing to reproduce through the general function without having to create new methods to
|
||||
the video library.
|
||||
@type item: item
|
||||
@param item: item with information
|
||||
"""
|
||||
|
||||
def search(item):
|
||||
channel = importChannel(item)
|
||||
from core import channeltools
|
||||
|
||||
if config.get_setting('last_search'):
|
||||
last_search = channeltools.get_channel_setting('Last_searched', 'search', '')
|
||||
else:
|
||||
last_search = ''
|
||||
|
||||
search_text = platformtools.dialog_input(last_search)
|
||||
|
||||
if search_text is not None:
|
||||
channeltools.set_channel_setting('Last_searched', search_text, 'search')
|
||||
itemlist = new_search(item.clone(text=search_text), channel)
|
||||
else:
|
||||
return
|
||||
|
||||
platformtools.render_items(itemlist, item)
|
||||
|
||||
|
||||
def addToLibrary(item):
|
||||
channel = importChannel(item)
|
||||
from core import videolibrarytools
|
||||
videolibrarytools.add_to_videolibrary(item, channel)
|
||||
|
||||
|
||||
def importChannel(item):
|
||||
channel = platformtools.channelImport(item.channel)
|
||||
if not channel:
|
||||
logger.debug('Channel', item.channel, 'not exist!')
|
||||
return
|
||||
|
||||
logger.debug('Running channel', channel.__name__, '|', channel.__file__)
|
||||
return channel
|
||||
|
||||
|
||||
def actions(item):
|
||||
logger.debug('Executing channel', item.channel, 'method', item.action)
|
||||
channel = importChannel(item)
|
||||
itemlist = getattr(channel, item.action)(item)
|
||||
if type(itemlist) == list:
|
||||
if config.get_setting('trakt_sync'):
|
||||
from core import trakt_tools
|
||||
token_auth = config.get_setting('token_trakt', 'trakt')
|
||||
if not token_auth:
|
||||
trakt_tools.auth_trakt()
|
||||
else:
|
||||
import xbmc
|
||||
if not xbmc.getCondVisibility('System.HasAddon(script.trakt)') and config.get_setting('install_trakt'):
|
||||
trakt_tools.ask_install_script()
|
||||
itemlist = trakt_tools.trakt_check(itemlist)
|
||||
else:
|
||||
config.set_setting('install_trakt', True)
|
||||
|
||||
if len([s for s in itemlist if s.server]) > 0:
|
||||
findvideos(item, itemlist)
|
||||
else:
|
||||
platformtools.render_items(itemlist, item)
|
||||
|
||||
|
||||
def playFromLibrary(item):
|
||||
if not item.next_ep: platformtools.fakeVideo()
|
||||
item.action = item.next_action if item.next_action else 'findvideos'
|
||||
logger.debug('Executing channel', item.channel, 'method', item.action)
|
||||
return run(item)
|
||||
|
||||
|
||||
|
||||
@@ -1711,10 +1711,10 @@ def serverWindow(item, itemlist):
|
||||
ENTER = 7
|
||||
EXIT = 10
|
||||
BACKSPACE = 92
|
||||
prevent_busy()
|
||||
|
||||
class ServerWindow(xbmcgui.WindowXMLDialog):
|
||||
def start(self, item, itemlist):
|
||||
prevent_busy()
|
||||
self.itemlist = itemlist
|
||||
self.item = item
|
||||
self.servers = []
|
||||
@@ -1789,6 +1789,7 @@ def serverWindow(item, itemlist):
|
||||
|
||||
class ServerSkinWindow(xbmcgui.WindowXMLDialog):
|
||||
def start(self, item, itemlist):
|
||||
prevent_busy()
|
||||
self.item = item
|
||||
self.itemlist = itemlist
|
||||
self.selection = -1
|
||||
@@ -1833,13 +1834,14 @@ def serverWindow(item, itemlist):
|
||||
color = typo(' •', 'bold color 0x{}'.format(color)) if color else ''
|
||||
title = '{}{}{}'.format(videoitem.serverName, quality, color)
|
||||
else:
|
||||
logger.debug(videoitem)
|
||||
title = videoitem.title
|
||||
it = xbmcgui.ListItem(title)
|
||||
if videoitem.ch_name:
|
||||
it.setLabel2(videoitem.ch_name)
|
||||
else:
|
||||
elif not videoitem.action:
|
||||
it.setLabel2(videoitem.plot)
|
||||
else:
|
||||
it.setLabel2(videoitem.fulltitle)
|
||||
it.setArt({'thumb': videoitem.thumbnail})
|
||||
items.append(it)
|
||||
self.list.reset()
|
||||
|
||||
@@ -219,8 +219,11 @@ def find_file(hash):
|
||||
def elementum_actions(parameter, TorrentHash):
|
||||
elementum_setting, elementum_host, TorrentPath = setting()
|
||||
if elementum_setting:
|
||||
if parameter == 'delete': monitor_update(TorrentPath, TorrentHash, remove=True)
|
||||
requests.get('%s/%s/%s' %(elementum_host, parameter, TorrentHash))
|
||||
try:
|
||||
if parameter == 'delete': monitor_update(TorrentPath, TorrentHash, remove=True)
|
||||
requests.get('%s/%s/%s' %(elementum_host, parameter, TorrentHash))
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def process_filename(filename, Title, ext=True):
|
||||
|
||||
Reference in New Issue
Block a user