def isInMediaList(mediaTitle, url, cType='Other'): utils.addon_log('isInMediaList') existInList = False thefile = xbmc.translatePath(os.path.join(MEDIALIST_PATH, 'MediaList.xml')) if not xbmcvfs.exists(profile): xbmcvfs.mkdirs(profile) if not xbmcvfs.exists(thefile): xbmcvfs.File(thefile, 'a').close() fle = xbmcvfs.File(thefile, 'r') thelist = fle.read().split('\n') fle.close() del fle if len(thelist) > 0: for i in thelist: splits = i.strip().split('|') if stringUtils.getStrmname( splits[1]) == stringUtils.getStrmname(mediaTitle): splitPlugin = re.search('plugin:\/\/([^\/\?]*)', splits[2]) mediaPlugin = re.search('plugin:\/\/([^\/\?]*)', url) if mediaPlugin and splitPlugin and mediaPlugin.group( 1) == splitPlugin.group(1): existInList = True if existInList: return True else: return False
def writeMediaList(url, name, cType='Other', cleanName=True, albumartist=None): utils.addon_log('writeMediaList') existInList = False thefile = xbmc.translatePath(os.path.join(MEDIALIST_PATH, 'MediaList.xml')) if not xbmcvfs.exists(profile): xbmcvfs.mkdirs(profile) if not xbmcvfs.exists(thefile): xbmcvfs.File(thefile, 'w').close() fle = xbmcvfs.File(thefile, 'r') thelist = fle.read().splitlines() fle.close() del fle thelist = [x for x in thelist if x != ''] if len(thelist) > 0: for i in thelist: splits = i.strip().split('|') if stringUtils.getStrmname( splits[1]).lower() == stringUtils.getStrmname( name).lower(): existInList = True if splits[2].find(url) == -1: splits[2] = '%s<next>%s' % (splits[2], url) if albumartist: splits[4] = albumartist.decode('utf-8') newentry = '|'.join(splits) xbmcgui.Dialog().notification( str(i), "Adding to MediaList", os.path.join(ADDON_PATH, 'resources/representerIcon.png'), 5000) thelist = stringUtils.replaceStringElem( thelist, i, newentry) if existInList != True: newentry = [cType, name.decode("utf-8"), url] if albumartist: newentry.append(albumartist.decode('utf-8')) newentry = '|'.join(newentry) thelist.append(newentry) output_file = xbmcvfs.File(thefile.decode("utf-8"), 'w') for index, linje in enumerate(thelist): output_file.write(('%s\n' if index < len(thelist) - 1 else '%s') % linje.strip().encode('utf-8'))
def update(strm_name, url, media_type, thelist): plex_details = jsonUtils.requestList("plugin://plugin.video.plexbmc", media_type).get('files', []) for plex_detail in plex_details: if stringUtils.getStrmname(strm_name) == stringUtils.cleanLabels( plex_detail['label']): serverurl = plex_detail['file'] if url != serverurl: for entry in thelist: splits = entry.split("|") if splits[1] == strm_name: splits[2] = serverurl newentry = '|'.join(splits) thelist = stringUtils.replaceStringElem( thelist, entry, newentry) thefile = xbmc.translatePath( os.path.join(addon.getSetting('MediaList_LOC'), 'MediaList.xml')) output_file = xbmcvfs.File(thefile.decode("utf-8"), 'w') for index, linje in enumerate(thelist): output_file.write( ('%s\n' if index < len(thelist) - 1 else '%s') % linje.strip().encode('utf-8')) return serverurl else: break return url
def removeItemsFromMediaList(action='list'): utils.addon_log('removingitemsdialog') selectedItems = getMediaListDialog() if selectedItems is not None: fileSys.removeMediaList(selectedItems) selectedLabels = [stringUtils.getStrmname(item.split('|')[1]) for item in selectedItems] xbmcgui.Dialog().notification("Finished deleting:", "{0}".format(", ".join(label for label in selectedLabels)))
def writeMediaList(url, name, cType='Other', cleanName=True): utils.addon_log('writeMediaList') existInList = False thelist = [] thefile = xbmc.translatePath(os.path.join(profile, 'MediaList.xml')) theentry = '|'.join([cType, name.decode("utf-8"), url]) + '\n' if not xbmcvfs.exists(profile): xbmcvfs.mkdirs(profile) if not xbmcvfs.exists(thefile): open(thefile, 'a').close() fle = codecs.open(thefile, "r", 'UTF-8') thelist = fle.readlines() fle.close() del fle if len(thelist) > 0: for i in thelist: splits = i.strip().split('|') if stringUtils.getStrmname( splits[1]) == stringUtils.getStrmname(name): splitPlugin = re.search('%s([^\/\?]*)' % ("plugin:\/\/"), splits[2]) mediaPlugin = re.search('%s([^\/\?]*)' % ("plugin:\/\/"), url) if mediaPlugin and splitPlugin and mediaPlugin.group( 1) == splitPlugin.group(1): xbmcgui.Dialog().notification( str(i), "Adding to MediaList", os.path.join(ADDON_PATH, 'resources/representerIcon.png'), 5000) thelist = stringUtils.replaceStringElem( thelist, i, theentry) existInList = True if existInList != True: thelist.append(theentry) with open(thefile.decode("utf-8"), 'w') as output_file: for linje in thelist: if not linje.startswith('\n'): output_file.write(linje.strip().encode('utf-8') + '\n') else: output_file.write(linje.strip())
def getMediaListDialog(): thelist = fileSys.readMediaList(purge=False) items = [] for entry in thelist: splits = entry.strip().split('|') plugin = re.search('%s([^\/\?]*)' % ("plugin:\/\/"), splits[2]) items.append(stringUtils.getStrmname(splits[1]) + " (" + fileSys.getAddonname(plugin.group(1)) + ")") selectedItemsIndex = xbmcgui.Dialog().multiselect("Select items", items) return [thelist[index] for index in selectedItemsIndex] if selectedItemsIndex is not None else []
def getEpisode(episode_item, strm_name, strm_type, j=0, pagesDone=0): episode = None utils.addon_log("detailInfo: %s" % (episode_item)) file = episode_item.get('file', None) episode = episode_item.get('episode', -1) season = episode_item.get('season', -1) strSeasonEpisode = 's%de%d' % (season, episode) showtitle = episode_item.get('showtitle', None) provider = getProvider(file) if showtitle is not None and showtitle != "" and strm_type != "": path = os.path.join( strm_type, stringUtils.cleanStrmFilesys(showtitle) ) if strm_name.find('++RenamedTitle++') == -1 else os.path.join( strm_type, stringUtils.cleanStrmFilesys(stringUtils.getStrmname(strm_name))) episode = { 'path': path, 'strSeasonEpisode': strSeasonEpisode, 'url': file, 'tvShowTitle': showtitle, 'provider': provider } if strm_name.find('++RenamedTitle++') == -1 else { 'path': path, 'strSeasonEpisode': strSeasonEpisode, 'url': file, 'tvShowTitle': stringUtils.getStrmname(strm_name), 'provider': provider } if addon.getSetting('Link_Type') == '0': episode = kodiDB.writeShow(episode) if episode is not None: strm_link = 'plugin://%s/?url=plugin&mode=10&mediaType=show&episode=%s&showid=%d|%s' % ( addon_id, episode.get('strSeasonEpisode'), episode.get('showID'), episode.get('tvShowTitle') ) if addon.getSetting('Link_Type') == '0' else episode.get('url') fileSys.writeSTRM(episode.get('path'), episode.get('strSeasonEpisode'), strm_link) return pagesDone
def getTVShowFromList(showList, strm_name='', strm_type='Other', pagesDone=0): dirList = [] episodesList = [] while pagesDone < int(PAGINGTVshows): strm_type = strm_type.replace('Shows-Collection', 'TV-Shows') try: for detailInfo in showList: filetype = detailInfo.get('filetype', None) file = detailInfo.get('file', None) episode = detailInfo.get('episode', -1) season = detailInfo.get('season', -1) if filetype is not None: if filetype == 'directory': dirList.append( jsonUtils.requestList(file, 'video').get('files', [])) continue elif season > -1 and episode > -1 and filetype == 'file': episodesList.append(detailInfo) step = float(100.0 / len(episodesList) if len(episodesList) > 0 else 1) if pagesDone == 0: thisDialog.dialogeBG.update( int(step), "Initialisation of TV-Shows: " + stringUtils.getStrmname(strm_name)) else: thisDialog.dialogeBG.update( int(step), "Page: " + str(pagesDone) + " " + stringUtils.getStrmname(strm_name)) for index, episode in enumerate(episodesList): pagesDone = getEpisode(episode, strm_name, strm_type, pagesDone=pagesDone) thisDialog.dialogeBG.update(int(step * (index + 1))) except IOError as (errno, strerror): print("I/O error({0}): {1}").format(errno, strerror) except ValueError: print("No valid integer in line.")
def addMovies(contentList, strm_name='', strm_type='Other', provider="n.a"): movieList = [] pagesDone = 0 file = '' filetype = '' j = len(contentList) * int(PAGINGMovies) / 100 if len(contentList) == 0: return while pagesDone < int(PAGINGMovies): if not contentList[0] == "palyableSingleMedia": for detailInfo in contentList: file = detailInfo.get('file').replace( "\\\\", "\\") if detailInfo.get('file', None) is not None else None filetype = detailInfo.get('filetype', None) label = detailInfo.get('label').strip() if detailInfo.get( 'label', None) is not None else None imdbnumber = detailInfo.get('imdbnumber').strip( ) if detailInfo.get('imdbnumber', None) is not None else None try: if label and strm_name: label = stringUtils.cleanLabels(label) if HIDE_tile_in_OV == "true" and label.find( "[OV]") > -1: get_title_with_OV = False else: get_title_with_OV = True provider = getProvider(file) thisDialog.dialogeBG.update( j, ADDON_NAME + ": Getting Movies: ", " Video: " + label) if filetype is not None and filetype == 'file' and get_title_with_OV == True: m_path = stringUtils.getMovieStrmPath( strm_type, strm_name, label) m_title = stringUtils.getStrmname(label) movieList.append({ 'path': m_path, 'title': m_title, 'url': file, 'provider': provider, 'imdbnumber': imdbnumber }) j = j + len(contentList) * int(PAGINGMovies) / 100 except IOError as (errno, strerror): print("I/O error({0}): {1}").format(errno, strerror) except ValueError: print("No valid integer in line.") except:
def getMediaListDialog(): thelist = sorted(fileSys.readMediaList(purge=False), key=lambda k: k.split('|')[1]) items = [] for entry in thelist: splits = entry.strip().split('|') matches = re.findall("plugin:\/\/([^\/\?]*)", splits[2]) if matches: pluginnames = [fileSys.getAddonname(plugin) for plugin in matches] items.append( stringUtils.getStrmname(splits[1]) + " (%s)" % (', '.join(pluginnames))) selectedItemsIndex = xbmcgui.Dialog().multiselect("Select items", items) return [thelist[index] for index in selectedItemsIndex] if selectedItemsIndex else None
def delNotInMediaList(delList): for entry in delList: try: splits = entry.split('|') type = splits[0] isAudio = True if type.lower().find('audio') > -1 else False path = completePath(STRM_LOC) + type if isAudio and len(splits) > 3: path = completePath( path) + stringUtils.cleanByDictReplacements(splits[3]) itemPath = stringUtils.getStrmname(splits[1]) path = completePath( completePath(path) + stringUtils.cleanStrmFilesys(itemPath)) utils.addon_log("remove: %s" % path) xbmcvfs.rmdir(path, force=True) if isAudio: xbmc.executeJSONRPC( '{"jsonrpc": "2.0", "method": "AudioLibrary.Clean", "id": 1}' ) except OSError: print("Unable to remove: %s" % path)
def fillPluginItems(url, media_type='video', file_type=False, strm=False, strm_name='', strm_type='Other', showtitle='None'): initialize_DialogBG("Updating", "Getting content..") thisDialog.dialogeBG.update(0, ADDON_NAME + ": Getting: ", stringUtils.getStrmname(strm_name)) utils.addon_log('fillPluginItems') details = [] if url.find("playMode=play") == -1: if not file_type: details = jsonUtils.requestList(url, media_type).get('files', []) else: details = jsonUtils.requestItem(url, media_type).get('files', []) else: details.append("palyableSingleMedia") details.append(url) thisDialog.dialogeBG.close() thisDialog.dialogeBG = None if strm_type.find('Cinema') != -1 or strm_type.find('YouTube') != -1 or strm_type.find('Movies') != -1: try: initialize_DialogBG("Movie", "Adding") movieList = addMovies(details, strm_name, strm_type) dbMovList = kodiDB.writeMovie(movieList) j = 100 / len(dbMovList) if len(dbMovList) > 0 else 1 # Write strms for all values in movieList for entry in dbMovList: thisDialog.dialogeBG.update(j, ADDON_NAME + ": Writing Movies: ", " Video: " + entry.get('title')) fileSys.writeSTRM(stringUtils.cleanStrms(entry.get('path')), stringUtils.cleanStrms(entry.get('title')) , "plugin://plugin.video.osmosix/?url=plugin&mode=10&mediaType=movie&id=" + str(entry.get('movieID')) + "|" + entry.get('title')) j = j + 100 / len(movieList) thisDialog.dialogeBG.close() thisDialog.dialogeBG = None return except: thisDialog.dialogeBG.close() thisDialog.dialogeBG = None guiTools.infoDialog("Unexpected error: " + str(sys.exc_info()[1])+ (". See your Kodi.log!")) utils.addon_log(("Unexpected error: ") + str(sys.exc_info()[1])) print ("Unexpected error:"), sys.exc_info()[0] raise if strm_type.find('TV-Show') != -1 or strm_type.find('Shows-Collection') != -1: try: initialize_DialogBG("Adding TV-Shows", "working..") getTVShowFromList(details, strm_name, strm_type) thisDialog.dialogeBG.close() thisDialog.dialogeBG = None return except: thisDialog.dialogeBG.close() thisDialog.dialogeBG = None guiTools.infoDialog("Unexpected error: " + str(sys.exc_info()[1])+ (". See your Kodi.log!")) utils.addon_log(("Unexpected error: ") + str(sys.exc_info()[1])) print ("Unexpected error:"), sys.exc_info()[0] raise if strm_type.find('Album') != -1 : try: initialize_DialogBG("Album", "Adding") addAlbum(details, strm_name, strm_type) thisDialog.dialogeBG.close() thisDialog.dialogeBG = None return except: thisDialog.dialogeBG.close() thisDialog.dialogeBG = None guiTools.infoDialog("Unexpected error: " + str(sys.exc_info()[1])+ (". See your Kodi.log!")) utils.addon_log(("Unexpected error: ") + str(sys.exc_info()[1])) print ("Unexpected error:"), sys.exc_info()[0] raise for detail in details: filetype = detail['filetype'] label = stringUtils.cleanLabels(detail['label']) file = detail['file'].replace("\\\\", "\\") strm_name = str(stringUtils.cleanByDictReplacements(strm_name.strip())) plot = stringUtils.cleanLabels(detail.get('plot','')) art = detail.get('art',{}) if addon.getSetting('Link_Type') == '0': link = sys.argv[0] + "?url=" +urllib.quote_plus(stringUtils.uni(file)) + "&mode=" + str(10) + "&name=" +urllib.quote_plus(stringUtils.uni(label)) + "&fanart=" + urllib.quote_plus(art.get('fanart','')) else: link = file if strm_type == 'Audio-Single': path = os.path.join('Singles', str(strm_name)) try: album = detail['album'].strip() artist = stringUtils.cleanByDictReplacements(", ".join(artist.strip() for artist in detailInfo['artist']) if isinstance(detailInfo['artist'], (list, tuple)) else detailInfo['artist'].strip()) title = detail['title'].strip() type = detail['type'].strip() filename = str(strm_name + ' - ' + label).strip() except: filename = str(strm_name + ' - ' + label).strip() if strm_type.find('Audio-Album') != -1: path = os.path.join(strm_type, strm_name) track = detail.get('track', 0) try: album = detail['album'].strip() artist = stringUtils.cleanByDictReplacements(", ".join(artist.strip() for artist in detailInfo['artist']) if isinstance(detailInfo['artist'], (list, tuple)) else detailInfo['artist'].strip()) title = stringUtils.cleanByDictReplacements(detail['title'].strip()) type = stringUtils.cleanByDictReplacements(detail['type'].strip()) filename = stringUtils.cleanByDictReplacements(label.strip()) except: filename = stringUtils.cleanByDictReplacements(label.strip()) if strm_type in ['Other']: path = os.path.join('Other', strm_name) filename = str(strm_name + ' - ' + label) if filetype == 'file': if strm: if strm_type.find('Audio-Albums') != -1: kodiDB.musicDatabase(album, artist, label, path, link, track) fileSys.writeSTRM(stringUtils.cleanStrms((path.rstrip("."))), stringUtils.cleanStrms(filename.rstrip(".")) , link) else: guiTools.addLink(label, file, 10, art, plot, '', '', '', None, '', total=len(details)) else: if strm: fillPluginItems(file, media_type, file_type, strm, label, strm_type) else: guiTools.addDir(label, file, 101, art, plot, '', '', '')
print ("Unexpected error:"), sys.exc_info()[0] raise pagesDone += 1 contentList = [] if pagesDone < int(PAGINGalbums) and len(dirList) > 0: contentList = [item for sublist in dirList for item in sublist] dirList = [] if False: try: urlUtils.downloadThumb(aThumb, album, os.path.join(STRM_LOC, strm_type, artist)) except: pass else: albumList.append([os.path.join(strm_type, stringUtils.getStrmname(strm_name) , label), stringUtils.cleanByDictReplacements(label), link]) pagesDone = int(PAGINGalbums) try: # Write strms for all values in albumList thelist = fileSys.readMediaList(purge=False) items = [] for entry in thelist: splits = entry.strip().split('|') splitsstrm = splits[0] splitsname = splits[1] if splitsstrm.find('Album') != -1 and splitsname.find(strm_name) != -1: url = splits[2] cType = splits[0] albumartist = artist fileSys.rewriteMediaList(url, strm_name, albumartist, cType)
def strm_update(selectedItems=None, actor=0): try: if xbmcvfs.exists(MediaList_LOC): thelist = selectedItems if selectedItems else readMediaList() if len(thelist) > 0: dialogeBG = xbmcgui.DialogProgressBG() dialogeBG.create("OSMOSIS: ", 'Total Update-Progress:') iUrls = 0 splittedEntries = [] for entry in thelist: splits = entry.strip().split('|') iUrls += len(splits[2].split('<next>')) splittedEntries.append(splits) step = j = 100 / iUrls for splittedEntry in splittedEntries: cType, name, url = splittedEntry[0], splittedEntry[ 1], splittedEntry[2] urls = url.split('<next>') for url in urls: try: plugin_id = re.search('plugin:\/\/([^\/\?]*)', url) if plugin_id: module = moduleUtil.getModule( plugin_id.group(1)) if module and hasattr(module, 'update'): url = module.update( name, url, 'video', readMediaList() if selectedItems else thelist) dialogeBG.update( j, "OSMOSIS total update process: ", "Current Item: %s Items left: %d" % (stringUtils.getStrmname(name), iUrls)) j += step create.fillPluginItems(url, strm=True, strm_name=name, strm_type=cType) iUrls -= 1 except: pass dialogeBG.close() if actor == actor_update_periodictime: xbmc.executebuiltin( 'Notification(%s, %s, %d, %s)' % (addon.getAddonInfo('name'), "Next update in: " + addon.getSetting('Automatic_Update_Time') + "h", 5000, represent)) elif actor == actor_update_fixtime: next_run = addon.getSetting('update_time')[:5] xbmc.executebuiltin( 'Notification(%s, %s, %d, %s)' % (addon.getAddonInfo('name'), "Next update: " + next_run + "h", 5000, represent)) except IOError as (errno, strerror): print("I/O error({0}): {1}").format(errno, strerror)
def getTVShowFromList(showList, strm_name='', strm_type='Other', pagesDone=0): dirList = [] episodesList = [] while pagesDone < int(PAGINGTVshows): strm_type = strm_type.replace('Shows-Collection', 'TV-Shows') try: for detailInfo in showList: filetype = detailInfo.get('filetype', None) file = detailInfo.get('file', None) if filetype: if filetype == 'directory': dirList.append( jsonUtils.requestList(file, 'video').get('files', [])) continue elif filetype == 'file': if detailInfo.get('season', -1) == -1 or detailInfo.get( 'episode', -1) == -1: showtitle = detailInfo.get('showtitle') episodetitle = detailInfo.get('title') if showtitle and showtitle != '' and episodetitle and episodetitle != '': lang = None if strm_type.lower().find('other') == -1: lang = strm_type[strm_type.find('(') + 1:strm_type.find(')')] data = tvdb.getEpisodeByName( showtitle, episodetitle, lang) if data: detailInfo['season'] = data.get('season') detailInfo['episode'] = data.get('episode') if detailInfo.get('season', -1) > -1 and detailInfo.get( 'episode', -1) > -1: if NOE0_STRMS_EXPORT == "false" or detailInfo.get( 'episode') > 0: episodesList.append(detailInfo) step = float(100.0 / len(episodesList) if len(episodesList) > 0 else 1) if pagesDone == 0: thisDialog.dialogeBG.update( int(step), "Initialisation of TV-Shows: " + stringUtils.getStrmname(strm_name)) else: thisDialog.dialogeBG.update( int(step), "Page: %d %s" % (pagesDone, stringUtils.getStrmname(strm_name))) for index, episode in enumerate(episodesList): pagesDone = getEpisode(episode, strm_name, strm_type, pagesDone=pagesDone) thisDialog.dialogeBG.update(int(step * (index + 1))) except: guiTools.infoDialog("Unexpected error: " + str(sys.exc_info()[1]) + (". See your Kodi.log!")) utils.addon_log(("Unexpected error: ") + str(sys.exc_info()[1])) print("Unexpected error:"), sys.exc_info()[0] raise pagesDone += 1 episodesList = [] showList = [] if pagesDone < int(PAGINGTVshows) and len(dirList) > 0: showList = [item for sublist in dirList for item in sublist] dirList = []
pagesDone += 1 contentList = [] if pagesDone < int(PAGINGalbums) and len(dirList) > 0: contentList = [item for sublist in dirList for item in sublist] dirList = [] if False: try: urlUtils.downloadThumb( aThumb, album, os.path.join(STRM_LOC, strm_type, artist)) except: pass else: albumList.append([ os.path.join(strm_type, stringUtils.getStrmname(strm_name), label), stringUtils.cleanByDictReplacements(label), link ]) pagesDone = int(PAGINGalbums) try: # Write strms for all values in albumList thelist = fileSys.readMediaList(purge=False) for entry in thelist: splits = entry.strip().split('|') splitsstrm = splits[0] splitsname = splits[1] if splitsstrm.find('Album') != -1 and splitsname.find( strm_name) != -1: url = splits[2]