Media Index Files Scanner

Can someone help me to write a scanner to copy bif files from movie folder to media folder and add make it available to plex.

I tried it myself trying to adapt the LocalMedia Bundle. But i get problems with media not defined, no idea how to check for index file in movie folder or how to get the destination folder from hash and copy files. And at least how to add it so Plex can see it. My first try was just copy manual the file into the correct folder but Plex could not see the index file.

Would be great if a plex guru can write a short script or just some snippets to help me starting this.

Check my signature for REMIdx…

Currently not working though, since the bifs it generate is out of sync, but you should be able to grap the rest from it.

/T

@dane22 thanks for your answer and code to use.

I really try to understand the code but i am no python developer.

I append what i have from copied from your code. It is easier to learn when i see output from your code. But i can not get it work. I get errors from line 29, the media part. But i do not understand why this is an error. Yes i know that a function like you have is better but i just try to get it work before make it nice.

I read your code and there are some things i do not understand, how can i get the folder of the movie destination, check for the bif file and copy it to the media folder. And the part where you add it to the database. I see you call the PMS Url with a parameter of a function i can not understand. How can i use that for my function?

Sorry about this noob questions but python is not my language. :wink: I am better in PHP and Javascript.

@Skycryer said:
I append what i have from copied from your code. It is easier to learn when i see output from your code. But i can not get it work. I get errors from line 29, the media part.

Media is an object, so it’s not to log

@Skycryer said:
i do not understand, how can i get the folder of the movie destination

Bif file location is generated in line 41

myIdxFile = os.path.join(Core.app_support_path, 'Media', 'localhost', myMediaHash[:1], myMediaHash[1:] + '.bundle', 'Contents', 'Indexes', 'index-sd.bif')

After the bif file is present, I call Analyse for the movie, using this function:

def Add2Db(myMediaID): opener = urllib2.build_opener(urllib2.HTTPHandler) #Enable Index Generation request = urllib2.Request('http://127.0.0.1:32400/:/prefs?GenerateIndexFilesDuringAnalysis=1') request.get_method = lambda: 'PUT' url = opener.open(request) #Analyze media request = urllib2.Request('http://127.0.0.1:32400/library/metadata/' + myMediaID + '/analyze') request.get_method = lambda: 'PUT' url = opener.open(request) #Disable Indexing request = urllib2.Request('http://127.0.0.1:32400/:/prefs?GenerateIndexFilesDuringAnalysis=0') request.get_method = lambda: 'PUT' url = opener.open(request)

In above, I switch PMS to generate an index file during analysing
Then I call analyse for the media
Then I switch PMS to not generate index files again

Best Regards

Tommy

Ah ok, so i removed the Log media line but then i get an error for mediaID = media.id (IndentationError: expected an indented block) i do not understand.

For the bif file i do not need to generate a path i think. I just need to check the movie folder for an index-sd.bif file. And if there is such a file copy it to the media (hash.bundle) folder. But how to i get the movie folder path and check for that file?

@Skycryer said:
Ah ok, so i removed the Log media line but then i get an error for mediaID = media.id (IndentationError: expected an indented block) i do not understand.

Python use indent(Tab) as a way to gather code lines together in groups.

Like:
def update(self, metadata, media, lang, force): #Start to work #GetMediaInfoMovie(media.id, media.title) Log.Debug(media) mediaID = media.id myTitle = media.title Log.Debug('Checking Movie media with an ID of : %s, and a title of : %s' %(mediaID, myTitle)) myURL = 'http://' + Prefs['This_PMS_IP'] + ':' + Prefs['This_PMS_Port'] #Get the hash myNewURL = myURL + '/library/metadata/' + mediaID + '/tree' sections = XML.ElementFromURL(myNewURL).xpath('//MediaPart') for section in sections: myMediaHash = section.get('hash') Log.Debug('The hash for media %s is %s' %(mediaID, myMediaHash)) # Does an index already exists? myIdxFile = os.path.join(Core.app_support_path, 'Media', 'localhost', myMediaHash[:1], myMediaHash[1:] + '.bundle', 'Contents', 'Indexes', 'index-sd.bif') Log.Debug('myIdxFile is : ' + myIdxFile) if os.path.isfile(myIdxFile): Log.Debug('Index exists for : %s with ID: %s, so skipping' %(myTitle, mediaID)) else: Log.Debug('ID: %s - Index is missing for : %s' %(mediaID, myTitle)) #Get media info myNewURL = myURL + '/library/metadata/' + mediaID # Grap the Section ID MediaContainer = XML.ElementFromURL(myNewURL) Log(MediaContainer)

Should instead be:
def update(self, metadata, media, lang, force): <insert tab here>#Start to work <insert tab here>#GetMediaInfoMovie(media.id, media.title) <insert tab here>Log.Debug(media) <insert tab here>mediaID = media.id

and so on

For the bif file i do not need to generate a path i think. I just need to check the movie folder for an index-sd.bif file. And if there is such a file copy it to the media (hash.bundle) folder. But how to i get the movie folder path and check for that file?

Check my signature for SRT2UTF-8, where I access the media folder :wink:

Thanks for all that info, helped me a lot, but now i have 2 new questions someone can hopefully help me with.

  1. How can i copy the index-sd.bif file from my movie folder to the destination folder? I have the source and destination path. But with the url thing from remidx or copy it is not working. Maybe copy is not working because of folder permissions. But i do not know how dto deal with it. I am under WIndows and want to build it so it will work on Linux and OSX too.

  2. I generate the token i need to communicate with the server to call the http://127.0.0.1:32400/:/prefs?GenerateIndexFilesDuringAnalysis=0. Direct opening in Url gives 401 because of token needed. But how can i call the url with the generated token. Could not find a sample.

How you know what i mean and can help me. If needed i can give access to me code.

Edit:
I added what i have until now (early dev, first python steps) to github