def checkLatest(current, latest): if current == latest: return CURRENT if not utils.DialogYesNo(utils.GETTEXT(30115), utils.GETTEXT(30116)): return DECLINED filename = 'addon-%s.zip' % latest url = s3.getFile(ROOT, filename) dest = os.path.join(PROFILE, filename) title = utils.GETTEXT(30117) dp = utils.DialogProgress(utils.GETTEXT(30079) % title, utils.GETTEXT(30080)) import download download.doDownload(url, dest, title=title, referrer='', dp=dp, silent=False) if not sfile.exists(dest): return FAILED extracted = extract(dest, dp) try: sfile.delete(dest) except: pass if not extracted: return FAILED import xbmcgui xbmcgui.Window(10000).setProperty('LB_RELAUNCH', 'true') cmd = 'UpdateLocalAddons' xbmc.executebuiltin(cmd) return UPDATED
def _doImportFromRemote(): try: location = LOCATION.replace(' ', '%20') file = os.path.join(HOME, '_sf_temp.zip') dp = utils.Progress(TITLE, line1=GETTEXT(30140) % GETTEXT(30000), line2=location.replace('%20', ' '), line3=GETTEXT(30141)) import download import urllib download.doDownload(urllib.quote_plus(location), urllib.quote_plus(file), urllib.quote_plus(TITLE), quiet=True) if os.path.exists(file): success = extractAll(file, dp, location.replace('%20', ' ')) utils.DeleteFile(file) return success except Exception as e: utils.log('Error in _doImportFromRemote %s' % str(e)) return False
def _doImportFromRemote(): try: location = LOCATION.replace(' ', '%20') file = os.path.join(HOME, '_sf_temp.zip') import download download.doDownload(location, file, TITLE) if os.path.exists(file): success = extractAll(file) utils.DeleteFile(file) return success except Exception, e: utils.log(e)
def _doImportFromRemote(): try: location = LOCATION.replace(' ', '%20') file = os.path.join(HOME, '_sf_temp.zip') dp = utils.Progress(TITLE, line1 = GETTEXT(30140) % GETTEXT(30000), line2 = location.replace('%20', ' '), line3 = GETTEXT(30141)) import download download.doDownload(location, file, TITLE) if os.path.exists(file): success = extractAll(file, dp, location.replace('%20', ' ')) utils.DeleteFile(file) return success except Exception, e: utils.log(e)
def _doImportFromRemote(): try: location = LOCATION.replace(' ', '%20') file = os.path.join(HOME, '_sf_temp.zip') dp = utils.Progress(TITLE, line1 = GETTEXT(30140) % GETTEXT(30000), line2 = location.replace('%20', ' '), line3 = GETTEXT(30141)) import download import urllib download.doDownload(urllib.quote_plus(location), urllib.quote_plus(file), urllib.quote_plus(TITLE), quiet=True) if os.path.exists(file): success = extractAll(file, dp, location.replace('%20', ' ')) utils.DeleteFile(file) return success except Exception, e: utils.log('Error in _doImportFromRemote %s' % str(e))
def DoDownload(name, dst, src, image=None, orignalSrc=None, progressClose=True, silent=False): import download import s3 import sfile dst = dst.replace(os.sep, DELIMETER) src = src.replace(os.sep, DELIMETER) if orignalSrc == None or len(orignalSrc) == 0: orignalSrc = src temp = dst + '.temp' url = urllib.quote_plus(src) url = s3.getURL(url) url = s3.convertToCloud(url) #image no longer used #if image and image.startswith('http'): # pass #else: # image = None image = None resp = download.getResponse(url, 0, '') if not resp: return 1 dp = None name = name.decode('utf-8') if not silent: dp = DialogProgress(GETTEXT(30079) % name) download.doDownload(url, temp, name, dp=dp, silent=silent) if dp and progressClose: dp.close() if sfile.exists(temp + '.part'): #if part file exists then download has failed return 1 if not sfile.exists(temp): #download was cancelled return 2 sfile.remove(dst) sfile.rename(temp, dst) src = orignalSrc #recursively get dsc files dscFile = removeExtension(dst) + '.%s' % DSC while len(src) > 0: try: plot = getAmazonContent(src, DSC) sfile.write(dscFile, plot) newSrc = src.rsplit(DELIMETER, 1)[0] if newSrc == src: break src = newSrc dscFile = dscFile.rsplit(DELIMETER, 1)[0] + '.%s' % DSC except: pass #original image handling - no longer used if image: img = image.rsplit('?', 1)[0] ext = img.rsplit('.' , 1)[-1] root = dst.rsplit('.' , 1)[0] jpg = root + '.%s' % ext gif = root + '.%s' % 'gif' gifURL = s3.getURL(urllib.quote_plus(_src.rsplit('.', 1)[0] + '.gif')) DownloadIfExists(image, jpg) DownloadIfExists(gifURL, gif) #recursively get image files src = orignalSrc.rsplit('.', 1)[0] dst = dst.rsplit('.', 1)[0] imageTypes = IMG_EXT imageTypes.append('.gif') while len(src) > 0: for ext in imageTypes: image = src + ext image = s3.getURL(urllib.quote_plus(image)) image = s3.convertToCloud(image) DownloadIfExists(image, dst+ext) newSrc = src.rsplit(DELIMETER, 1)[0] if newSrc == src: break src = newSrc dst = dst.rsplit(DELIMETER, 1)[0] return 0
def getOneStrm(all_strms): if not all_strms: return False first_strm_name = sorted(all_strms.keys())[0] ep = all_strms[first_strm_name] title = ep["title"] year = ep["year"] imdb = ep["imdb"] tvdb = ep["tvdb"] tmdb = ep["tmdb"] tvrage = ep["tvrage"] date = ep["date"] season = ep["season"] episode = ep["episode"] show = ep["tvshowtitle"] name = ep["name"] downloaded_filename_base = ( getGenesisSetting("tv_downloads") + first_strm_name[len(getGenesisSetting("tv_library")) :] ) try: xbmcvfs.mkdirs(os.path.dirname(downloaded_filename_base)) except: pass all_strms.pop(first_strm_name, None) try: state().setProperty(curr_download_prop, os.path.basename(str(first_strm_name))) except: state().setProperty(next_download_prop, "None") try: state().setProperty(next_download_prop, os.path.basename(str(sorted(all_strms.keys())[0]))) except: state().setProperty(next_download_prop, "None") try: state().setProperty(queue_length, str(len(all_strms.keys()))) except: state().setProperty(queue_length, "0") src = sources.sources() has_sources = src.checkSources(name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, show, "0", date) if not has_sources: xbmc.log(msg="Genesis Prefetch: No sources for " + name, level=xbmc.LOGNOTICE) return False source_names = src.sourcesFilter() extra_filtered_sources = [] # Drop LQ/MQ links. We want decent quality for the prefetch. for s in source_names: if s["label"].find("LQ") >= 0 or s["label"].find("MQ") >= 0: continue else: extra_filtered_sources.append(s) sources_dict = {} # This part needs to be put into threads per URL. # Gets so slow that we can't use opened connections and need to open again. for single_source in extra_filtered_sources: src.sources = [single_source] url = src.sourcesDirect() if not url: continue try: (main_url, headers) = parseGenesisUrl(url) u = download.getResponse(main_url, headers, 0, "") if not u: continue meta = u.info() try: content_type = meta.getheaders("Content-Type")[0] except: content_type = None if content_type == "text/html" or content_type == "text/plain": continue h = meta.getheaders("Content-Length") try: file_size = int(h[0]) except: continue extension = ".mp4" for ext in [".mp4", ".flv", ".avi", ".mkv"]: if url.lower().find(ext) > 0: extension = ext sources_dict[main_url] = (file_size, u, extension, main_url, headers) except Exception as e: xbmc.log(msg="Genesis Prefetch: FETCH HEADERS EXCEPTION: " + str(e), level=xbmc.LOGNOTICE) continue # Pick largest file, because quality. sorted_by_size = sorted(sources_dict.values(), key=lambda tup: tup[0], reverse=True) for (file_size, u, extension, url, headers) in sorted_by_size: file_name = downloaded_filename_base + extension try: if download.doDownload(url, headers, downloaded_filename_base + ".temp_dl", title, ""): xbmcvfs.rename(downloaded_filename_base + ".temp_dl", file_name) return True except Exception as e: xbmc.log(msg="Genesis Prefetch: DOWNLOAD EXCEPTION: " + str(e), level=xbmc.LOGNOTICE) continue return False
def doMenu(): DEBUG = ADDON.getSetting('DEBUG') == 'true' if DEBUG: window = xbmcgui.getCurrentWindowId() utils.DialogOK('Current Window ID %d' % window) active = [0, 1, 2, 3, 25, 40, 500, 501, 502, 601, 2005] window = xbmcgui.getCurrentWindowId() utils.log('Window : %d' % window) if window - 10000 not in active: doStandard(useScript=False) return import menus # to prevent master profile setting being used in other profiles if ADDON.getSetting('CONTEXT') != 'true': doStandard(useScript=False) return folder = xbmc.getInfoLabel('Container.FolderPath') path = xbmc.getInfoLabel('ListItem.FolderPath') #ignore if in Super Favourites if (ADDONID in folder) or (ADDONID in path): doStandard(useScript=False) return choice = 0 label = xbmc.getInfoLabel('ListItem.Label') filename = xbmc.getInfoLabel('ListItem.FilenameAndPath') name = xbmc.getInfoLabel('ListItem.Label') thumb = xbmc.getInfoLabel('ListItem.Thumb') icon = xbmc.getInfoLabel('ListItem.ActualIcon') #thumb = xbmc.getInfoLabel('ListItem.Art(thumb)') playable = xbmc.getInfoLabel( 'ListItem.Property(IsPlayable)').lower() == 'true' fanart = xbmc.getInfoLabel('ListItem.Property(Fanart_Image)') fanart = xbmc.getInfoLabel('ListItem.Art(fanart)') isFolder = xbmc.getCondVisibility('ListItem.IsFolder') == 1 desc = getDescription() if not thumb: thumb = icon try: file = xbmc.Player().getPlayingFile() except: file = None isStream = False if hasattr(xbmc.Player(), 'isInternetStream'): isStream = xbmc.Player().isInternetStream() elif file: isStream = file.startswith('http://') if window == 10003: #filemanager control = 0 if xbmc.getCondVisibility('Control.HasFocus(20)') == 1: control = 20 elif xbmc.getCondVisibility('Control.HasFocus(21)') == 1: control = 21 if control == 0: return doStandard() name = xbmc.getInfoLabel('Container(%d).ListItem.Label' % control) root = xbmc.getInfoLabel('Container(%d).ListItem.Path' % control) path = root + name isFolder = True thumb = 'DefaultFolder.png' #if not path.endswith(os.sep): # path += os.sep if isFolder: path = path.replace('\\', '\\\\') filename = filename.replace('\\', '\\\\') utils.log('**** Context Menu Information ****') utils.log('Label : %s' % label) utils.log('Folder : %s' % folder) utils.log('Path : %s' % path) utils.log('Filename : %s' % filename) utils.log('Name : %s' % name) utils.log('Thumb : %s' % thumb) utils.log('Fanart : %s' % fanart) utils.log('Window : %d' % window) utils.log('IsPlayable : %s' % playable) utils.log('IsFolder : %s' % isFolder) utils.log('File : %s' % file) utils.log('IsStream : %s' % isStream) menu = [] localAddon = None #if xbmc.getCondVisibility('Player.HasVideo') == 1: # if isStream: # menu.append(('Download %s' % label, _DOWNLOAD)) # menu.append(('Now playing...', _PLAYLIST)) if len(path) > 0: if MENU_ADDTOFAVES: menu.append((GETTEXT(30047), _ADDTOFAVES)) if MENU_ADDON_SETTINGS: localAddon = utils.findAddon(path) if localAddon: label = utils.getSettingsLabel(localAddon) menu.append((label, _SETTINGS)) if MENU_DEF_ISEARCH: default = getDefaultSearch() if len(default) > 0: menu.append((GETTEXT(30098) % default, _SEARCHDEF)) if MENU_ISEARCH: menu.append((GETTEXT(30054), _SEARCH)) if MENU_IRECOMMEND: menu.append((GETTEXT(30088), _RECOMMEND)) if MENU_COPY_PROPS: if len(thumb) > 0 or len(fanart) > 0: menu.append((GETTEXT(30209), _COPYIMAGES)) if MENU_VIEW_IMAGES: menu.append((GETTEXT(30216), _SHOWIMAGE)) else: if len(description) > 0: menu.append((GETTEXT(30209), _COPYIMAGES)) if MENU_SF_SETTINGS: menu.append((GETTEXT(30049), _SF_SETTINGS)) if MENU_STD_MENU: menu.append((GETTEXT(30048), _STD_MENU)) if len(menu) == 0 or (len(menu) == 1 and MENU_STD_MENU): doStandard(useScript=False) return xbmcgui.Window(10000).setProperty('SF_MENU_VISIBLE', 'true') dialog = ADDON.getSetting('CONTEXT_STYLE') == '1' if dialog: choice = menus.selectMenu(utils.TITLE, menu) else: choice = menus.showMenu(ADDONID, menu) #if choice == _STD_MENU: # doStandard() # return xbmc.executebuiltin('Dialog.Close(all, true)') if choice == _PLAYLIST: xbmc.executebuiltin('ActivateWindow(videoplaylist)') if choice == _DOWNLOAD: import download download.doDownload(file, 'c:\\temp\\file.mpg', 'Super Favourites', '', True) if choice == _STD_MENU: doStandard() if choice == _SF_SETTINGS: utils.ADDON.openSettings() if choice == _SETTINGS: xbmcaddon.Addon(localAddon).openSettings() if choice == _ADDTOFAVES: import favourite if isFolder: cmd = 'ActivateWindow(%d,"%s' % (window, path) elif path.lower().startswith('script'): #if path[-1] == '/': # path = path[:-1] cmd = 'RunScript("%s' % path.replace('script://', '') elif path.lower().startswith('videodb') and len(filename) > 0: cmd = 'PlayMedia("%s' % filename #elif path.lower().startswith('musicdb') and len(filename) > 0: # cmd = 'PlayMedia("%s")' % filename elif path.lower().startswith('androidapp'): cmd = 'StartAndroidActivity("%s")' % path.replace( 'androidapp://sources/apps/', '', 1) else: cmd = 'PlayMedia("%s")' % path cmd = favourite.updateSFOption(cmd, 'winID', window) cmd = favourite.addFanart(cmd, fanart) cmd = favourite.updateSFOption(cmd, 'desc', desc) if isFolder: cmd = cmd.replace('")', '",return)') copyFave(name, thumb, cmd) if choice == _LAUNCH_SF: utils.LaunchSF() if choice in [_SEARCH, _SEARCHDEF, _RECOMMEND]: if utils.ADDON.getSetting('STRIPNUMBERS') == 'true': name = utils.Clean(name) thumb = thumb if len(thumb) > 0 else 'null' fanart = fanart if len(fanart) > 0 else 'null' #declared in default.py _SUPERSEARCH = 0 _SUPERSEARCHDEF = 10 _RECOMMEND_KEY = 2700 videoID = 10025 #video if window == 10000: #don't activate on home screen, push to video window = videoID import urllib if choice == _RECOMMEND: mode = _RECOMMEND_KEY else: mode = _SUPERSEARCH if (choice == _SEARCH) else _SUPERSEARCHDEF cmd = 'ActivateWindow(%d,"plugin://%s/?mode=%d&keyword=%s&image=%s&fanart=%s")' % ( window, ADDONID, mode, urllib.quote_plus(name), urllib.quote_plus(thumb), urllib.quote_plus(fanart)) activateCommand(cmd) if choice == _COPYIMAGES: if not fanart: fanart = thumb xbmcgui.Window(10000).setProperty('SF_THUMB', thumb) xbmcgui.Window(10000).setProperty('SF_FANART', fanart) xbmcgui.Window(10000).setProperty('SF_DESCRIPTION', desc) if choice == _SHOWIMAGE: if not fanart: fanart = thumb import viewer viewer.show(fanart, thumb, ADDONID)
def doMenu(): DEBUG = ADDON.getSetting('DEBUG') == 'true' if DEBUG: window = xbmcgui.getCurrentWindowId() utils.DialogOK('Current Window ID %d' % window) active = [0, 1, 2, 3, 25, 40, 500, 501, 502, 601, 2005] window = xbmcgui.getCurrentWindowId() utils.log('Window : %d' % window) if window-10000 not in active: doStandard(useScript=False) return import menus # to prevent master profile setting being used in other profiles if ADDON.getSetting('CONTEXT') != 'true': doStandard(useScript=False) return folder = xbmc.getInfoLabel('Container.FolderPath') path = xbmc.getInfoLabel('ListItem.FolderPath') #ignore if in Super Favourites if (ADDONID in folder) or (ADDONID in path): doStandard(useScript=False) return choice = 0 label = xbmc.getInfoLabel('ListItem.Label') filename = xbmc.getInfoLabel('ListItem.FilenameAndPath') name = xbmc.getInfoLabel('ListItem.Label') thumb = xbmc.getInfoLabel('ListItem.Thumb') icon = xbmc.getInfoLabel('ListItem.ActualIcon') #thumb = xbmc.getInfoLabel('ListItem.Art(thumb)') playable = xbmc.getInfoLabel('ListItem.Property(IsPlayable)').lower() == 'true' fanart = xbmc.getInfoLabel('ListItem.Property(Fanart_Image)') fanart = xbmc.getInfoLabel('ListItem.Art(fanart)') isFolder = xbmc.getCondVisibility('ListItem.IsFolder') == 1 desc = getDescription() if not thumb: thumb = icon try: file = xbmc.Player().getPlayingFile() except: file = None isStream = False if hasattr(xbmc.Player(), 'isInternetStream'): isStream = xbmc.Player().isInternetStream() elif file: isStream = file.startswith('http://') if window == 10003: #filemanager control = 0 if xbmc.getCondVisibility('Control.HasFocus(20)') == 1: control = 20 elif xbmc.getCondVisibility('Control.HasFocus(21)') == 1: control = 21 if control == 0: return doStandard() name = xbmc.getInfoLabel('Container(%d).ListItem.Label' % control) root = xbmc.getInfoLabel('Container(%d).ListItem.Path' % control) path = root + name isFolder = True thumb = 'DefaultFolder.png' #if not path.endswith(os.sep): # path += os.sep if isFolder: path = path.replace('\\', '\\\\') filename = filename.replace('\\', '\\\\') utils.log('**** Context Menu Information ****') utils.log('Label : %s' % label) utils.log('Folder : %s' % folder) utils.log('Path : %s' % path) utils.log('Filename : %s' % filename) utils.log('Name : %s' % name) utils.log('Thumb : %s' % thumb) utils.log('Fanart : %s' % fanart) utils.log('Window : %d' % window) utils.log('IsPlayable : %s' % playable) utils.log('IsFolder : %s' % isFolder) utils.log('File : %s' % file) utils.log('IsStream : %s' % isStream) menu = [] localAddon = None #if xbmc.getCondVisibility('Player.HasVideo') == 1: # if isStream: # menu.append(('Download %s' % label, _DOWNLOAD)) # menu.append(('Now playing...', _PLAYLIST)) if len(path) > 0: if MENU_ADDTOFAVES: menu.append((GETTEXT(30047), _ADDTOFAVES)) if MENU_ADDON_SETTINGS: localAddon = utils.findAddon(path) if localAddon: label = utils.getSettingsLabel(localAddon) menu.append((label, _SETTINGS)) if MENU_DEF_ISEARCH: default = getDefaultSearch() if len(default) > 0: menu.append((GETTEXT(30098) % default, _SEARCHDEF)) if MENU_ISEARCH: menu.append( (GETTEXT(30054), _SEARCH)) if MENU_IRECOMMEND: menu.append((GETTEXT(30088), _RECOMMEND)) if MENU_COPY_PROPS: if len(thumb) > 0 or len(fanart) > 0: menu.append((GETTEXT(30209), _COPYIMAGES)) if MENU_VIEW_IMAGES: menu.append((GETTEXT(30216), _SHOWIMAGE)) else: if len(description) > 0: menu.append((GETTEXT(30209), _COPYIMAGES)) if MENU_SF_SETTINGS: menu.append((GETTEXT(30049), _SF_SETTINGS)) if MENU_STD_MENU: menu.append((GETTEXT(30048), _STD_MENU)) if len(menu) == 0 or (len(menu) == 1 and MENU_STD_MENU): doStandard(useScript=False) return xbmcgui.Window(10000).setProperty('SF_MENU_VISIBLE', 'true') dialog = ADDON.getSetting('CONTEXT_STYLE') == '1' if dialog: choice = menus.selectMenu(utils.TITLE, menu) else: choice = menus.showMenu(ADDONID, menu) #if choice == _STD_MENU: # doStandard() # return xbmc.executebuiltin('Dialog.Close(all, true)') if choice == _PLAYLIST: xbmc.executebuiltin('ActivateWindow(videoplaylist)') if choice == _DOWNLOAD: import download download.doDownload(file, 'c:\\temp\\file.mpg', 'Super Favourites', '', True) if choice == _STD_MENU: doStandard() if choice == _SF_SETTINGS: utils.ADDON.openSettings() if choice == _SETTINGS: xbmcaddon.Addon(localAddon).openSettings() if choice == _ADDTOFAVES: import favourite if isFolder: cmd = 'ActivateWindow(%d,"%s' % (window, path) elif path.lower().startswith('script'): #if path[-1] == '/': # path = path[:-1] cmd = 'RunScript("%s' % path.replace('script://', '') elif path.lower().startswith('videodb') and len(filename) > 0: cmd = 'PlayMedia("%s' % filename #elif path.lower().startswith('musicdb') and len(filename) > 0: # cmd = 'PlayMedia("%s")' % filename elif path.lower().startswith('androidapp'): cmd = 'StartAndroidActivity("%s")' % path.replace('androidapp://sources/apps/', '', 1) else: cmd = 'PlayMedia("%s")' % path cmd = favourite.updateSFOption(cmd, 'winID', window) cmd = favourite.addFanart(cmd, fanart) cmd = favourite.updateSFOption(cmd, 'desc', desc) if isFolder: cmd = cmd.replace('")', '",return)') copyFave(name, thumb, cmd) if choice == _LAUNCH_SF: utils.LaunchSF() if choice in [_SEARCH, _SEARCHDEF, _RECOMMEND]: if utils.ADDON.getSetting('STRIPNUMBERS') == 'true': name = utils.Clean(name) thumb = thumb if len(thumb) > 0 else 'null' fanart = fanart if len(fanart) > 0 else 'null' #declared in default.py _SUPERSEARCH = 0 _SUPERSEARCHDEF = 10 _RECOMMEND_KEY = 2700 videoID = 10025 #video if window == 10000: #don't activate on home screen, push to video window = videoID import urllib if choice == _RECOMMEND: mode = _RECOMMEND_KEY else: mode = _SUPERSEARCH if (choice == _SEARCH) else _SUPERSEARCHDEF cmd = 'ActivateWindow(%d,"plugin://%s/?mode=%d&keyword=%s&image=%s&fanart=%s")' % (window, ADDONID, mode, urllib.quote_plus(name), urllib.quote_plus(thumb), urllib.quote_plus(fanart)) activateCommand(cmd) if choice == _COPYIMAGES: if not fanart: fanart = thumb xbmcgui.Window(10000).setProperty('SF_THUMB', thumb) xbmcgui.Window(10000).setProperty('SF_FANART', fanart) xbmcgui.Window(10000).setProperty('SF_DESCRIPTION', desc) if choice == _SHOWIMAGE: if not fanart: fanart = thumb import viewer viewer.show(fanart, thumb, ADDONID)