Mark Folder plugin for Plex / add to database
#1
I am a recent Apple convertie who got over from PC just recently, 1 year about. In windows I used a selfmade script (vbscript) to tag folders of which episodes I have been watching and it also sent the foldername to a database so I could keep track even if I deleted the episode from the disk. What the script did by a contextmenubutton was to change the icon of the folder by putting in a desktop.ini file in the folder telling it to display another icon (in this case a cross). Then it did a http-request to a site with the foldername as parameter for store in an Accessdatabase. I now wonder if I could make the same thing work but with a plugin for XBMC?

Basicaly what I want to do is a plugin that...

1. Lists folders within given SMB-shares
2. Check subfolders for desktop.ini file
a. if the file is there show a cross
b. if the folder is not there show a normal foldericon
3. Then there needs to be a shortcut/button/option to tag the folder after successfull watching

Tagging the folder should do the following

1. Create a desktop.ini file in the folder
2. Submit the foldername via HTTP-request


Is the above possible with XBMC's Plugin API or would I possibly need to make a webservice to serve as backend?

Image
Reply
#2
Potentially this is possible I think, yes. First off you need to list the shares. Not sure the best way to go about this with smb - it may be easier to mount the drives using the OS so as far as python goes they're local.

Then it's just a basic matter of checking for the desktop.ini and setting the thumbnail appropriately.

Finally, adding a context menu item is doable for a plugin and you can create the file and send off your http request.

Note that you're on the forums for XBMC. Plex is a fork that has nothing to do with us other than that they use our code. Note that Plex has ditched our plugin API (or at least it's unsupported) so if you want to use that you'll have to ask over there.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
Yah, but i guess since there were no answers on plex forum and the fact that they're support for scripts are a bit limited I will instead go about using XBMC on both my MAC and my HTPC (windows 8). It's very nice to hear that this is indeed possible, I have no experience with python but then again it's a simple language so it should be doable...Thanks for your response you gave me hope and clear insight...I'll post it here when it's finished if someone else needs it or it could work as an example Wink
Reply
#4
Windows 8? Do you work for Microsoft or something then? ;-)
Reply
#5
Sure enough, referring to your nick, your smart enough to draw your own accurate conclusion Wink
Reply
#6
I have been reading up and doing some testing tonight....New to python doesn't seem to pose any eminent harm at this time. Although I realised I have two ways to do this....Easy and hard....where as hard is beautiful.

1. (easy). Create a script that lists all folder from a webservice and gets all the info, icons and path to videofile. Then all there is left is to list foldercontents like any other script and add a B-button action to send the http-response and let the PHP-script there create the desktop.ini and tag the folder.

2. (hard). Do all the coding in python and skip the webservice alltogether except for submition of Watched Episode to database.


However I do wonder how to list XBMC array of current Sources and dump them in a container where as one can browser folders just like "Video" on the homescreen menu. Are there any examplescripts of this?

Gone through the whole vicki but found nothing of relevance...some hint / help would be appreciated.
Reply
#7
Ok I got as far as listing all folders, making those with desktop.ini red and finally made it possible to play with filtering everything out but videofiles from the SMB-browser. Then I added two actions for A and B to play and mark.

However I do wonder how to get current list of SMB shares from the ones I add under Videos?
Reply
#8
One option is to try and grab them via the jsonrpc interface perhaps? Nasty alternatives are loading sources.xml and parsing that yourself, though ofcourse that could break at any time should we decide to change the layout.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#9
Actualy this JSON-RPC can come in handy for other projects but as of now I really do consider using the least reliable version, ie parsing sources.xml. But I am quite confident that future versions of XBMC will brake scripts in some way so no matter what it is one has to update when that time comes. Thanks for the tip!
Reply
#10
I got another idea, maybe one could you http getshares from XBMC http api to get a list of shares then it will be a bit of coding to get multipath to work but I am eager to do that to...Wink

What ´do you guys think of that? Possible solution?
Reply
#11
OK got the code together and it worked good for a few weeks. But now all of a sudden it started acting up on all of my computers. After watching and marking/watched-checking a few movies I get script error which is not going away until I restart XBMC. It doesn't help just exiting the script out to the root of videos in xbmc then entering addons again and the error is still there. Is anyone able to see any direct flaws in the code?


--------------------------- CODE -------------------------------


import os #Used to access host file system
import os.path
import xbmcplugin #Used to interface with XBMC
import xbmcgui #Used for XBMC gui
import urllib #Used for URL handling
import urllib2

def listFolderContent(rootFolder):
folderContents = os.listdir(rootFolder)

#for each entry in the directory listing, create a listitem, then add it to XBMC (noting the check to see if it's a dir or not)
#if the entry IS a folder, then reuse this plugin as the URL, with the new root folder as a parameter
sz = len(folderContents)
mediaVideos = xbmc.getSupportedMedia("video")
found = 0
for entries in folderContents:
url = os.path.join(rootFolder,entries)
url2 = os.path.join(url,"desktop.ini")
isDir = os.path.isdir(url)
isFile = os.path.isfile(url2)
if entries.lower() <> "sample":
if isDir and isFile:
url = sys.argv[0] + "?path=" + url + "\\"
liz=xbmcgui.ListItem("[color=FFFF0000]"+entries+"[/color]",iconImage="DefaultVideo.png")
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir,sz)
elif isDir:
url = sys.argv[0] + "?path=" + url + "\\"
liz=xbmcgui.ListItem(entries,'')
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir,sz)
else:
ext = os.path.splitext(entries)[1].lower()
if ext in mediaVideos:
liz=xbmcgui.ListItem(entries,'')
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir,sz)
found = 1
if found:
url = sys.argv[0] + "?a=" + rootFolder + "\\"
liz=xbmcgui.ListItem("-- Archive",'')
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,0)
url = sys.argv[0] + "?m=" + rootFolder + "\\"
liz=xbmcgui.ListItem("-- Mark",'')
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,0)
url = sys.argv[0] + "?u=" + rootFolder + "\\"
liz=xbmcgui.ListItem("-- Unmark",'')
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,0)
url = sys.argv[0] + "?w=" + rootFolder + "\\"
liz=xbmcgui.ListItem("-- Watched",'')
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,0)
xbmcplugin.endOfDirectory(int(sys.argv[1]), 1)
return (0)


#list the available drives on the host PC
def listDrives():
if (sys.platform == 'darwin'):
shares = os.listdir("/volumes")
for share in shares:
drive = "/volumes/"+share
liz=xbmcgui.ListItem(share,'')
url = sys.argv[0] + "?path=" + drive + "\\"
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,1)
elif (sys.platform == 'win32'):
for i in range(ord('a'), ord('z')+1):
drive = chr(i) + ":\\"
if os.path.exists(drive):
liz=xbmcgui.ListItem(drive,'')
url = sys.argv[0] + "?path=" + drive + "\\"
xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,1)
xbmcplugin.endOfDirectory(int(sys.argv[1]), 1)
return(0)


#If a path has been supplied as a parameter, then use that as the root folder to browse, otherwise, start from a list of drives
if cmp (sys.argv[2][0:6],"?path=") == 0:
listFolderContent(sys.argv[2][6:])
elif cmp (sys.argv[2][0:3],"?a=") == 0 or cmp (sys.argv[2][0:3],"?m=") == 0 or cmp (sys.argv[2][0:3],"?u=") == 0 or cmp (sys.argv[2][0:3],"?w=") == 0:
dialog = xbmcgui.Dialog()
if dialog.yesno("Confirmation", "Are you sure?"):
pageUrl = "http://10.0.0.7/commit.asp"+sys.argv[2][0:3]+urllib.quote_plus(sys.argv[2][3:])
f=urllib2.urlopen(pageUrl)
a=f.read()
f.close()
if a != "":
dialog = xbmcgui.Dialog()
ok = dialog.ok('Status', a)
else:
listDrives()
Reply
#12
This is the Debug Log of the error that happens sometimes after I played a movie or move to quickly in the menues for a while. I don't at all understand the errormessage, anyone can help?


01:56:03 T:608 M:1606332416 NOTICE: -->Python Interpreter Initialized<--
01:56:03 T:608 M:1606332416 DEBUG: XBPyThread:Tonguerocess - The source file to load is C:\Program Files (x86)\XBMC\addons\MarkFolder.xayide.com\default.py
01:56:03 T:608 M:1606332416 DEBUG: XBPyThread:Tonguerocess - Setting the Python path to C:\Program Files (x86)\XBMC\addons\MarkFolder.xayide.com;C:\Program Files (x86)\XBMC\addons\script.module.pil\lib;C:\Program Files (x86)\XBMC\addons\script.module.pysqlite\lib;special://xbmc/system/python/Lib;special://xbmcbin/system/python/python24.zip;special://xbmc/system/python\DLLs;special://xbmc/system/python\lib;special://xbmc/system/python\lib\plat-win;special://xbmc/system/python\lib\lib-tk;C:\Program Files (x86)\XBMC
01:56:03 T:608 M:1606332416 DEBUG: XBPyThread:Tonguerocess - Entering source directory C:\Program Files (x86)\XBMC\addons\MarkFolder.xayide.com
01:56:03 T:608 M:1606348800 ERROR: Stat: fd == -1
01:56:03 T:608 M:1606348800 INFO: -->Python script returned the following error<--
01:56:03 T:608 M:1606348800 ERROR: Error Type: exceptions.RuntimeError
01:56:03 T:608 M:1606348800 ERROR: Error Contents: unable to get modification time from 'special://xbmc/system/python/Lib\tempfile.py'
01:56:03 T:608 M:1606344704 ERROR: Stat: fd == -1
01:56:03 T:608 M:1606336512 ERROR: Previous line repeats 1 times.
01:56:03 T:608 M:1606336512 INFO: -->End of Python script error report<--
01:56:03 T:608 M:1606336512 ERROR: Stat: fd == -1
01:56:03 T:608 M:1606336512 NOTICE: Traceback (most recent call last):
01:56:03 T:608 M:1606336512 NOTICE: File "<string>", line 1, in ?
01:56:03 T:608 M:1606336512 NOTICE: RuntimeError
01:56:03 T:608 M:1606336512 NOTICE: :
01:56:03 T:608 M:1606336512 NOTICE: unable to get modification time from 'special://xbmc/system/python/Lib\threading.py'
01:56:03 T:608 M:1606336512 INFO: Python script stopped
01:56:03 T:608 M:1606336512 DEBUG: Thread 608 terminating
01:56:03 T:1144 M:1606332416 DEBUG: XFILE::CPluginDirectory::WaitOnScriptResult - plugin exited prematurely - terminating
01:56:03 T:1144 M:1606332416 ERROR: XFILE::CDirectory::GetDirectory - Error getting plugin://MarkFolder.xayide.com/?path=x://[HDTV] - NATIONAL_GEOGRAPHIC_720P\National.Geographic.Big.Bigger.Biggest.Tunnel.720p.HDTV.x264-TESTHD/
01:56:03 T:1144 M:1606332416 ERROR: CGUIMediaWindow::GetDirectory(plugin://MarkFolder.xayide.com/?path=x://[HDTV] - NATIONAL_GEOGRAPHIC_720P\National.Geographic.Big.Bigger.Biggest.Tunnel.720p.HDTV.x264-TESTHD/) failed
01:56:03 T:1144 M:1606332416 DEBUG: python thread 21 destructed
Reply

Logout Mark Read Team Forum Stats Members Help
Mark Folder plugin for Plex / add to database0