Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- if url == "x:/" or url == "x://":
- isDir = 1
- isFile = 0
- else:
- isDir = os.path.isdir(url)
- url2 = os.path.join(url,"desktop.ini")
- isFile = os.path.isfile(url2)
- if entries.lower() <> "sample" and entries.lower() <> ".ds_store" and entries.lower() <> "$recycle.bin" and entries.lower() <> "system volume information":
- 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)
- elif (sys.platform == 'linux'):
- shares = os.listdir("/mnt")
- for share in shares:
- drive = "/mnt/"+share
- liz=xbmcgui.ListItem(share,'')
- url = sys.argv[0] + "?path=" + drive + "/"
- xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,1)
- else:
- shares = os.listdir("/storage/mount")
- for share in shares:
- drive = "/storage/mount/"+share
- liz=xbmcgui.ListItem(share,'')
- 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/addtodb.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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement