Advertisement
Guest User

Untitled

a guest
Nov 17th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. import os #Used to access host file system
  2. import os.path
  3. import xbmcplugin #Used to interface with XBMC
  4. import xbmcgui #Used for XBMC gui
  5. import urllib #Used for URL handling
  6. import urllib2
  7.  
  8. def listFolderContent(rootFolder):
  9. folderContents = os.listdir(rootFolder)
  10.  
  11. #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)
  12. #if the entry IS a folder, then reuse this plugin as the URL, with the new root folder as a parameter
  13. sz = len(folderContents)
  14. mediaVideos = xbmc.getSupportedMedia("video")
  15. found = 0
  16. for entries in folderContents:
  17. url = os.path.join(rootFolder,entries)
  18. if url == "x:/" or url == "x://":
  19. isDir = 1
  20. isFile = 0
  21. else:
  22. isDir = os.path.isdir(url)
  23. url2 = os.path.join(url,"desktop.ini")
  24. isFile = os.path.isfile(url2)
  25. if entries.lower() <> "sample" and entries.lower() <> ".ds_store" and entries.lower() <> "$recycle.bin" and entries.lower() <> "system volume information":
  26. if isDir and isFile:
  27. url = sys.argv[0] + "?path=" + url + "/"
  28. liz=xbmcgui.ListItem("[COLOR=FFFF0000]"+entries+"[/COLOR]",iconImage="DefaultVideo.png")
  29. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir,sz)
  30. elif isDir:
  31. url = sys.argv[0] + "?path=" + url + "/"
  32. liz=xbmcgui.ListItem(entries,'')
  33. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir,sz)
  34. else:
  35. ext = os.path.splitext(entries)[1].lower()
  36. if ext in mediaVideos:
  37. liz=xbmcgui.ListItem(entries,'')
  38. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,isDir,sz)
  39. found = 1
  40. if found:
  41. url = sys.argv[0] + "?a=" + rootFolder + "/"
  42. liz=xbmcgui.ListItem("-- Archive",'')
  43. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,0)
  44. url = sys.argv[0] + "?m=" + rootFolder + "/"
  45. liz=xbmcgui.ListItem("-- Mark",'')
  46. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,0)
  47. url = sys.argv[0] + "?u=" + rootFolder + "/"
  48. liz=xbmcgui.ListItem("-- Unmark",'')
  49. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,0)
  50. url = sys.argv[0] + "?w=" + rootFolder + "/"
  51. liz=xbmcgui.ListItem("-- Watched",'')
  52. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,0)
  53. xbmcplugin.endOfDirectory(int(sys.argv[1]), 1)
  54. return (0)
  55.  
  56.  
  57. #list the available drives on the host PC
  58. def listDrives():
  59. if (sys.platform == 'darwin'):
  60. shares = os.listdir("/volumes")
  61. for share in shares:
  62. drive = "/volumes/"+share
  63. liz=xbmcgui.ListItem(share,'')
  64. url = sys.argv[0] + "?path=" + drive + "/"
  65. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,1)
  66. elif (sys.platform == 'win32'):
  67. for i in range(ord('a'), ord('z')+1):
  68. drive = chr(i) + ":/"
  69. if os.path.exists(drive):
  70. liz=xbmcgui.ListItem(drive,'')
  71. url = sys.argv[0] + "?path=" + drive + "/"
  72. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,1)
  73. elif (sys.platform == 'linux'):
  74. shares = os.listdir("/mnt")
  75. for share in shares:
  76. drive = "/mnt/"+share
  77. liz=xbmcgui.ListItem(share,'')
  78. url = sys.argv[0] + "?path=" + drive + "/"
  79. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,1)
  80. else:
  81. shares = os.listdir("/storage/mount")
  82. for share in shares:
  83. drive = "/storage/mount/"+share
  84. liz=xbmcgui.ListItem(share,'')
  85. url = sys.argv[0] + "?path=" + drive + "/"
  86. xbmcplugin.addDirectoryItem(int(sys.argv[1]),url,liz,1)
  87. xbmcplugin.endOfDirectory(int(sys.argv[1]), 1)
  88. return(0)
  89.  
  90.  
  91. #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
  92. if cmp (sys.argv[2][0:6],"?path=") == 0:
  93. listFolderContent(sys.argv[2][6:])
  94. 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:
  95. dialog = xbmcgui.Dialog()
  96. if dialog.yesno("Confirmation", "Are you sure?"):
  97. pageUrl = "http://10.0.0.7/addtodb.asp"+sys.argv[2][0:3]+urllib.quote_plus(sys.argv[2][3:])
  98. f=urllib2.urlopen(pageUrl)
  99. a=f.read()
  100. f.close()
  101. if a != "":
  102. dialog = xbmcgui.Dialog()
  103. ok = dialog.ok('Status', a)
  104. else:
  105. listDrives()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement