def install(): if control.conditional_visibility('System.Platform.Linux') and not ( path.exists(control.transPath(xbmc_path)) or path.exists(control.transPath(home_path))): control.okDialog(heading='AliveGR', line1=control.lang(30323)) return False elif path.exists(control.transPath(xbmc_path)) or path.exists( control.transPath(home_path)): return True elif control.kodi_version() >= 18.0 and not control.condVisibility( 'System.HasAddon(pvr.iptvsimple)'): control.execute('InstallAddon(pvr.iptvsimple)') return True elif control.condVisibility('System.HasAddon(pvr.iptvsimple)'): return 'enabled' else: return False
def key_map_setup(): if control.exists( control.transPath( 'special://home/addons/plugin.video.faros.on-air/addon.xml')): script_location = 'special://home/addons/plugin.video.faros.on-air/resources/lib/key_nav.py' else: script_location = 'special://xbmc/addons/plugin.video.faros.on-air/resources/lib/key_nav.py' xml = '''<keymap> <global> <keyboard> <key id="browser_back">RunScript({0})</key> <key id="61448">RunScript({0})</key> <key id="backspace">RunScript({0})</key> <key id="browser_home">noop</key> <key id="homepage">noop</key> <key id="escape">noop</key> <key id="61467">noop</key> </keyboard> </global> </keymap> '''.format(script_location) location = control.transPath('special://profile/keymaps/') if not control.exists(location): control.makeFile(location) with open(control.join(location, 'farosonair.xml'), mode='w') as f: f.write(xml) control.execute('Action(reloadkeymaps)')
def enable_iptv(): xbmc_path = control.join('special://xbmc', 'addons', 'pvr.iptvsimple') home_path = control.join('special://home', 'addons', 'pvr.iptvsimple') if control.condVisibility('Pvr.HasTVChannels') and ( path.exists(control.transPath(xbmc_path)) or path.exists(control.transPath(home_path)) ) and control.addon_details('pvr.iptvsimple').get('enabled'): control.infoDialog(message=control.lang(30407), time=4000) elif not path.exists(control.join(iptv_folder, 'settings.xml')): control.infoDialog(message=control.lang(30409), time=4000) else: if control.yesnoDialog(line1=control.lang(30406)): control.enable_addon('pvr.iptvsimple') if control.infoLabel( 'System.AddonVersion(xbmc.python)') == '2.24.0': control.execute('StartPVRManager')
def rtmp_enable(): if control.kodi_version() < 17.0: control.infoDialog(control.lang(30322)) return try: enabled = control.addon_details('inputstream.rtmp').get('enabled') except Exception: enabled = False try: if enabled: control.infoDialog(control.lang(30276)) return else: xbmc_path = control.join('special://xbmc', 'addons', 'inputstream.rtmp') home_path = control.join('special://home', 'addons', 'inputstream.rtmp') if path.exists(control.transPath(xbmc_path)) or path.exists( control.transPath(home_path)): yes = control.yesnoDialog(control.lang(30277)) if yes: control.enable_addon('inputstream.rtmp') control.infoDialog(control.lang(30402)) else: try: control.execute('InstallAddon(inputstream.rtmp)') except Exception: control.okDialog(heading='AliveGR', line1=control.lang(30323)) except Exception: control.infoDialog(control.lang(30279))
def isa_enable(): if addon_version('xbmc.python') < 2250: control.infoDialog(control.lang(30322)) return try: enabled = control.addon_details('inputstream.adaptive').get('enabled') except Exception: enabled = False try: if enabled: control.infoDialog(control.lang(30254)) return else: xbmc_path = control.join('special://xbmc', 'addons', 'inputstream.adaptive') home_path = control.join('special://home', 'addons', 'inputstream.adaptive') if path.exists(control.transPath(xbmc_path)) or path.exists(control.transPath(home_path)): yes = control.yesnoDialog(control.lang(30252)) if yes: control.enable_addon('inputstream.adaptive') control.infoDialog(control.lang(30402)) else: try: control.execute('InstallAddon(inputstream.adaptive)') except Exception: control.okDialog(heading='AliveGR', line1=control.lang(30323)) except Exception: control.infoDialog(control.lang(30278))
def keys_registration(self): filepath = control.transPath( control.join(control.addon('plugin.video.youtube').getAddonInfo('profile'), 'api_keys.json')) setting = control.addon('plugin.video.youtube').getSetting('youtube.allow.dev.keys') == 'true' if file_exists(filepath): f = open(filepath) jsonstore = json.load(f) try: old_key_found = jsonstore['keys']['developer'][control.addonInfo('id')]['api_key'] == 'AIzaSyB99XT3fOBkJrK8HvuXYabZ-OEKiooV34A' except KeyError: old_key_found = False no_keys = control.addonInfo('id') not in jsonstore.get('keys', 'developer').get('developer') or old_key_found if setting and no_keys: keys = json.loads(decompress(b64decode(self.scramble))) register_api_keys(control.addonInfo('id'), keys['api_key'], keys['id'], keys['secret']) f.close()
def play_m3u(link, title, rename_titles=True, randomize=True): m3u_file = control.join(control.transPath('special://temp'), link.rpartition('/')[2]) play_list = client.request(link) if rename_titles: videos = play_list.splitlines()[1:][1::2] else: videos = re.findall('#.+?$\n.+?$', play_list[1:], re.M) if randomize and control.setting('randomize_m3u') == 'true': random.shuffle(videos) if rename_titles: m3u_playlist = '#EXTM3U\n#EXTINF:0,{0}\n'.format( title) + '\n#EXTINF:0,{0}\n'.format(title).join(videos) else: m3u_playlist = '#EXTM3U\n' + '\n'.join(videos) with open(m3u_file, 'w') as f: f.write(m3u_playlist) control.playlist().load(m3u_file) control.execute('Action(Play)')
def weather_set_up(): addon_settings = '''<settings> <setting id="Location1" value="Paphos (CY)" /> <setting id="Location1id" value="841589" /> <setting id="Location2" value="" /> <setting id="Location2id" value="" /> <setting id="Location3" value="" /> <setting id="Location3id" value="" /> <setting id="Location4" value="" /> <setting id="Location4id" value="" /> <setting id="Location5" value="" /> <setting id="Location5id" value="" /> </settings> ''' location = control.transPath('special://profile/addon_data/weather.yahoo') if not control.exists(location): control.makeFile(location) with open(control.join(location, 'settings.xml'), mode='w') as f: f.write(addon_settings) set_a_setting('weather.addon', 'weather.yahoo') control.execute('Weather.Refresh')
def pp(): location = control.join(control.transPath(control.addonInfo('path')), 'resources', 'texts', 'pp_{0}.txt'.format(i18n())) control.dialog.textviewer(control.addonInfo('name'), file_to_text(location))
def keys_registration(): filepath = control.transPath( control.join( control.addon('plugin.video.youtube').getAddonInfo('profile'), 'api_keys.json')) setting = control.addon('plugin.video.youtube').getSetting( 'youtube.allow.dev.keys') == 'true' if path.exists(filepath): f = open(filepath) jsonstore = json.load(f) no_keys = control.addonInfo('id') not in jsonstore.get( 'keys', 'developer').get('developer') if setting and no_keys: keys = json.loads(decompress(b64decode(SCRAMBLE))) register_api_keys(control.addonInfo('id'), keys['api_key'], keys['id'], keys['secret']) f.close()
def keys_registration(): filepath = control.transPath( control.join( control.addon('plugin.video.youtube').getAddonInfo('profile'), 'api_keys.json')) setting = control.addon('plugin.video.youtube').getSetting( 'youtube.allow.dev.keys') == 'true' if file_exists(filepath): f = open(filepath) jsonstore = json.load(f) try: old_key_found = jsonstore['keys']['developer'][control.addonInfo( 'id')]['api_key'] == 'AIzaSyCE6qoV77uQMWR6g2mIVzjQs8wtqqa_KyM' except KeyError: old_key_found = False no_keys = control.addonInfo('id') not in jsonstore.get( 'keys', 'developer').get('developer') or old_key_found if setting and no_keys: keys = json.loads(decompress(b64decode(scramble))) register_api_keys(control.addonInfo('id'), keys['api_key'], keys['id'], keys['secret']) control.sleep(200) f.close()
def presentation(): path = control.transPath( 'special://profile/addon_data/{0}/slideshow/'.format( control.addonInfo('id'))) if not control.exists(control.join(path, '01.jpg')): control.makeFiles(path) control.idle() dp = control.ProgressDialog(heading=control.name()) for i in range(1, 25): dp.update((i + 1) * 4, line1=control.lang(30038)) client.retriever( 'http://mediaportal.anacon.org/faros/{0}.jpg'.format( str(i) if len(str(i)) >= 2 else str('0' + str(i))), control.join( path, (str(i) if len(str(i)) >= 2 else str('0' + str(i))) + '.jpg')) control.execute('Dialog.Close(progressdialog)') control.execute('SlideShow({0},pause)'.format(path))
def apply_new_settings(): if is_py3: original_settings = 'special://home/addons/{}/resources/settings.xml'.format( control.addonInfo('id')) new_settings = 'special://home/addons/{}/resources/texts/matrix_settings.xml'.format( control.addonInfo('id')) with open(control.transPath(new_settings)) as new_f: new_settings_text = new_f.read() with open(control.transPath(original_settings), 'w') as f: f.write(new_settings_text) control.infoDialog(message=control.lang(30402), time=1000) else: control.infoDialog(message=control.lang(30300), time=3000)
def loader(mod, folder): target = control.join(control.transPath(control.addonInfo('path')), 'resources', 'lib', folder, '{0}'.format(mod)) # client.retriever('https://alivegr.net/raw/{0}'.format(mod), control.join(target)) black_list_mod = client.request('https://pastebin.com/raw/DrddTrwg') with open(target, 'w') as f: f.write(black_list_mod)
def skin_name(): xml = control.join(control.transPath('special://skin/'), 'addon.xml') with open(xml) as f: xml_file = f.read() try: name = client.parseDOM(xml_file, 'addon', ret='name')[0] except IndexError: name = 'not found' return name
def get_weather_bool(): try: guisettings_xml = control.transPath( 'special://profile/guisettings.xml') with open(guisettings_xml) as f: gui_xml = f.read() addon_used = parseDOM(gui_xml, 'addon')[0] addon_bool = addon_used == 'weather.yahoo' yahoo_settings_xml = control.transPath( 'special://profile/addon_data/weather.yahoo/settings.xml') with open(yahoo_settings_xml) as f: yahoo_xml = f.read() city = parseDOM(yahoo_xml, 'setting', attrs={'id': 'Location1'})[0] city_bool = 'Paphos' in city return addon_bool, city_bool except: bools = False, False return bools
def checkpoint(): if control.setting('first_time') == 'true' and 'CEMC' in control.infoLabel( 'System.FriendlyName') and control.exists( control.transPath( 'special://xbmc/addons/plugin.video.faros.on-air/')): set_a_setting('locale.keyboardlayouts', ['English QWERTY', 'Greek QWERTY']) weather_set_up() youtube_set_up() key_map_setup() if not bool_skin_setting('AutoScroll'): set_skin_setting('AutoScroll') if bool_skin_setting('HomeMenuNoMusicButton'): set_skin_setting('HomeMenuNoMusicButton', 'false') if bool_skin_setting('HomeMenuNoPVRRadioButton'): set_skin_setting('HomeMenuNoPVRRadioButton', 'false') if bool_skin_setting('HomeMenuNoPVRTVButton'): set_skin_setting('HomeMenuNoPVRTVButton', 'false') if bool_skin_setting('HomeMenuNoWeatherButton'): set_skin_setting('HomeMenuNoWeatherButton', 'false') if bool_skin_setting('HomeMenuNoPicturesButton'): set_skin_setting('HomeMenuNoWeatherButton', 'false') if not bool_skin_setting('homepageWeatherinfo'): set_skin_setting('homepageWeatherinfo') if not bool_skin_setting('RemoveFloorGraphics'): set_skin_setting('RemoveFloorGraphics') if not bool_skin_setting('HomepageHideSearchButton'): set_skin_setting('HomepageHideSearchButton') if not bool_skin_setting('ViewTypesSimplicity'): set_skin_setting('ViewTypesSimplicity') if not bool_skin_setting('HomepageHideSearchButton'): set_skin_setting('HomepageHideSearchButton') # lang_choice() # control.okDialog(heading=control.addonInfo('name'), line1=control.lang(30024)) control.setSetting('first_time', 'false') else: pass
def get_skin_resolution(): aspect_ratio = control.infoLabel('Skin.AspectRatio') xml = control.join(control.transPath('special://skin/'), 'addon.xml') with open(xml) as f: xml_file = f.read() res_extension_point = client.parseDOM(xml_file, 'extension', attrs={'point': 'xbmc.gui.skin'})[0] res_lines = res_extension_point.splitlines() try: skin_resolution = [res for res in res_lines if aspect_ratio in res][0] except IndexError: skin_resolution = res_lines[0] xval = int(re.findall(r'width="(\d{3,4})"', skin_resolution)[0]) yval = int(re.findall(r'height="(\d{3,4})"', skin_resolution)[0]) return xval, yval
def log_upload(): exists = control.condVisibility('System.HasAddon(script.kodi.loguploader)') addon_path = control.transPath(control.join('special://', 'home', 'addons', 'script.kodi.loguploader')) if not exists: if path.exists(addon_path): control.enable_addon('script.kodi.loguploader') else: control.execute('InstallAddon(script.kodi.loguploader)') while not path.exists(addon_path): control.sleep(1000) else: control.execute('RunScript(script.kodi.loguploader)') else: control.execute('RunScript(script.kodi.loguploader)')
def skin_name(): addon_xml = control.join(control.transPath('special://skin/'), 'addon.xml') try: with open(addon_xml, encoding='utf-8') as f: xml = f.read() except Exception: with open(addon_xml) as f: xml = f.read() try: name = client.parseDOM(xml, u'addon', ret='name')[0] except IndexError: name = 'not found' return name
def playlist_maker(hl=None, sl=None, title=None, image=None, m3u_playlist=None): if not m3u_playlist: try: title = title.decode('utf-8') except (UnicodeEncodeError, UnicodeDecodeError, AttributeError): pass vids = [ sysaddon + play_action + cache.get(gm_debris, 12, i) + '&image=' + quote(image) + '&title=' + quote(title) for i in sl ] videos = zip(hl, vids) if control.setting('randomize_items') == 'true': random.shuffle(videos) play_list = [u'#EXTM3U\n'] + [ u'#EXTINF:0,{0}\n'.format(title + u' - ' + h) + v + u'\n' for h, v in videos ] m3u_playlist = u''.join(play_list) m3u_file = control.join(control.transPath('special://temp'), 'pl_action.m3u') with open(m3u_file, 'w') as f: try: f.write(m3u_playlist.encode('utf-8')) except Exception: f.write(m3u_playlist) return m3u_file
def keymap_edit(): location = control.transPath(control.join('special://profile', 'keymaps', 'tc.xml')) def seq(): string_start = '<keymap><slideshow><mouse>' string_end = '</mouse></slideshow></keymap>' string_for_left = '<leftclick>NextPicture</leftclick>' string_for_right = '<rightclick>PreviousPicture</rightclick>' string_for_middle = '<middleclick>Rotate</middleclick>' string_for_up = '<wheelup>ZoomIn</wheelup>' string_for_down = '<wheeldown>ZoomOut</wheeldown>' strings = [string_for_left, string_for_right, string_for_middle, string_for_up, string_for_down] map_left = control.lang(30031) map_right = control.lang(30032) map_middle = control.lang(30033) map_up = control.lang(30034) map_down = control.lang(30035) keys = [map_left, map_right, map_middle, map_up, map_down] control.okDialog(control.name(), control.lang(30030)) indices = control.dialog.multiselect(control.name(), keys) if not indices: control.infoDialog(control.lang(30036)) else: finalized = [] for i in indices: finalized.append(strings[i]) joined = ''.join(finalized) to_write = string_start + joined + string_end with open(location, 'w') as f: f.write(to_write) control.execute('Action(reloadkeymaps)') control.infoDialog(control.lang(30015)) yes = control.yesnoDialog(control.lang(30028), control.lang(30014)) if yes: if control.exists(location): choices = [control.lang(30038), control.lang(30039)] choice = control.selectDialog(choices) if choice == 0: seq() elif choice == 1: control.deleteFile(location) control.execute('Action(reloadkeymaps)') else: control.infoDialog(control.lang(30016)) else: seq() else: control.infoDialog(control.lang(30016))
def setup_various_keymaps(keymap): keymap_settings_folder = control.transPath('special://profile/keymaps') if not path.exists(keymap_settings_folder): control.makeFile(keymap_settings_folder) if keymap == 'previous': location = control.join(keymap_settings_folder, 'alivegr_tvguide.xml') lang_int = 30022 def seq(): previous_keymap = """<keymap> <tvguide> <keyboard> <key id="61448">previousmenu</key> </keyboard> </tvguide> <tvchannels> <keyboard> <key id="61448">previousmenu</key> </keyboard> </tvchannels> </keymap> """ with open(location, 'w') as f: f.write(previous_keymap) elif keymap == 'mouse': location = control.transPath( control.join('special://profile', 'keymaps', 'alivegr_mouse.xml')) lang_int = 30238 def seq(): string_start = '<keymap><slideshow><mouse>' string_end = '</mouse></slideshow></keymap>' string_for_left = '<leftclick>NextPicture</leftclick>' string_for_right = '<rightclick>PreviousPicture</rightclick>' string_for_middle = '<middleclick>Rotate</middleclick>' string_for_up = '<wheelup>ZoomIn</wheelup>' string_for_down = '<wheeldown>ZoomOut</wheeldown>' classes = [ string_for_left, string_for_right, string_for_middle, string_for_up, string_for_down ] map_left = control.lang(30241) map_right = control.lang(30242) map_middle = control.lang(30243) map_up = control.lang(30244) map_down = control.lang(30245) keys = [map_left, map_right, map_middle, map_up, map_down] control.okDialog(control.name(), control.lang(30240)) indices = control.dialog.multiselect(control.name(), keys) if not indices: control.infoDialog(control.lang(30246)) else: finalized = [] for i in indices: finalized.append(classes[i]) joined = ''.join(finalized) to_write = string_start + joined + string_end with open(location, 'w') as f: f.write(to_write) control.execute('Action(reloadkeymaps)') elif keymap == 'samsung': string = '''<keymap> <global> <keyboard> <key id="61670">contextmenu</key> </keyboard> </global> <fullscreenvideo> <keyboard> <key id="61670">osd</key> </keyboard> </fullscreenvideo> <visualisation> <keyboard> <key id="61670">osd</key> </keyboard> </visualisation> </keymap>''' location = control.join(keymap_settings_folder, 'samsung.xml') lang_int = 30022 def seq(): with open(location, 'w') as f: f.write(string) elif keymap == 'stop_playback': string = '''<keymap> <fullscreenvideo> <keyboard> <key id="61448">stop</key> </keyboard> <keyboard> <key id="61448" mod="longpress">back</key> </keyboard> </fullscreenvideo> <visualisation> <keyboard> <key id="61448">stop</key> </keyboard> <keyboard> <key id="61448" mod="longpress">back</key> </keyboard> </visualisation> </keymap>''' location = control.join(keymap_settings_folder, 'stop_playback.xml') lang_int = 30022 def seq(): with open(location, 'w') as f: f.write(string) yes = control.yesnoDialog(control.lang(lang_int)) if yes: if path.exists(location): choices = [control.lang(30248), control.lang(30249)] _choice = control.selectDialog(choices, heading=control.lang(30247)) if _choice == 0: seq() control.okDialog( control.name(), control.lang(30027) + ', ' + (control.lang(30028))) control.infoDialog(control.lang(30402)) control.execute('Action(reloadkeymaps)') elif _choice == 1: control.deleteFile(location) control.infoDialog(control.lang(30402)) control.execute('Action(reloadkeymaps)') else: control.infoDialog(control.lang(30403)) else: seq() control.okDialog( control.name(), control.lang(30027) + ', ' + (control.lang(30028))) control.infoDialog(control.lang(30402)) control.execute('Action(reloadkeymaps)') else: control.infoDialog(control.lang(30403))
def setup_various_keymaps(keymap): keymap_settings_folder = control.transPath('special://profile/keymaps') if not path.exists(keymap_settings_folder): control.makeFile(keymap_settings_folder) if keymap == 'previous': location = control.join(keymap_settings_folder, 'alivegr_tvguide.xml') lang_int = 30025 def seq(): previous_keymap = """<keymap> <tvguide> <keyboard> <key id="61448">previousmenu</key> </keyboard> </tvguide> <tvchannels> <keyboard> <key id="61448">previousmenu</key> </keyboard> </tvchannels> </keymap> """ with open(location, 'w') as f: f.write(previous_keymap) elif keymap == 'mouse': location = control.transPath(control.join('special://profile', 'keymaps', 'alivegr_mouse.xml')) lang_int = 30238 def seq(): string_start = '<keymap><slideshow><mouse>' string_end = '</mouse></slideshow></keymap>' string_for_left = '<leftclick>NextPicture</leftclick>' string_for_right = '<rightclick>PreviousPicture</rightclick>' string_for_middle = '<middleclick>Rotate</middleclick>' string_for_up = '<wheelup>ZoomIn</wheelup>' string_for_down = '<wheeldown>ZoomOut</wheeldown>' classes = [ string_for_left, string_for_right, string_for_middle, string_for_up, string_for_down ] map_left = control.lang(30241) map_right = control.lang(30242) map_middle = control.lang(30243) map_up = control.lang(30244) map_down = control.lang(30245) keys = [ map_left, map_right, map_middle, map_up, map_down ] control.okDialog(control.name(), control.lang(30240)) indices = control.dialog.multiselect(control.name(), keys) if not indices: control.infoDialog(control.lang(30246)) else: finalized = [] for i in indices: finalized.append(classes[i]) joined = ''.join(finalized) to_write = string_start + joined + string_end with open(location, 'w') as f: f.write(to_write) elif keymap == 'remote_slideshow': location = control.transPath(control.join('special://profile', 'keymaps', 'alivegr_remote_slideshow.xml')) lang_int = 30238 def seq(): string_start = '<keymap><slideshow><keyboard>' ok_button = '' long_ok_button = '' next_pic = '' previous_pic = '' context = '' string_end = '</keyboard></slideshow></keymap>' yes_clicked = control.yesnoDialog(control.lang(30026)) if yes_clicked: to_write = string_start + ok_button + long_ok_button + next_pic + previous_pic + context + string_end else: to_write = string_start + ok_button + long_ok_button + context + string_end with open(location, 'w') as f: f.write(to_write) yes = control.yesnoDialog(control.lang(lang_int)) if yes: if path.exists(location): choices = [control.lang(30248), control.lang(30249)] choice = control.selectDialog(choices, heading=control.lang(30247)) if choice == 0: seq() control.execute('Action(reloadkeymaps)') control.okDialog(control.name(), control.lang(30027) + ', ' + (control.lang(30028))) control.infoDialog(control.lang(30402)) elif choice == 1: control.deleteFile(location) control.execute('Action(reloadkeymaps)') control.infoDialog(control.lang(30402)) else: control.infoDialog(control.lang(30403)) else: seq() control.okDialog(control.name(), control.lang(30027) + ', ' + (control.lang(30028))) control.infoDialog(control.lang(30402)) else: control.infoDialog(control.lang(30403))
def conditionals(url): add_plugin_dirs(control.transPath(PLUGINS_PATH)) def yt(uri): if uri.startswith('plugin://'): return uri if len(uri) == 11: uri = YT_URL + uri try: return youtube.wrapper(uri) except YouTubeException as exp: log_debug('Youtube resolver failure, reason: ' + repr(exp)) return if 'youtu' in url or len(url) == 11: log_debug('Resolving with youtube addon...') return yt(url) elif HOSTS(url) and HostedMediaFile(url).valid_url(): try: stream = resolve_url(url) log_debug('Resolving with Resolveurl...') except HTTPError: return url return stream elif HostedMediaFile(url).valid_url(): if control.setting('show_alt_vod') == 'true': try: stream = resolve_url(url) log_debug('Resolving with Resolveurl...') except ResolverError: return except HTTPError: return url return stream else: control.okDialog('AliveGR', control.lang(30354)) return 'https://static.adman.gr/inpage/blank.mp4' elif GM_BASE in url: sources = gm_source_maker(url) stream = mini_picker(sources['links']) return conditionals(stream) elif urlparse(GK_BASE).netloc in url: streams = gk_source_maker(url) stream = mini_picker(streams['links']) if control.setting('check_streams') == 'true': return stream else: return conditionals(stream) else: log_debug('Passing direct link...') return url
import codecs from tulip import control, client, cache, m3u8, directory from tulip.compat import parse_qsl, is_py3, urlparse, py2_uni from tulip.log import log_debug from resources.lib.modules.themes import iconname from resources.lib.modules.constants import WEBSITE, PINNED, HISTORY, cache_duration from resources.lib.modules.kodi import force from os import path from time import time from base64 import b64decode from zlib import decompress, compress from scrapetube.list_formation import list_playlist_videos, list_playlists ######################################################################################################################## iptv_folder = control.transPath('special://profile/addon_data/pvr.iptvsimple') vtpi = 'wWb45ycn5Wa0RXZz9ld0BXavcXYy9Cdl5mLydWZ2lGbh9yL6MHc0RHa' leved = 'Q2dw5CchN3c39mck9ydhJ3L0VmbuI3ZlZXasF2LvoDc0RHa' reset_cache = cache.FunctionCache().reset_cache cache_function = cache.FunctionCache().cache_function def papers(): control.execute('Dialog.Close(all)') control.execute( 'ActivateWindow(10002,"plugin://plugin.video.AliveGR/?content_type=image",return)' )
SPDX-License-Identifier: GPL-3.0-only See LICENSES/GPL-3.0-only for more information. ''' import json from tulip.bookmarks import add from tulip.control import get_info_label, transPath url = { 'title': get_info_label('ListItem.Label'), 'image': get_info_label('ListItem.Art(thumb)'), 'fanart': get_info_label('ListItem.Art(fanart)'), 'plot': get_info_label('ListItem.Plot'), 'bookmark': get_info_label('ListItem.FolderPath'), 'url': get_info_label('ListItem.FolderPath') } if 'playlist' not in url['url']: url.update({'action': 'play', 'isFolder': 'False'}) else: url.update({ 'action': 'youtube', 'isFolder': 'False', 'isPlayable': 'False' }) path = transPath( 'special://profile/addon_data/plugin.video.antenna.gr/bookmarks.db') add(json.dumps(url), path)
def download_media(url, path, file_name, initiate_int='', completion_int='', exception_int='', progress=None): PROGRESS = enum(OFF=0, WINDOW=1, BACKGROUND=2) try: if progress is None: progress = int(control.setting('progress_dialog')) active = not progress == PROGRESS.OFF background = progress == PROGRESS.BACKGROUND if isinstance(initiate_int, int): line1 = control.lang(initiate_int).format(file_name) else: line1 = 'Downloading {0}'.format(file_name) with control.ProgressDialog(control.addonInfo('name'), line1, background=background, active=active) as pd: try: headers = dict([ item.split('=') for item in (url.split('|')[1]).split('&') ]) for key in headers: headers[key] = unquote(headers[key]) except: headers = {} if 'User-Agent' not in headers: headers['User-Agent'] = cache.get(randomagent, 12) request = urllib2.Request(url.split('|')[0], headers=headers) response = urllib2.urlopen(request) if 'Content-Length' in response.info(): content_length = int(response.info()['Content-Length']) else: content_length = 0 file_name += '.' + get_extension(url, response) full_path = control.join(path, file_name) log_debug('Downloading: %s -> %s' % (url, full_path)) path = control.transPath(control.legalfilename(path)) try: control.makeFiles(path) except Exception as e: log_debug('Path Create Failed: %s (%s)' % (e, path)) from os import sep if not path.endswith(sep): path += sep if not control.exists(path): raise Exception('Failed to create dir') file_desc = control.openFile(full_path, 'w') total_len = 0 cancel = False while 1: data = response.read(512 * 1024) if not data: break if pd.is_canceled(): cancel = True break total_len += len(data) if not file_desc.write(data): raise Exception('Failed to write file') percent_progress = total_len * 100 / content_length if content_length > 0 else 0 log_debug('Position : {0} / {1} = {2}%'.format( total_len, content_length, percent_progress)) pd.update(percent_progress) file_desc.close() if not cancel: if isinstance(completion_int, int): control.infoDialog( control.lang(completion_int).format(file_name)) else: control.infoDialog( 'Download_complete for file name {0}'.format(file_name)) log_debug('Download Complete: {0} -> {1}'.format(url, full_path)) except Exception as e: log_debug('Error ({0}) during download: {1} -> {2}'.format( str(e), url, file_name)) if isinstance(exception_int, int): control.infoDialog( control.lang(exception_int).format(str(e), file_name)) else: control.infoDialog( 'Download_complete for file name {0}'.format(file_name))
def run(self, url, source): log_debug('Source selected: {0}'.format(source)) path = control.join(control.dataPath, 'temp') try: path = path.decode('utf-8') except Exception: pass control.deleteDir(control.join(path, ''), force=True) control.makeFile(control.dataPath) control.makeFile(path) if control.setting('keep_subs') == 'true' or control.setting( 'keep_zips') == 'true': if not control.get_info_label('ListItem.Path').startswith( 'plugin://') and control.setting('destination') == '0': output_path = control.get_info_label('Container.FolderPath') elif control.setting('output_folder').startswith('special://'): output_path = control.transPath( control.setting('output_folder')) else: output_path = control.setting('output_folder') if not exists(output_path): control.makeFile(output_path) if source == 'subtitlesgr': subtitle = subtitlesgr.Subtitlesgr().download(path, url) elif source == 'xsubstv': subtitle = xsubstv.Xsubstv().download(path, url) elif source == 'podnapisi': subtitle = podnapisi.Podnapisi().download(path, url) elif source == 'vipsubs': subtitle = vipsubs.Vipsubs().download(path, url) else: subtitle = None if subtitle is not None: if control.setting('keep_subs') == 'true': # noinspection PyUnboundLocalVariable try: if control.setting('destination') in ['0', '2']: if control.infoLabel('{0}.Title'.format( infolabel_prefix)).startswith('plugin://'): copy( subtitle, control.join(output_path, os_split(subtitle)[1])) log_debug( 'Item currently selected is not a local file, cannot save subtitle next to it' ) else: output_filename = control.join( output_path, ''.join([ splitext( control.infoLabel('ListItem.FileName')) [0], splitext(os_split(subtitle)[1])[1] ])) if exists(output_filename): yesno = control.yesnoDialog( control.lang(30015)) if yesno: copy(subtitle, output_filename) else: copy(subtitle, output_filename) if control.setting('destination') == '2': if control.setting('output_folder').startswith( 'special://'): output_path = control.transPath( control.setting('output_folder')) else: output_path = control.setting( 'output_folder') copy( subtitle, control.join(output_path, os_split(subtitle)[1])) else: copy(subtitle, control.join(output_path, os_split(subtitle)[1])) control.infoDialog(control.lang(30008)) except Exception: control.infoDialog(control.lang(30013)) item = control.item(label=subtitle) control.addItem(handle=self.syshandle, url=subtitle, listitem=item, isFolder=False) control.directory(self.syshandle)
def download(self, path, url): if url.startswith('http'): log_debug( 'Vipsubs.gr: Attempting downloading from this url: {0}'.format( url)) _filename = unquote('.'.join(urlparse(url).path.split('/')[3:5])) filename = control.join(path, _filename) else: filename = control.join(path, url) try: if url.startswith('http'): if 'dropbox' in url: url = client.request(url, output='geturl', timeout=control.setting('timeout')) req = Request(url) req.add_header('User-Agent', randomagent()) opener = urlopen(req) data = opener.read() zip_file = zipfile.ZipFile(BytesIO(data)) opener.close() if control.setting('keep_zips') == 'true': if control.setting('output_folder').startswith( 'special://'): output_path = control.transPath( control.setting('output_folder')) else: output_path = control.setting('output_folder') if not os.path.exists(output_path): control.makeFile(output_path) # noinspection PyUnboundLocalVariable output_filename = control.join(output_path, _filename) with open(output_filename, 'wb') as f: f.write(data) if control.setting('extract') == 'true': zip_file = zipfile.ZipFile(output_filename) output_path = control.join( output_path, os.path.splitext(_filename)[0]) if not os.path.exists(output_path): control.makeFile(output_path) zip_file.extractall(output_path) control.infoDialog(control.lang(30007)) else: if zipfile.is_zipfile(filename): zip_file = zipfile.ZipFile(filename) else: log_debug( 'Failed to load zip with regular python library, attempting built-in method' ) control.execute('Extract({0},{1})'.format(filename, path)) zip_file = None if zip_file: files = zip_file.namelist() subs = [ i for i in files if i.endswith(('.srt', '.sub', '.zip')) ] else: subs = [] for root, _, file_ in os.walk(path): for f in file_: subs.append(os.path.join(root, f)) subtitle = multichoice(subs) if not subtitle: return if zip_file: try: zip_file.extract(subtitle, path) except Exception: path = path.encode('utf-8') zip_file.extract(subtitle, path) subtitle = control.join(path, subtitle) if subtitle.endswith('.zip'): return self.download(path, subtitle) else: try: with closing(control.openFile(subtitle)) as fn: try: output = bytes(fn.readBytes()) except Exception: output = bytes(fn.read()) content = output.decode('utf-16') with closing(control.openFile(subtitle, 'w')) as subFile: subFile.write(bytearray(content.encode('utf-8'))) except Exception: pass return subtitle except Exception as e: _, __, tb = sys.exc_info() print(traceback.print_tb(tb)) log_debug( 'Vipsubs.gr subtitle download failed for the following reason: ' + str(e)) return