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") 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) # 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 ***********")
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, timeout=float(consts.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))) AllTVShows = partMedias.xpath('.//Directory') for TVShows in AllTVShows: bScanStatusCount += 1 iCount += 1 ratingKey = TVShows.get("ratingKey") title = TVShows.get("title") if 'Show Only' in Prefs['TV_Level']: myRow = {} # Export the info myRow = tvseries.getShowOnly(TVShows, myRow, Prefs['TV_Level']) iCount += consts.CONTAINERSIZETV - 1 try: csvwriter.writerow(myRow) except Exception, e: Log.Exception('Exception happend in ScanShowDB: ' + 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(consts.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(consts.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(consts.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(consts.PMSTIMEOUT)) Episodes = MainEpisodes.xpath('//Video') 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, timeout=float(consts.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 csvwriter.writerow(myRow) episodeCounter += consts.CONTAINERSIZEEPISODES if episodeCounter > int(episodeTotalSize): break # Got to the end of the line? if int(partMedias.get('size')) == 0: break csvfile.close
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 ***********")
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, timeout=float(consts.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))) AllTVShows = partMedias.xpath('.//Directory') for TVShows in AllTVShows: bScanStatusCount += 1 iCount += 1 ratingKey = TVShows.get("ratingKey") title = TVShows.get("title") if 'Show Only' in Prefs['TV_Level']: myRow = {} # Export the info myRow = tvseries.getShowOnly(TVShows, myRow, Prefs['TV_Level']) iCount += consts.CONTAINERSIZETV - 1 try: csvwriter.writerow(myRow) except Exception, e: Log.Exception('Exception happend in ScanShowDB: ' + 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(consts.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( consts.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( consts.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(consts.PMSTIMEOUT)) Episodes = MainEpisodes.xpath('//Video') 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, timeout=float( consts.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 csvwriter.writerow(myRow) episodeCounter += consts.CONTAINERSIZEEPISODES if episodeCounter > int(episodeTotalSize): break # Got to the end of the line? if int(partMedias.get('size')) == 0: break csvfile.close