def getPlayListSimpleAudio(playListItem, myRow): ''' This function will export and return the simple info for the Playlist for audio types ''' # Get the Playlist ItemID myRow['Playlist ItemID'] = misc.GetRegInfo(playListItem, 'playlistItemID') # Get the media ID myRow['Media ID'] = misc.GetRegInfo(playListItem, 'ratingKey') # Get media type myRow['Type'] = misc.GetRegInfo(playListItem, 'type') # Get media title myRow['Title'] = misc.GetRegInfo(playListItem, 'title') # Get Artist name myRow['Artist'] = misc.GetRegInfo(playListItem, 'grandparentTitle', 'N/A') # Get Album name myRow['Album'] = misc.GetRegInfo(playListItem, 'parentTitle', 'N/A') # Get Summary myRow['Summary'] = misc.GetRegInfo(playListItem, 'summary', 'N/A') # Get year myRow['Year'] = misc.GetRegInfo(playListItem, 'year', 'N/A') # Get Artist name myRow['Original Title'] = misc.GetRegInfo(playListItem, 'originalTitle', 'N/A') # Grab the FileName(s) myRow['File Name'] = getFileNamesFromObject(playListItem) # Get Duration myRow['Duration'] = misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'duration', '0')).encode('utf8') return myRow
def scanMovieDB(myMediaURL, outFile): Log.Debug("******* Starting scanMovieDB with an URL of %s ***********" % (myMediaURL)) Log.Debug('Movie Export level is %s' % (Prefs['Movie_Level'])) global bScanStatusCount global bScanStatusCountOf global bScanStatus bScanStatusCount = 0 bScanStatusCountOf = 0 iCurrent = 0 try: Log.Debug("About to open file %s" % (outFile)) output.createHeader(outFile, 'movies') if Prefs['Movie_Level'] in moviefields.singleCall: bExtraInfo = False else: bExtraInfo = True while True: Log.Debug("Walking medias") fetchURL = myMediaURL + '?X-Plex-Container-Start=' + str( iCurrent) + '&X-Plex-Container-Size=' + str( CONTAINERSIZEMOVIES) iCount = bScanStatusCount partMedias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT)) if bScanStatusCount == 0: bScanStatusCountOf = partMedias.get('totalSize') Log.Debug('Amount of items in this section is %s' % bScanStatusCountOf) # HERE WE DO STUFF Log.Debug("Retrieved part of medias okay [%s of %s]" % (str(bScanStatusCount), str(bScanStatusCountOf))) medias = partMedias.xpath('.//Video') for media in medias: myRow = {} # Was extra info needed here? if bExtraInfo: myExtendedInfoURL = genParam( misc.GetLoopBack() + '/library/metadata/' + misc.GetRegInfo(media, 'ratingKey')) media = XML.ElementFromURL( myExtendedInfoURL, timeout=float(PMSTIMEOUT)).xpath('//Video')[0] # Export the info myRow = movies.getMovieInfo(media, myRow) output.writerow(myRow) iCurrent += 1 bScanStatusCount += 1 Log.Debug("Media #%s from database: '%s'" % (str(iCurrent), misc.GetRegInfo(media, 'title'))) # Got to the end of the line? if int(partMedias.get('size')) == 0: break if bScanStatus == 3: break output.closefile() except ValueError, Argument: Log.Critical('Unknown error in scanMovieDb %s' % (Argument)) bScanStatus = 99 raise
def getPlayListSimpleVideo(playListItem, myRow): ''' This function will export and return the simple info for the Playlist for video types ''' # Get the Playlist ItemID myRow['Playlist ItemID'] = misc.GetRegInfo(playListItem, 'playlistItemID') # Get the media ID myRow['Media ID'] = misc.GetRegInfo(playListItem, 'ratingKey') # Get media type myRow['Type'] = misc.GetRegInfo(playListItem, 'type') # Get media title myRow['Title'] = misc.GetRegInfo(playListItem, 'title') # Get TV-Show name myRow['TV-Show'] = misc.GetRegInfo(playListItem, 'grandparentTitle', 'N/A') # Get Rating myRow['Rating'] = misc.GetRegInfo(playListItem, 'rating', 'N/A') # Get Summary myRow['Summary'] = misc.GetRegInfo(playListItem, 'summary', 'N/A') # Get year myRow['Year'] = misc.GetRegInfo(playListItem, 'year', 'N/A') # Get studio myRow['Studio'] = misc.GetRegInfo(playListItem, 'studio', 'N/A') # Get Duration myRow['Duration'] = misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'duration', '0')).encode('utf8') # Grab the FileName(s) myRow['File Name'] = getFileNamesFromObject(playListItem) return myRow
def getPlayListBasicPhoto(playListItem, myRow): # Get Originally Available At myRow['Originally Available At'] = misc.GetRegInfo(playListItem, 'originallyAvailableAt', 'N/A') # Get Added At myRow['Added At'] = misc.ConvertDateStamp(misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') # Get Updated At myRow['Updated At'] = misc.ConvertDateStamp(misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') return myRow
def getPlayListBasicAudio(playListItem, myRow): # Get Rating count myRow['Rating Count'] = misc.GetRegInfo(playListItem, 'ratingCount', 'N/A') # Get Added At myRow['Added At'] = misc.ConvertDateStamp(misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') # Get Updated At myRow['Updated At'] = misc.ConvertDateStamp(misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') # Grab the FileName(s) myRow['File Name'] = getFileNamesFromObject(playListItem) return myRow
def getPlayListBasicAudio(playListItem, myRow): # Get Rating count myRow['Rating Count'] = misc.GetRegInfo(playListItem, 'ratingCount', 'N/A') # Get Duration myRow['Duration'] = misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'duration', '0')).encode('utf8') # Get Added At myRow['Added At'] = misc.ConvertDateStamp(misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') # Get Updated At myRow['Updated At'] = misc.ConvertDateStamp(misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') return myRow
def getPlayListBasicVideo(playListItem, myRow): ''' This function will export and return the basic info for the Playlist for movie/tv-shows types ''' # Get Studio myRow['Studio'] = misc.GetRegInfo(playListItem, 'studio', 'N/A') # Get Content Rating myRow['Content Rating'] = misc.GetRegInfo(playListItem, 'contentRating', 'N/A') # Get Tagline myRow['Tagline'] = misc.GetRegInfo(playListItem, 'tagline', 'N/A') # Get Duration myRow['Duration'] = misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'duration', '0')).encode('utf8') # Get Originally Available At myRow['Originally Available At'] = misc.GetRegInfo( playListItem, 'originallyAvailableAt', 'N/A') # Get Added At myRow['Added At'] = misc.ConvertDateStamp( misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') # Get Updated At myRow['Updated At'] = misc.ConvertDateStamp( misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') return myRow
def scanMovieDB(myMediaURL, myCSVFile): Log.Debug("******* Starting scanMovieDB with an URL of %s ***********" %(myMediaURL)) Log.Debug('Movie Export level is %s' %(Prefs['Movie_Level'])) global bScanStatusCount global bScanStatusCountOf global bScanStatus bScanStatusCount = 0 bScanStatusCountOf = 0 iCurrent = 0 try: Log.Debug("About to open file %s" %(myCSVFile)) csvfile = io.open(myCSVFile,'wb') # Create output file, and print the header csvwriter = csv.DictWriter(csvfile, fieldnames=movies.getMovieHeader(Prefs['Movie_Level']), delimiter=Prefs['Delimiter'], quoting=csv.QUOTE_NONNUMERIC) Log.Debug("Writing header") csvwriter.writeheader() if Prefs['Movie_Level'] in moviefields.singleCall: bExtraInfo = False else: bExtraInfo = True while True: Log.Debug("Walking medias") fetchURL = myMediaURL + '?X-Plex-Container-Start=' + str(iCurrent) + '&X-Plex-Container-Size=' + str(consts.CONTAINERSIZEMOVIES) iCount = bScanStatusCount partMedias = XML.ElementFromURL(fetchURL) if bScanStatusCount == 0: bScanStatusCountOf = partMedias.get('totalSize') Log.Debug('Amount of items in this section is %s' %bScanStatusCountOf) # HERE WE DO STUFF Log.Debug("Retrieved part of medias okay [%s of %s]" %(str(bScanStatusCount), str(bScanStatusCountOf))) medias = partMedias.xpath('.//Video') for media in medias: myRow = {} # Was extra info needed here? if bExtraInfo: myExtendedInfoURL = misc.GetLoopBack() + '/library/metadata/' + misc.GetRegInfo(media, 'ratingKey') + '?includeExtras=1' if Prefs['Check_Files']: myExtendedInfoURL = myExtendedInfoURL + '&checkFiles=1' media = XML.ElementFromURL(myExtendedInfoURL).xpath('//Video')[0] # Export the info myRow = movies.getMovieInfo(media, myRow, csvwriter) csvwriter.writerow(myRow) iCurrent += 1 bScanStatusCount += 1 Log.Debug("Media #%s from database: '%s'" %(str(iCurrent), misc.GetRegInfo(media, 'title'))) # Got to the end of the line? if int(partMedias.get('size')) == 0: break csvfile.close except ValueError, Argument: Log.Critical('Unknown error in scanMovieDb %s' %(Argument)) bScanStatus = 99 raise
def scanArtistDB(myMediaURL, myCSVFile): Log.Debug("******* Starting scanArtistDB with an URL of %s ***********" % (myMediaURL)) global bScanStatusCount global bScanStatusCountOf global bScanStatus bScanStatusCount = 0 try: mySepChar = Prefs['Seperator'] Log.Debug('Writing headers for Audio Export') csvfile = io.open(myCSVFile, 'wb') csvwriter = csv.DictWriter(csvfile, fieldnames=audio.getMusicHeader( Prefs['Artist_Level']), delimiter=Prefs['Delimiter'], quoting=csv.QUOTE_NONNUMERIC) csvwriter.writeheader() if Prefs['Artist_Level'] in audiofields.singleCall: bExtraInfo = False else: bExtraInfo = True Log.Debug('Starting to fetch the list of items in this section') fetchURL = myMediaURL + '?type=10&X-Plex-Container-Start=' + str( bScanStatusCount) + '&X-Plex-Container-Size=0' medias = XML.ElementFromURL(fetchURL) if bScanStatusCount == 0: bScanStatusCountOf = medias.get('totalSize') Log.Debug('Amount of items in this section is %s' % bScanStatusCountOf) Log.Debug("Walking medias") while True: fetchURL = myMediaURL + '?type=10&sort=artist.titleSort,album.titleSort:asc&X-Plex-Container-Start=' + str( bScanStatusCount) + '&X-Plex-Container-Size=' + str( consts.CONTAINERSIZEAUDIO) medias = XML.ElementFromURL(fetchURL) if medias.get('size') == '0': break # HERE WE DO STUFF tracks = medias.xpath('.//Track') for track in tracks: bScanStatusCount += 1 # Get the Audio Info myRow = {} # Was extra info needed here? if bExtraInfo: myExtendedInfoURL = misc.GetLoopBack( ) + '/library/metadata/' + misc.GetRegInfo( track, 'ratingKey') + '?includeExtras=1' if Prefs['Check_Files']: myExtendedInfoURL = myExtendedInfoURL + '&checkFiles=1' track = XML.ElementFromURL(myExtendedInfoURL).xpath( '//Track')[0] audio.getAudioInfo(track, myRow) csvwriter.writerow(myRow) csvfile.close except: Log.Critical("Detected an exception in scanArtistDB") bScanStatus = 99 raise # Dumps the error so you can see what the problem is Log.Debug("******* Ending scanArtistDB ***********")
def scanArtistDB(myMediaURL, outFile, level=None): ''' This function will scan a Music section.''' Log.Debug("*** Starting scanArtistDB with an URL of %s ***" % myMediaURL) global bScanStatusCount global bScanStatusCountOf global bScanStatus bScanStatusCount = 0 try: Log.Debug('Writing headers for Audio Export') output.createHeader(outFile=outFile, sectionType='audio', level=level) if level in audiofields.singleCall: bExtraInfo = False else: bExtraInfo = True Log.Debug('Starting to fetch the list of items in this section') fetchURL = ''.join((myMediaURL, '?type=10&X-Plex-Container-Start=', str(bScanStatusCount), '&X-Plex-Container-Size=0')) medias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT)) if bScanStatusCount == 0: bScanStatusCountOf = medias.get('totalSize') output.setMax(int(bScanStatusCountOf)) Log.Debug('Amount of items in this section is %s' % bScanStatusCountOf) Log.Debug("Walking medias") while True: fetchURL = ''.join( (myMediaURL, '?type=10&sort=artist.titleSort,album.titleSort:', 'asc&X-Plex-Container-Start=', str(bScanStatusCount), '&X-Plex-Container-Size=', str(CONTAINERSIZEAUDIO))) medias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT)) if medias.get('size') == '0': break # HERE WE DO STUFF tracks = medias.xpath('.//Track') for track in tracks: bScanStatusCount += 1 # Get the Audio Info myRow = {} # Was extra info needed here? if bExtraInfo: myExtendedInfoURL = genParam(''.join( (misc.GetLoopBack(), '/library/metadata/', misc.GetRegInfo(track, 'ratingKey')))) track = XML.ElementFromURL( myExtendedInfoURL, timeout=float(PMSTIMEOUT)).xpath('//Track')[0] audio.getAudioInfo(track, myRow, level=level) output.writerow(myRow) output.closefile() except Exception, e: Log.Exception("Detected an exception in scanArtistDB as: %s" % str(e)) bScanStatus = 99 # Dumps the error so you can see what the problem is raise
def getPlayListBasicPhoto(playListItem, myRow): ''' This function will export and return the basic info for the Playlist for photo types ''' # Get Originally Available At myRow['Originally Available At'] = misc.GetRegInfo( playListItem, 'originallyAvailableAt', 'N/A') # Get Added At myRow['Added At'] = misc.ConvertDateStamp( misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') # Get Updated At myRow['Updated At'] = misc.ConvertDateStamp( misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') return myRow
def scanArtistDB(myMediaURL, outFile): Log.Debug("******* Starting scanArtistDB with an URL of %s ***********" % (myMediaURL)) global bScanStatusCount global bScanStatusCountOf global bScanStatus bScanStatusCount = 0 try: Log.Debug('Writing headers for Audio Export') output.createHeader(outFile, 'audio') if Prefs['Artist_Level'] in audiofields.singleCall: bExtraInfo = False else: bExtraInfo = True Log.Debug('Starting to fetch the list of items in this section') fetchURL = myMediaURL + '?type=10&X-Plex-Container-Start=' + str( bScanStatusCount) + '&X-Plex-Container-Size=0' medias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT)) if bScanStatusCount == 0: bScanStatusCountOf = medias.get('totalSize') Log.Debug('Amount of items in this section is %s' % bScanStatusCountOf) Log.Debug("Walking medias") while True: fetchURL = myMediaURL + '?type=10&sort=artist.titleSort,album.titleSort:asc&X-Plex-Container-Start=' + str( bScanStatusCount) + '&X-Plex-Container-Size=' + str( CONTAINERSIZEAUDIO) medias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT)) if medias.get('size') == '0': break # HERE WE DO STUFF tracks = medias.xpath('.//Track') for track in tracks: bScanStatusCount += 1 # Get the Audio Info myRow = {} # Was extra info needed here? if bExtraInfo: myExtendedInfoURL = genParam( misc.GetLoopBack() + '/library/metadata/' + misc.GetRegInfo(track, 'ratingKey')) track = XML.ElementFromURL( myExtendedInfoURL, timeout=float(PMSTIMEOUT)).xpath('//Track')[0] audio.getAudioInfo(track, myRow) output.writerow(myRow) output.closefile() except: Log.Critical("Detected an exception in scanArtistDB") bScanStatus = 99 raise # Dumps the error so you can see what the problem is Log.Debug("******* Ending scanArtistDB ***********")
def getPlayListBasicAudio(playListItem, myRow): ''' This function will export and return the basic info for the Playlist for audio types ''' # Get Rating count myRow['Rating Count'] = misc.GetRegInfo(playListItem, 'ratingCount', 'N/A') # Get Added At myRow['Added At'] = misc.ConvertDateStamp( misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') # Get Updated At myRow['Updated At'] = misc.ConvertDateStamp( misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp( misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') # Grab the FileName(s) myRow['File Name'] = getFileNamesFromObject(playListItem) return myRow
def getPlayListSimpleVideo(playListItem, myRow): # Get the Playlist ItemID myRow['Playlist ItemID'] = misc.GetRegInfo(playListItem, 'playlistItemID') # Get the media ID myRow['Media ID'] = misc.GetRegInfo(playListItem, 'ratingKey') # Get media type myRow['Type'] = misc.GetRegInfo(playListItem, 'type') # Get media title myRow['Title'] = misc.GetRegInfo(playListItem, 'title') # Get TV-Show name myRow['TV-Show'] = misc.GetRegInfo(playListItem, 'grandparentTitle', 'N/A') # Get Rating myRow['Rating'] = misc.GetRegInfo(playListItem, 'rating', 'N/A') # Get Summary myRow['Summary'] = misc.GetRegInfo(playListItem, 'summary', 'N/A') # Get year myRow['Year'] = misc.GetRegInfo(playListItem, 'year', 'N/A') return myRow
def getPlayListSimpleAudio(playListItem, myRow): # Get the Playlist ItemID myRow['Playlist ItemID'] = misc.GetRegInfo(playListItem, 'playlistItemID') # Get the media ID myRow['Media ID'] = misc.GetRegInfo(playListItem, 'ratingKey') # Get media type myRow['Type'] = misc.GetRegInfo(playListItem, 'type') # Get media title myRow['Title'] = misc.GetRegInfo(playListItem, 'title') # Get Artist name myRow['Artist'] = misc.GetRegInfo(playListItem, 'grandparentTitle', 'N/A') # Get Album name myRow['Album'] = misc.GetRegInfo(playListItem, 'parentTitle', 'N/A') # Get Summary myRow['Summary'] = misc.GetRegInfo(playListItem, 'summary', 'N/A') # Get year myRow['Year'] = misc.GetRegInfo(playListItem, 'year', 'N/A') return myRow
def getPlayListBasicVideo(playListItem, myRow): # Get Studio myRow['Studio'] = misc.GetRegInfo(playListItem, 'studio', 'N/A') # Get Content Rating myRow['Content Rating'] = misc.GetRegInfo(playListItem, 'contentRating', 'N/A') # Get Tagline myRow['Tagline'] = misc.GetRegInfo(playListItem, 'tagline', 'N/A') # Get Duration myRow['Duration'] = misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'duration', '0')).encode('utf8') # Get Originally Available At myRow['Originally Available At'] = misc.GetRegInfo(playListItem, 'originallyAvailableAt', 'N/A') # Get Added At myRow['Added At'] = misc.ConvertDateStamp(misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'addedAt', '0')).encode('utf8') # Get Updated At myRow['Updated At'] = misc.ConvertDateStamp(misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') + ' ' + misc.ConvertTimeStamp(misc.GetRegInfo(playListItem, 'updatedAt', '0')).encode('utf8') return myRow
def getPlayListSimplePhoto(playListItem, myRow): # Get the Playlist ItemID myRow['Playlist ItemID'] = misc.GetRegInfo(playListItem, 'playlistItemID') # Get the media ID myRow['Media ID'] = misc.GetRegInfo(playListItem, 'ratingKey') # Get media type myRow['Type'] = misc.GetRegInfo(playListItem, 'type') # Get media title myRow['Title'] = misc.GetRegInfo(playListItem, 'title') # Get Summary myRow['Summary'] = misc.GetRegInfo(playListItem, 'summary', 'N/A') # Get year myRow['Year'] = misc.GetRegInfo(playListItem, 'year', 'N/A') return myRow
def getPlayListSimplePhoto(playListItem, myRow): ''' This function will export and return the simple info for the Playlist for photo types ''' # Get the Playlist ItemID myRow['Playlist ItemID'] = misc.GetRegInfo(playListItem, 'playlistItemID') # Get the media ID myRow['Media ID'] = misc.GetRegInfo(playListItem, 'ratingKey') # Get media type myRow['Type'] = misc.GetRegInfo(playListItem, 'type') # Get media title myRow['Title'] = misc.GetRegInfo(playListItem, 'title') # Get Summary myRow['Summary'] = misc.GetRegInfo(playListItem, 'summary', 'N/A') # Get year myRow['Year'] = misc.GetRegInfo(playListItem, 'year', 'N/A') # Grab the FileName(s) myRow['File Name'] = getFileNamesFromObject(playListItem) return myRow
def scanShowDB(myMediaURL, outFile): Log.Debug("******* Starting scanShowDB with an URL of %s ***********" %(myMediaURL)) global bScanStatusCount global bScanStatusCountOf global bScanStatus bScanStatusCount = 0 bScanStatusCountOf = 0 try: Log.Debug("About to open file %s" %(outFile)) output.createHeader(outFile, 'tvseries') if Prefs['TV_Level'] in tvfields.singleCall: bExtraInfo = False else: bExtraInfo = True Log.Debug('Starting to fetch the list of items in this section') while True: Log.Debug("Walking medias") iCount = bScanStatusCount if 'Show Only' in Prefs['TV_Level']: fetchURL = myMediaURL + '?X-Plex-Container-Start=' + str(iCount) + '&X-Plex-Container-Size=1' else: fetchURL = myMediaURL + '?X-Plex-Container-Start=' + str(iCount) + '&X-Plex-Container-Size=' + str(CONTAINERSIZETV) partMedias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT)) if bScanStatusCount == 0: bScanStatusCountOf = partMedias.get('totalSize') Log.Debug('Amount of items in this section is %s' %bScanStatusCountOf) # HERE WE DO STUFF Log.Debug("Retrieved part of medias okay [%s of %s]" %(str(iCount), str(bScanStatusCountOf))) for TVShow in partMedias: bScanStatusCount += 1 iCount += 1 ratingKey = TVShow.get("ratingKey") title = TVShow.get("title") if 'Show Only' in Prefs['TV_Level']: myRow = {} # Export the info myRow = tvseries.getShowOnly(TVShow, myRow, Prefs['TV_Level']) try: output.writerow(myRow) except Exception, e: Log.Exception('Exception happend in ScanShowDB: %s' %str(e)) continue else: if Prefs['TV_Level'] in ['Level 2','Level 3', 'Level 4', 'Level 5', 'Level 6', 'Level 7', 'Level 8', 'Level 666']: myURL = misc.GetLoopBack() + '/library/metadata/' + ratingKey tvSeriesInfo = XML.ElementFromURL(myURL, timeout=float(PMSTIMEOUT)) # Getting stuff from the main TV-Show page # Grab collections serieInfo = tvSeriesInfo.xpath('//Directory/Collection') myCol = '' for collection in serieInfo: if myCol == '': myCol = collection.get('tag') else: myCol = myCol + Prefs['Seperator'] + collection.get('tag') if myCol == '': myCol = 'N/A' # Grab locked fields serieInfo = tvSeriesInfo.xpath('//Directory/Field') myField = '' for Field in serieInfo: if myField == '': myField = Field.get('name') else: myField = myField + Prefs['Seperator'] + Field.get('name') if myField == '': myField = 'N/A' # Get size of TV-Show episodeTotalSize = XML.ElementFromURL(misc.GetLoopBack() + '/library/metadata/' + ratingKey + '/allLeaves?X-Plex-Container-Start=0&X-Plex-Container-Size=0', timeout=float(PMSTIMEOUT)).xpath('@totalSize')[0] Log.Debug('Show: %s has %s episodes' %(title, episodeTotalSize)) episodeCounter = 0 baseURL = misc.GetLoopBack() + '/library/metadata/' + ratingKey + '/allLeaves' while True: myURL = baseURL + '?X-Plex-Container-Start=' + str(episodeCounter) + '&X-Plex-Container-Size=' + str(CONTAINERSIZEEPISODES) Log.Debug('Show %s of %s with a RatingKey of %s at myURL: %s with a title of "%s" episode %s of %s' %(iCount, bScanStatusCountOf, ratingKey, myURL, title, episodeCounter, episodeTotalSize)) MainEpisodes = XML.ElementFromURL(myURL, timeout=float(PMSTIMEOUT)) Episodes = MainEpisodes.xpath('//Video') for Episode in Episodes: myRow = {} # Was extra info needed here? if bExtraInfo: myExtendedInfoURL = genParam(misc.GetLoopBack() + '/library/metadata/' + misc.GetRegInfo(Episode, 'ratingKey')) Episode = XML.ElementFromURL(myExtendedInfoURL, timeout=float(PMSTIMEOUT)).xpath('//Video')[0] # Export the info myRow = tvseries.getTvInfo(Episode, myRow) if Prefs['TV_Level'] in ['Level 2','Level 3', 'Level 4', 'Level 5', 'Level 6', 'Level 7', 'Level 8', 'Level 666']: myRow['Collection'] = myCol myRow['Locked Fields'] = myField output.writerow(myRow) episodeCounter += CONTAINERSIZEEPISODES if episodeCounter > int(episodeTotalSize): break # Got to the end of the line? if int(partMedias.get('size')) == 0: break output.closefile()
def scanShowDB(myMediaURL, myCSVFile): Log.Debug("******* Starting scanShowDB with an URL of %s ***********" %(myMediaURL)) global bScanStatusCount global bScanStatusCountOf global bScanStatus bScanStatusCount = 0 bScanStatusCountOf = 0 try: Log.Debug("About to open file %s" %(myCSVFile)) csvfile = io.open(myCSVFile,'wb') # Create output file, and print the header csvwriter = csv.DictWriter(csvfile, fieldnames=tvseries.getTVHeader(Prefs['TV_Level']), delimiter=Prefs['Delimiter'], quoting=csv.QUOTE_NONNUMERIC) Log.Debug("Writing header") csvwriter.writeheader() if Prefs['TV_Level'] in tvfields.singleCall: bExtraInfo = False else: bExtraInfo = True Log.Debug('Starting to fetch the list of items in this section') while True: Log.Debug("Walking medias") iCount = bScanStatusCount fetchURL = myMediaURL + '?X-Plex-Container-Start=' + str(iCount) + '&X-Plex-Container-Size=' + str(consts.CONTAINERSIZETV) partMedias = XML.ElementFromURL(fetchURL, headers=MYHEADER) if bScanStatusCount == 0: bScanStatusCountOf = partMedias.get('totalSize') Log.Debug('Amount of items in this section is %s' %bScanStatusCountOf) # HERE WE DO STUFF Log.Debug("Retrieved part of medias okay [%s of %s]" %(str(iCount), str(bScanStatusCountOf))) AllTVShows = partMedias.xpath('.//Directory') for TVShows in AllTVShows: bScanStatusCount += 1 iCount += 1 ratingKey = TVShows.get("ratingKey") title = TVShows.get("title") if Prefs['TV_Level'] in ['Level 2','Level 3', 'Level 4', 'Level 5', 'Level 6', 'Level 7', 'Level 8', 'Level 666']: # Getting stuff from the main TV-Show page myURL = misc.GetLoopBack() + '/library/metadata/' + ratingKey # Grab collections serieInfo = XML.ElementFromURL(myURL).xpath('//Directory/Collection') myCol = '' for collection in serieInfo: if myCol == '': myCol = collection.get('tag') else: myCol = myCol + Prefs['Seperator'] + collection.get('tag') if myCol == '': myCol = 'N/A' # Grab locked fields serieInfo = XML.ElementFromURL(myURL).xpath('//Directory/Field') myField = '' for Field in serieInfo: if myField == '': myField = Field.get('name') else: myField = myField + Prefs['Seperator'] + Field.get('name') if myField == '': myField = 'N/A' myURL = misc.GetLoopBack() + '/library/metadata/' + ratingKey + '/allLeaves' Log.Debug('Show %s of %s with a RatingKey of %s at myURL: %s with a title of "%s"' %(iCount, bScanStatusCountOf, ratingKey, myURL, title)) MainEpisodes = XML.ElementFromURL(myURL) Episodes = MainEpisodes.xpath('//Video') Log.Debug('Show %s with an index of %s contains %s episodes' %(MainEpisodes.get('parentTitle'), iCount, MainEpisodes.get('size'))) for Episode in Episodes: myRow = {} # Was extra info needed here? if bExtraInfo: myExtendedInfoURL = misc.GetLoopBack() + '/library/metadata/' + misc.GetRegInfo(Episode, 'ratingKey') + '?includeExtras=1' if Prefs['Check_Files']: myExtendedInfoURL = myExtendedInfoURL + '&checkFiles=1' Episode = XML.ElementFromURL(myExtendedInfoURL).xpath('//Video')[0] # Export the info myRow = tvseries.getTvInfo(Episode, myRow) if Prefs['TV_Level'] in ['Level 2','Level 3', 'Level 4', 'Level 5', 'Level 6', 'Level 7', 'Level 8', 'Level 666']: myRow['Collection'] = myCol myRow['Locked Fields'] = myField # Log.Debug("Show %s from database: %s Season %s Episode %s title: %s" %(bScanStatusCount, misc.GetRegInfo(Episode, 'grandparentTitle'), misc.GetRegInfo(Episode, 'parentIndex'), misc.GetRegInfo(Episode, 'index'), misc.GetRegInfo(Episode, 'title'))) csvwriter.writerow(myRow) # Got to the end of the line? if int(partMedias.get('size')) == 0: break csvfile.close except ValueError as err: Log.Debug('Exception happend as %s' %err.args) Log.Debug("******* Ending scanShowDB ***********")