示例#1
0
def scanPList(key, outFile):
	Log.Debug("******* Starting scanPList with an URL of: %s" %(key))
	global bScanStatusCount
	global bScanStatusCountOf
	global bScanStatus
	bScanStatusCount = 0
	try:
		# Get playlist type once more
		playListType = XML.ElementFromURL(key + '?X-Plex-Container-Start=0&X-Plex-Container-Size=0', timeout=float(PMSTIMEOUT)).get('playlistType')
		Log.Debug('Writing headers for Playlist Export')
		output.createHeader(outFile, 'playlist', playListType)
		iCount = bScanStatusCount
		Log.Debug('Starting to fetch the list of items in this section')
		myRow = {}
		if playListType == 'video':
			playListItems = XML.ElementFromURL(key, timeout=float(PMSTIMEOUT)).xpath('//Video')
		elif playListType == 'audio':
			playListItems = XML.ElementFromURL(key, timeout=float(PMSTIMEOUT)).xpath('//Track')
		elif playListType == 'photo':
			playListItems = XML.ElementFromURL(key, timeout=float(PMSTIMEOUT)).xpath('//Photo')
		for playListItem in playListItems:
			playlists.getPlayListInfo(playListItem, myRow, playListType)			
			output.writerow(myRow)
		output.closefile()
	except:
		Log.Critical("Detected an exception in scanPList")
		bScanStatus = 99
		raise # Dumps the error so you can see what the problem is
	message = 'All done'
	oc = ObjectContainer(title1='Playlists', no_cache=True, message=message)
	oc.add(DirectoryObject(key=Callback(MainMenu), title="Go to the Main Menu"))
	Log.Debug("******* Ending scanPListDB ***********")
	return oc
示例#2
0
def scanPhotoDB(myMediaURL, outFile):
	Log.Debug("******* Starting scanPhotoDB with an URL of %s ***********" %(myMediaURL))
	global bScanStatusCount
	global bScanStatusCountOf
	global bScanStatus
	bScanStatusCount = 0
	iLocalCounter = 0
	try:
		mySepChar = Prefs['Seperator']
		Log.Debug('Writing headers for Photo Export')
		output.createHeader(outFile, 'photo')
		if Prefs['Photo_Level'] in photofields.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(iLocalCounter) + '&X-Plex-Container-Size=0'
		medias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT))
		bScanStatusCountOf = 'N/A'
		Log.Debug("Walking medias")
		while True:
			fetchURL = myMediaURL + '?X-Plex-Container-Start=' + str(iLocalCounter) + '&X-Plex-Container-Size=' + str(CONTAINERSIZEPHOTO)	
			medias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT))
			if medias.get('size') == '0':
				break
			getPhotoItems(medias, bExtraInfo)
			iLocalCounter += int(CONTAINERSIZEPHOTO)	
		output.closefile()
	except:
		Log.Critical("Detected an exception in scanPhotoDB")
		bScanStatus = 99
		raise # Dumps the error so you can see what the problem is
	Log.Debug("******* Ending scanPhotoDB ***********")
	return
示例#3
0
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
示例#4
0
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
示例#5
0
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 ***********")
示例#6
0
def scanPhotoDB(myMediaURL, outFile, level=None):
    ''' This function will scan a Photo section. '''
    Log.Debug("*** Starting scanPhotoDB with an URL of %s ***" % myMediaURL)
    global bScanStatusCount
    global bScanStatusCountOf
    global bScanStatus
    bScanStatusCount = 0
    iLocalCounter = 0
    try:
        mySepChar = Prefs['Seperator']
        Log.Debug('Writing headers for Photo Export')
        output.createHeader(outFile=outFile, sectionType='photo', level=level)
        if level in photofields.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(iLocalCounter), '&X-Plex-Container-Size=0'))
        medias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT))
        bScanStatusCountOf = 'N/A'
        output.setMax(int(0))
        Log.Debug("Walking medias")
        while True:
            fetchURL = ''.join(
                (myMediaURL, '?X-Plex-Container-Start=', str(iLocalCounter),
                 '&X-Plex-Container-Size=', str(CONTAINERSIZEPHOTO)))
            medias = XML.ElementFromURL(fetchURL, timeout=float(PMSTIMEOUT))
            if medias.get('size') == '0':
                break
            getPhotoItems(medias=medias, bExtraInfo=bExtraInfo, level=level)
            iLocalCounter += int(CONTAINERSIZEPHOTO)
        output.closefile()
    except:
        Log.Critical("Detected an exception in scanPhotoDB")
        bScanStatus = 99
        # Dumps the error so you can see what the problem is
        raise
    Log.Debug("******* Ending scanPhotoDB ***********")
    return
示例#7
0
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()