PageRenderTime 50ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/teh_tools.py

https://github.com/HIGHWAY99/plugin.video.vidics4
Python | 1723 lines | 1663 code | 8 blank | 52 comment | 53 complexity | 5acde5d775ecfcb99403c8669237cd8c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. ### ############################################################################################################
  2. ### #
  3. ### # Project: # teh_tools - by The Highway 2013.
  4. ### # Author: # The Highway
  5. ### # Version: # (ever changing)
  6. ### # Description: # My collection of common tools.
  7. ### #
  8. ### ############################################################################################################
  9. ### ############################################################################################################
  10. __plugin__ = "Vidics4.com"
  11. __authors__ = "The Highway"
  12. plugin_id = "plugin.video.vidics4"
  13. ### ############################################################################################################
  14. ### ############################################################################################################
  15. import xbmc,xbmcplugin,xbmcgui,xbmcaddon,xbmcvfs
  16. try: import requests ### <import addon="script.module.requests" version="1.1.0"/> ###
  17. except: t='' ### See https://github.com/kennethreitz/requests ###
  18. import urllib,urllib2,re,os,sys,htmllib,string,StringIO,logging,random,array,time,datetime
  19. import urlresolver
  20. import copy
  21. try: import json
  22. except ImportError: import simplejson as json
  23. try: import StorageServer
  24. except: import storageserverdummy as StorageServer
  25. cache = StorageServer.StorageServer(plugin_id)
  26. #import SimpleDownloader as downloader
  27. from t0mm0.common.net import Net as net
  28. from t0mm0.common.addon import Addon
  29. from config import *
  30. ### ############################################################################################################
  31. ### ############################################################################################################
  32. ### ### Common Imports ###
  33. ### ######################
  34. ### import shutil, md5, base64, unicodedata, threading, string
  35. ### import resources.lib.common as common
  36. ### import xbmc, xbmcplugin, xbmcgui, xbmcaddon, xbmcvfs, common
  37. ### import os.path, sys, urllib, urllib2, cookielib, string, httplib, socket, random
  38. ### import os, re, math, binascii, datetime, HTMLParser
  39. ### from BeautifulSoup import BeautifulStoneSoup
  40. ### from BeautifulSoup import BeautifulSoup , Tag, NavigableString
  41. ### try: from xml.etree import ElementTree
  42. ### except: from elementtree import ElementTree
  43. ### from xbmcgui import Dialog
  44. ### import copy
  45. ### requests, httplib, urlparse
  46. ### from operator import itemgetter
  47. ### from metahandler import metahandlers
  48. ### from metahandler import metacontainers
  49. ###
  50. ###
  51. ###
  52. ###
  53. ###
  54. ###
  55. ###
  56. ###
  57. ###
  58. ### ############################################################################################################
  59. ### ############################################################################################################
  60. def get_params():
  61. param=[]
  62. paramstring=sys.argv[2]
  63. if len(paramstring)>=2:
  64. params=sys.argv[2]
  65. cleanedparams=params.replace('?','')
  66. if (params[len(params)-1]=='/'):
  67. params=params[0:len(params)-2]
  68. pairsofparams=cleanedparams.split('&')
  69. param={}
  70. for i in range(len(pairsofparams)):
  71. splitparams={}
  72. splitparams=pairsofparams[i].split('=')
  73. if (len(splitparams))==2:
  74. param[splitparams[0]]=splitparams[1]
  75. return param
  76. ### ############################################################################################################
  77. ### ############################################################################################################
  78. cache = StorageServer.StorageServer(plugin_id)
  79. addon = Addon(plugin_id, sys.argv)
  80. local = xbmcaddon.Addon(id=plugin_id)
  81. __settings__ = xbmcaddon.Addon(id=plugin_id)
  82. __home__ = __settings__.getAddonInfo('path')
  83. addonPath = __settings__.getAddonInfo('path')
  84. artPath = addonPath+'/art/' #special://home/addons/plugin.video.theanimehighway/art
  85. if __settings__.getSetting("debug-enable") == "true":debugging=True #if (debugging==True):
  86. else: debugging=False
  87. if __settings__.getSetting("debug-show") == "true": shoDebugging=True #if (showDebugging==True):
  88. else: shoDebugging=False
  89. _debugging=debugging; _shoDebugging=shoDebugging
  90. params=get_params()
  91. ICON = os.path.join(__home__, 'icon.png')
  92. fanart = os.path.join(__home__, 'fanart.jpg')
  93. _addon=Addon(ps('_addon_id'), sys.argv);
  94. def addst(r,s=''): return _addon.get_setting(r) ## Get Settings
  95. def addpr(r,s=''): return _addon.queries.get(r,s) ## Get Params
  96. def cFL(t,c=ps('default_cFL_color')): ### For Coloring Text ###
  97. return '[COLOR '+c+']'+t+'[/COLOR]'
  98. ### ############################################################################################################
  99. ### ############################################################################################################
  100. url=None; urlbac=None; name=None; name2=None; type2=None; favcmd=None; mode=None; scr=None; imgfan=None; show=None; category=None
  101. try: category=urllib.unquote_plus(params["cat"])
  102. except: pass
  103. if category==None: category='Base'
  104. try:
  105. url=urllib.unquote_plus(params["url"])
  106. urlbac=url
  107. except: pass
  108. try: scr=urllib.unquote_plus(params["scr"])
  109. except: pass
  110. try: imgfan=urllib.unquote_plus(params["fan"])
  111. except: pass
  112. try: favcmd=urllib.unquote_plus(params["fav"])
  113. except: pass
  114. try: name=urllib.unquote_plus(params["name"])
  115. except: pass
  116. try: name2=urllib.unquote_plus(params["nm"])
  117. except: pass
  118. try: show=urllib.unquote_plus(params["show"])
  119. except: pass
  120. try: type2=int(params["tp"])
  121. except: pass
  122. try: mode=int(params["mode"])
  123. except: pass
  124. ### ############################################################################################################
  125. ### ############################################################################################################
  126. ICON8 = os.path.join(artPath, 'icon_watchdub.png');ICON7 = os.path.join(artPath, 'icon_dubhappy.png');ICON6 = os.path.join(artPath, 'iconDAOn2.png');ICON5 = os.path.join(artPath, 'iconA44couk.png');ICON4 = os.path.join(artPath, 'icongd.png');ICON3 = os.path.join(artPath, 'iconAPlus.png');ICON2 = os.path.join(artPath, 'iconA44.png');ICON1 = os.path.join(artPath, 'iconAG.png');ICON0 = os.path.join(__home__, 'icon.png')
  127. fanart8 = os.path.join(artPath, 'fanart_watchdub.jpg');fanart7 = os.path.join(artPath, 'fanart_dubhappy.jpg');fanart6 = os.path.join(artPath, 'fanartDAOn2.jpg');fanart5 = os.path.join(artPath, 'fanartA44couk.jpg');fanart4 = os.path.join(artPath, 'fanartgd.jpg');fanart3 = os.path.join(artPath, 'fanartAPlus.jpg');fanart2 = os.path.join(artPath, 'fanartA44.jpg');fanart1 = os.path.join(artPath, 'fanartAG.jpg');fanart0 = os.path.join(__home__, 'fanart.jpg')
  128. if type2==8: #site 8
  129. fanart = os.path.join(artPath, 'fanart_watchdub.jpg');ICON = os.path.join(artPath, 'icon_watchdub.png');mainSite='http://www.watchdub.com/'
  130. elif type2==7: #site 7
  131. fanart = os.path.join(artPath, 'fanart_dubhappy.jpg');ICON = os.path.join(artPath, 'icon_dubhappy.png');mainSite='http://www.dubhappy.eu/'
  132. elif type2==6: #site 6
  133. fanart = os.path.join(artPath, 'fanartDAOn2.jpg');ICON = os.path.join(artPath, 'iconDAOn2.png');mainSite='http://dubbedanimeon.com/'
  134. elif type2==5: #site 5
  135. fanart = os.path.join(artPath, 'fanartA44couk.jpg');ICON = os.path.join(artPath, 'iconA44couk.png');mainSite='http://www.anime44.co.uk/'
  136. if ('-anime' in url) and ('http://' not in url): url = mainSite + 'subanime/' + url
  137. if ('-anime' in url) and ('http://' not in scr) and (artPath not in scr): scr = mainSite + 'subanime/' + scr
  138. if ('-anime' in url) and ('http://' not in imgfan) and (artPath not in imgfan): imgfan = mainSite + 'subanime/' + imgfan
  139. #if ('-anime' not in url) and ('http://' not in url): url = mainSite + 'english-dubbed/' + url
  140. #if ('-anime' not in url) and ('http://' not in scr) and (artPath not in scr): scr = mainSite + 'english-dubbed/' + scr
  141. #if ('-anime' not in url) and ('http://' not in imgfan) and (artPath not in imgfan): imgfan = mainSite + 'english-dubbed/' + imgfan
  142. #if ('alpha-anime' in url): url.replace('alpha-anime','subanime')
  143. #if ('alpha-movies' in url): url.replace('alpha-movies','subanime')
  144. #if ('alpha-anime' in show): show.replace('alpha-anime','subanime')
  145. #if ('alpha-movies' in show): show.replace('alpha-movies','subanime')
  146. elif type2==4: #site 4
  147. fanart = os.path.join(artPath, 'fanartgd.jpg');ICON = os.path.join(artPath, 'icongd.png');mainSite='http://www.gooddrama.net/'
  148. elif type2==3: #site 3
  149. fanart = os.path.join(artPath, 'fanartplus.jpg');ICON = os.path.join(artPath, 'iconplus.png');mainSite='http://www.animeplus.tv/'
  150. elif type2==2: #site 2
  151. fanart = os.path.join(artPath, 'fanartA44.jpg');ICON = os.path.join(artPath, 'iconA44.png');mainSite='http://www.anime44.com/'
  152. else: #site 1
  153. fanart = os.path.join(artPath, 'fanartAG.jpg');ICON = os.path.join(artPath, 'iconAG.png');mainSite='http://www.animeget.com/'
  154. ### ############################################################################################################
  155. ### ############################################################################################################
  156. SiteBits=['nosite','animeget.com','anime44.com','animeplus.tv','gooddrama.net','anime44.co.uk','dubbedanimeon.com','dubhappy.eu','watchdub.com']
  157. SiteNames=['nosite','[COLOR blue][COLOR white]Anime[/COLOR]Get[/COLOR]','[COLOR red][COLOR white]Anime[/COLOR]44[/COLOR]','[COLOR darkblue][COLOR white]Anime[/COLOR]Plus[/COLOR]','[COLOR grey]Good[COLOR white]Drama[/COLOR][/COLOR]','[COLOR maroon][COLOR white]Anime[/COLOR]Zone[/COLOR]','[COLOR teal]Dubbed[COLOR white]Anime[/COLOR]On [/COLOR]','[COLOR cornflowerblue][COLOR white]dub[/COLOR]happy[/COLOR]','[COLOR cornflowerblue]Watch[/COLOR][COLOR white]Dub[/COLOR]','','']
  158. SitePrefixes=['nosite','','','','','subanime/','','','','','','','','','','','','']
  159. SiteSufixes= ['nosite','','','','','.html','','','','','','','','','','','','','']
  160. SiteSearchUrls= ['nosite','http://www.animeget.com/search','http://www.anime44.com/anime/search?search_submit=Go&key=','http://www.animeplus.tv/anime/search?search_submit=Go&key=','http://www.gooddrama.net/drama/search?stype=drama&search_submit=Go&key=','No Search Engine for VideoZone','http://dubbedanimeon.com/?s=','','','','','','','']
  161. SiteSearchMethod= ['nosite','post','get','get','get','VideoZone','get','','','','','','','']
  162. Sites=['animeget.com','anime44.com','animeplus.tv','gooddrama.net','anime44.co.uk','dubbedanimeon.com','dubhappy.eu','watchdub.com']
  163. MyAlphabet=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
  164. MyColors=['red','blue','darkblue','grey','maroon','teal','cornflowerblue','cornflowerblue','','','','']
  165. MyBrowser=['User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3']
  166. ### ############################################################################################################
  167. MyVideoLinkSrcMatches=['src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"' ,'src="(.+?)"' ,'src="(.+?)"', 'src="(.+?)"']
  168. MyVideoLinkSrcMatchesB=['src="(.+?)"', '<embed.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"' ,'src="(.+?)"' ,'src="(.+?)"', 'src="(.+?)"']
  169. MyVideoLinkBrackets=['<iframe.+?src="(.+?)"', '<embed.+?src="(.+?)"', '<object.+?data="(.+?)"']
  170. MyAlphabet= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
  171. MyBrowser= ['User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3']
  172. MySourcesV= ['videoweed.es', 'video44.net', 'novamov.com', 'dailymotion.com', 'videofun.me', 'yourupload.com', 'video.google.com', 'vidzur.com', 'upload2.com','putlocker.com','videoslasher.com','vidbull.com', 'uploadc.com', 'veevr.com', 'rutube.ru']
  173. #MySourcesV= ['videoweed.es', 'video44.net', 'novamov.com', 'dailymotion.com', 'videofun.me', 'yourupload.com', 'video.google.com', 'vidzur.com', 'upload2.com','putlocker.com','videoslasher.com','vidbull.com', 'UploadC', 'veevr.com', 'rutube.ru', 'MP4UPLOAD' ,'AUENGINE']
  174. MyIconsV= [artPath + 'videoweed.jpg', artPath + 'video44a.png', artPath + 'novamov.jpg', artPath + 'dailymotion.jpg', artPath + 'videofun.png', artPath + 'yourupload.jpg', artPath + 'googlevideo.gif', artPath + 'vidzur.png', artPath + 'upload2.png', artPath + 'putlocker.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png']#BLANK.png
  175. MyNamesV= ['VideoWeed', 'Video44', 'NovaMov', 'DailyMotion', 'VideoFun', 'YourUpload', 'Google Video', 'VidZur', 'Upload2', 'PutLocker', 'VideoSlasher', 'VidBull', 'UploadC', 'Veevr', 'RuTube', 'MP4Upload' ,'AUEngine']
  176. MyColorsV= ['lime', 'red', 'silver', 'green', 'cyan', 'grey', 'blue', 'orange', 'white', 'white', 'white', 'white', 'white', 'white', 'white', 'white', 'white', 'white', 'white']
  177. ### ############################################################################################################
  178. ### ############################################################################################################
  179. def getURLr(url,dReferer):
  180. try:
  181. req = urllib2.Request(url,dReferer)
  182. req.add_header(MyBrowser[0], MyBrowser[1])
  183. req.add_header('Referer', dReferer)
  184. response = urllib2.urlopen(req)
  185. link=response.read()
  186. response.close()
  187. return(link)
  188. except:
  189. return('none')
  190. def getURL(url):
  191. try:
  192. req = urllib2.Request(url)
  193. req.add_header(MyBrowser[0], MyBrowser[1])
  194. response = urllib2.urlopen(req)
  195. link=response.read()
  196. response.close()
  197. return(link)
  198. except:
  199. return('none')
  200. def postURL(url,postStr):
  201. postData=urllib.urlencode(postStr)
  202. req = urllib2.Request(url,postData)
  203. req.add_header(MyBrowser[0], MyBrowser[1])
  204. response = urllib2.urlopen(req)
  205. link=response.read()
  206. response.close()
  207. return(link)
  208. def notification(header="", message="", sleep=5000 ):
  209. xbmc.executebuiltin( "XBMC.Notification(%s,%s,%i)" % ( header, message, sleep ) )
  210. #notify(msg=message, title=header, delay=sleep, image=ICON)
  211. #notify(msg=message, title='[COLOR green][B]'+header+'[/B][/COLOR]', delay=sleep, image=ICON0)
  212. ### ############################################################################################################
  213. ##Example##VaddDir('[COLOR blue]' + text[0] + '[/COLOR]', '', 0, '', False)
  214. def addFolder(name,name2,url,type2,mode,iconimage,categoryA='Blank'):
  215. ###addDir(name,name2,url,type2,mode,iconimage,fanimage)
  216. if ('http://' in iconimage) or (artPath in iconimage): t=''
  217. else: iconimage = artPath + iconimage
  218. mainSite='http://'+SiteBits[type2]+'/'
  219. addDir(name,name2,mainSite + url,type2,mode,iconimage,fanart,categoryA)
  220. #addDirD(name,name2,mainSite + url,type2,mode,artPath + iconimage,fanart,'wow')
  221. ### from videolinks.py ###
  222. #def addFolder(name,name2,url,type2,mode,iconimage):
  223. # ##addDir(name,name2,url,type2,mode,iconimage,fanimage)
  224. # addDir(name,name2,mainSite + url,type2,mode,artPath + iconimage,fanart)
  225. def addDirF(name,name2,url,favcmd,type2=0,mode=0,iconimage=ICON0,fanimage=fanart0,categoryA='Blank'):
  226. if (debugging==True): print 'Category: ',category,categoryA
  227. categoryA=category+' ::: '+categoryA
  228. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&nm="+urllib.quote_plus(name2)+"&tp="+str(type2)+"&scr="+urllib.quote_plus(iconimage)+"&fan="+urllib.quote_plus(fanimage)+"&show="+urllib.quote_plus(name2)+"&cat="+categoryA+'&fav='+favcmd
  229. ok=True
  230. liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  231. liz.setInfo( type="Video", infoLabels={ "Title": name } )
  232. liz.setProperty( "Fanart_Image", fanimage )
  233. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  234. return ok
  235. def addDir(name,name2,url,type2,mode,iconimage,fanimage,categoryA='Blank'):
  236. if (debugging==True): print 'Category: ',category,categoryA
  237. categoryA=category+' ::: '+categoryA
  238. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&nm="+urllib.quote_plus(name2)+"&tp="+str(type2)+"&scr="+urllib.quote_plus(iconimage)+"&fan="+urllib.quote_plus(fanimage)+"&show="+urllib.quote_plus(name2)+"&cat="+categoryA
  239. ok=True
  240. liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  241. liz.setInfo( type="Video", infoLabels={ "Title": name } )
  242. liz.setProperty( "Fanart_Image", fanimage )
  243. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  244. return ok
  245. def addDirD(name,name2,url,type2,mode,iconimage,fanimage,doSorting=False,categoryA='Blank',Labels='none'):#,plot='Blank',genres='none listed',status='none',released='unknown',rating='none',others='none'):
  246. if Labels=='none': Labels={ "Title" : name }
  247. if categoryA=='Blank': categoryA=name
  248. #if (debugging==True): print 'Category: ',category,categoryA
  249. categoryA=category+' ::: '+categoryA
  250. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&nm="+urllib.quote_plus(name2)+"&tp="+str(type2)+"&scr="+urllib.quote_plus(iconimage)+"&fan="+urllib.quote_plus(fanimage)+"&show="+urllib.quote_plus(name2)+"&cat="+urllib.quote_plus(categoryA)
  251. #
  252. if (debugging==True): print u
  253. vc_tag=visited_DoCheck(u)
  254. #if (name=='Maburaho'): visited_add(u)
  255. if (debugging==True): print vc_tag
  256. #
  257. ok=True
  258. liz=xbmcgui.ListItem(vc_tag+name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  259. liz.setInfo( type="Video", infoLabels= Labels ) #"Title": "'" + name + "'", "Plot" : plot, "Genres" : genres } )
  260. liz.setProperty( "Fanart_Image", fanimage )
  261. sysname = urllib.quote_plus(name)
  262. sysurl = urllib.quote_plus(url)
  263. sysscr = urllib.quote_plus(iconimage)
  264. sysfan = urllib.quote_plus(fanimage)
  265. #handle adding context menus
  266. contextMenuItems = []
  267. if (debugging==True): print getsetbool('enable-showurl')
  268. if __settings__.getSetting("enable-showurl") == "true":#doesn't work for some odd reason >> #if getsetbool('enable-showurl') == 'true':#
  269. contextMenuItems.append(('[B][COLOR orange]Show[/COLOR][/B] ~ [B]URL[/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],mode , sysname, urllib.quote_plus(name2), type2, 'showurl', sysurl, sysscr, sysfan)))
  270. contextMenuItems.append(('[B][COLOR green]ADD[/COLOR][/B] ~ [B][COLOR tan]Favorite[/COLOR][/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s&show=%s)' % (sys.argv[0],mode , sysname, urllib.quote_plus(name2), type2, 'add', sysurl, sysscr, sysfan,urllib.quote_plus(name2))))
  271. contextMenuItems.append(('[B][COLOR red]REMOVE[/COLOR][/B] ~ [B][COLOR tan]Favorite[/COLOR][/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s&show=%s)' % (sys.argv[0],mode , sysname, urllib.quote_plus(name2), type2, 'rem', sysurl, sysscr, sysfan,urllib.quote_plus(name2))))
  272. contextMenuItems.append(('Show Information', 'XBMC.Action(Info)'))
  273. #
  274. #contextMenuItems.append(('[B][COLOR orange]Test[/COLOR][/B] ~ [B]Test[/B]',"notification(%s,%s)" % (sysname,sysurl)))
  275. if (debugging==True): print getset('enable-clearfavorites')
  276. if __settings__.getSetting("enable-clearfavorites") == "true":#if getset('enable-clearfavorites')==True:
  277. contextMenuItems.append(('[B][COLOR yellow]Clear[/COLOR][/B] ~ [B][COLOR tan]Favorites[/COLOR][/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],mode , sysname, urllib.quote_plus(name2), type2, 'clr', sysurl, sysscr, sysfan)))
  278. liz.addContextMenuItems(contextMenuItems, replaceItems=False)#True#liz.addContextMenuItems(contextMenuItems)
  279. if doSorting==True:
  280. xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE)
  281. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  282. return ok
  283. def addDirV(name,name2,url,type2,mode,iconimage,fanimage,categoryA=''):
  284. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&nm="+urllib.quote_plus(name2)+"&tp="+str(type2)+"&cat="+categoryA
  285. ok=True
  286. liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  287. liz.setInfo( type="Video", infoLabels={ "Title": name } )
  288. liz.setProperty( "Fanart_Image", fanimage )
  289. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  290. return ok
  291. #def VaddDir(name, url, mode, iconimage, fanimage, is_folder=False,categoryA=''):#VANILLA ADDDIR (kept for reference)
  292. # u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&cat="+categoryA
  293. # ok=True
  294. # liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  295. # liz.setInfo( type="Video", infoLabels={ "Title": name } )
  296. # liz.setProperty( "Fanart_Image", fanimage )
  297. # ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=is_folder)
  298. # return ok
  299. def VaddDir(name, url, mode, iconimage, fanimage, is_folder=False,categoryA=''):#VANILLA ADDDIR (kept for reference)
  300. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&cat="+categoryA
  301. #if (debugging==True): print u
  302. ok=True
  303. liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  304. liz.setInfo( type="Video", infoLabels={ "Title": name } )
  305. liz.setProperty( "Fanart_Image", fanimage )
  306. contextMenuItems = []
  307. if __settings__.getSetting("enable-showurl") == "true":
  308. contextMenuItems.append(('[B][COLOR orange]Show[/COLOR][/B] ~ [B]URL[/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],mode , urllib.quote_plus(name), urllib.quote_plus(name), 877, 'showurl', urllib.quote_plus(url), urllib.quote_plus(iconimage), urllib.quote_plus(fanimage))))
  309. liz.addContextMenuItems(contextMenuItems, replaceItems=True)#True#liz.addContextMenuItems(contextMenuItems)
  310. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=is_folder)
  311. return ok
  312. ### from theanimehighway.py ###
  313. #def addLink(name,url,iconimage):
  314. # ok=True
  315. # liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
  316. # liz.setInfo( type="Video", infoLabels={ "Title": name } )
  317. # ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
  318. # return ok
  319. def addLink(name,url,iconimage=ICON,fanimage=fanart,shoname='none',downloadable=True):
  320. ok=True
  321. if shoname=='none':
  322. try: shoname=show
  323. except: shoname=name
  324. if fanimage==fanart:
  325. try: fanimage=imgfan
  326. except: pass
  327. if iconimage in MyIconsV:
  328. try:
  329. iconimage=scr
  330. except: pass
  331. #
  332. #liz=xbmcgui.ListItem(name, iconImage=artPath+"blank.gif", thumbnailImage=iconimage)
  333. liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
  334. ##if (debugging==True): print 'sitename name: '+SiteNames[type2] + name
  335. ##liz.setInfo( type="Video", infoLabels={ "Title": name } )
  336. Studio=name
  337. if (' - [COLOR grey]' in Studio): Studio = Studio.split(' - [COLOR grey]')[0]
  338. if (' [COLOR grey]- ' in Studio): Studio = Studio.split(' [COLOR grey]- ')[0]
  339. if ('[COLOR grey] - ' in Studio): Studio = Studio.split('[COLOR grey] - ')[0]
  340. if (' - [COLOR' in Studio): Studio = Studio.split(' - [COLOR')[0]
  341. showtitle=shoname
  342. if (' [COLOR lime](English Dubbed)[/COLOR]' in showtitle):
  343. Studio += ' [COLOR lime](English Dubbed)[/COLOR]'
  344. showtitle = showtitle.replace(' [COLOR lime](English Dubbed)[/COLOR]','')
  345. elif ('English Dubbed' in showtitle): Studio += ' [COLOR lime](English Dubbed)[/COLOR]'
  346. elif ('Eng Dubbed' in showtitle): Studio += ' [COLOR lime](English Dubbed)[/COLOR]'
  347. elif ('Dubbed' in showtitle): Studio += ' [COLOR lime](Dubbed)[/COLOR]'
  348. elif ('English Subbed' in showtitle): Studio += ' [COLOR lime](English Subbed)[/COLOR]'
  349. elif ('Eng Subbed' in showtitle): Studio += ' [COLOR lime](English Subbed)[/COLOR]'
  350. elif ('Subbed' in showtitle): Studio += ' [COLOR lime](Subbed)[/COLOR]'
  351. liz.setInfo( type="Video", infoLabels={ "Title": showtitle, "Studio": Studio } )
  352. #liz.setProperty( "Fanart_Image", fanimage )
  353. contextMenuItems = []
  354. if (debugging==True): print getset('enable-showurl')
  355. if __settings__.getSetting("enable-showurl") == "true":#if getset('enable-showurl')=='true':
  356. contextMenuItems.append(('[B][COLOR orange]Show[/COLOR][/B] ~ [B]URL[/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],0 , urllib.quote_plus(shoname), urllib.quote_plus(shoname), 0, 'showurl', urllib.quote_plus(url), iconimage, fanimage)))
  357. if (__settings__.getSetting("enable-downloading") == "true") and (downloadable == True):#if getset('enable-downloading',True)=='True':
  358. #if ('videofun.me' not in url) and ('videoweed.es' not in url) and ('dailymotion.com' not in url):
  359. if ('novamov.com' not in url) and ('videoweed.es' not in url) and ('dailymotion.com' not in url):
  360. contextMenuItems.append(('[B][COLOR purple]Download[/COLOR][/B] ~ [B]File[/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],0 , urllib.quote_plus(shoname), urllib.quote_plus(shoname), 0, 'download', urllib.quote_plus(url), iconimage, fanimage)))
  361. liz.addContextMenuItems(contextMenuItems, replaceItems=True)#True#liz.addContextMenuItems(contextMenuItems)
  362. ##liz.addContextMenuItems([('[B][COLOR green]D[/COLOR][/B][B]ownload[/B]',"downloadfile(url,name)")])
  363. #liz.addContextMenuItems([('[B][COLOR green]D[/COLOR][/B][B]ownload[/B]',"XBMC.RunPlugin(%s?mode=%s&name=%s&url=%s)"%(sys.argv[0],999,name,url))])
  364. ##xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
  365. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
  366. return ok
  367. ### ############################################################################################################
  368. def getset(idSetting):#,defaultValue=''):#Addon.getSetting('idNameOfSetting')
  369. return __settings__.getSetting(idSetting)#==defaultValue
  370. def getsetbool(idSetting):#Addon.getSetting('idNameOfSetting') #Method seems to be an utter failure for BOOL(true/false)'s
  371. #if (debugging==True): print __settings__.getSetting(idSetting) == 'true'
  372. return __settings__.getSetting(idSetting) == 'true'
  373. def getsetbool_(idSetting):#Addon.getSetting('idNameOfSetting') #Method seems to be an utter failure for BOOL(true/false)'s
  374. #if (debugging==True): print __settings__.getSetting(idSetting) == 'true'
  375. #try: tst=__settings__.getSetting(idSetting) == 'true'
  376. try: tst=__settings__.getSetting(idSetting)
  377. except: tst='False'
  378. if (tst=='true') or (tst=='True') or (tst=='TRUE'): return True
  379. else: return False
  380. #return __settings__.getSetting(idSetting) == 'true'
  381. ### ############################################################################################################
  382. def download_it_now(url,name):## mode=1901 ##
  383. name=name.strip()
  384. if ('[/COLOR]' in name): name=name.replace('[/COLOR]','')
  385. if ('[COLOR lime]' in name): name=name.replace('[COLOR lime]','')
  386. if ('[/color]' in name): name=name.replace('[/color]','')
  387. if ('[color lime]' in name): name=name.replace('[color lime]','')
  388. #if ('' in name): name=name.replace('','')
  389. #if ('' in name): name=name.replace('','')
  390. #if ('' in name): name=name.replace('','')
  391. notification(name,'Attempting Download...')
  392. download_file_prep(url,name,name,name)
  393. ## Example of how to connect to this addon's download feature from another plugin: ##
  394. #### xbmc.executebuiltin('XBMC.RunPlugin(%s?mode=1901&url=%s&name=%s)' % ('plugin://plugin.video.theanimehighway/', urllib.quote_plus(stream_url), urllib.quote_plus(title)))
  395. #### Simply make sure to include the quoted name and url for this function to work.
  396. #### File must be for a downloadable file or video stream, not for a page with a video on it.
  397. def download_metapack(url, dest, displayname=False):
  398. print 'Downloading Metapack'
  399. print 'URL: %s' % url
  400. print 'Destination: %s' % dest
  401. if not displayname:
  402. displayname = url
  403. dlg = xbmcgui.DialogProgress()
  404. dlg.create('Downloading', '', displayname)
  405. start_time = time.time()
  406. if os.path.isfile(dest):
  407. print 'File to be downloaded already esists'
  408. return True
  409. try:
  410. urllib.urlretrieve(url, dest, lambda nb, bs, fs: _pbhook(nb, bs, fs, dlg, start_time))
  411. except:
  412. #only handle StopDownloading (from cancel),
  413. #ContentTooShort (from urlretrieve), and OS (from the race condition);
  414. #let other exceptions bubble
  415. if sys.exc_info()[0] in (urllib.ContentTooShortError, StopDownloading, OSError):
  416. return False
  417. else:
  418. raise
  419. return True
  420. ###
  421. ### Dialog DialogBusy DialogButton Menu DialogContentSettings DialogContentMenu DialogExtendedProgressBar
  422. ### DialogFavourites DialogKaiToast DialogKeyboard DialogOK DialogProgress DialogVolumeBar DialogVideoScan
  423. ### DialogVideoInfo DialogTextViewer DialogSlider DialogSelect DialogSeekBar DialogYesNo
  424. ###
  425. def download_file(url='',name='temp',localfilename='temp',localpath=artPath,filext='.flv'):
  426. t=''
  427. ###url='https://github.com/HIGHWAY99/plugin.video.theanimehighway/archive/master.zip'
  428. ###localfilename='plugin.video.theanimehighway.zip'
  429. ###localpath=__home__
  430. #localfilewithpath=os.path.join(localpath,localfilename)
  431. #if (debugging==True): print 'Attempting to download "' + localfilename + '" to "' + localfilewithpath + '" from: ' + url
  432. ###dialogbox('To: ' + localfilewithpath,'Download File: ' + localfilename,'From: ' + url,'[COLOR red]This is still being tested.[/COLOR]')
  433. #if os.path.isfile(localfilewithpath):
  434. # if (debugging==True): print 'File to be downloaded already esists.'
  435. # notification('Download: '+localfilename,'File already exists.')#This function may never happen.
  436. # return
  437. #dialog = xbmcgui.Dialog()
  438. #if dialog.yesno('Download File', 'Do you wish to download this file?','File: ' + localfilename,'To: ' + localpath):
  439. # notification('Attempting to Download File',localfilename + '[CR] This function is still being tested.')#This function may never happen.
  440. # try: dp = xbmcgui.DialogProgressBG() ## Only works on daily build of XBMC.
  441. # except: dp = xbmcgui.DialogProgress()
  442. # dp.create('Downloading', '', localfilename)
  443. # ####
  444. # ####urllib.urlretrieve(url, dest, lambda nb, bs, fs: _pbhookb(nb, bs, fs, dlg, start_time))
  445. # ####
  446. # urllib.urlretrieve(url, localfilewithpath, lambda nb, bs, fs: _pbhookb(nb, bs, fs, dlg, start_time))
  447. # #urllib.urlretrieve(url, localfilewithpath)
  448. # notification('Download File','Download Complete.[CR] ' + localfilename,15000)
  449. # dialogbox_ok('File Size: ' + str(os.path.getsize(localfilewithpath)) + ' (bytes)','Download Complete','Note:','Make sure the size seems right.')
  450. # ###total_size += os.path.getsize(fp)
  451. ###
  452. ###
  453. ###notification('Download File','Sorry this feature is not yet implimented.')#This function may never happen.
  454. def _pbhookb(numblocks, blocksize, filesize, dlg, start_time):
  455. try:
  456. percent = min(numblocks * blocksize * 100 / filesize, 100)
  457. currently_downloaded = float(numblocks) * blocksize / (1024 * 1024)
  458. kbps_speed = numblocks * blocksize / (time.time() - start_time)
  459. if kbps_speed > 0:
  460. eta = (filesize - numblocks * blocksize) / kbps_speed
  461. else:
  462. eta = 0
  463. kbps_speed /= 1024
  464. total = float(filesize) / (1024 * 1024)
  465. mbs = '%.02f MB of %.02f MB' % (currently_downloaded, total)
  466. est = 'Speed: %.02f Kb/s ' % kbps_speed
  467. est += 'ETA: %02d:%02d' % divmod(eta, 60)
  468. dlg.update(percent, mbs, est)
  469. except:
  470. percent = 100
  471. dlg.update(percent)
  472. #if dlg.iscanceled(): ## used for xbmcgui.DialogProgress() but causes an error with xbmcgui.DialogProgressBG()
  473. # dlg.close()
  474. # raise StopDownloading('Stopped Downloading')
  475. def download_file_frodo(url='',name='temp',localfilename='temp',localpath=artPath,filext='.flv'):
  476. localfilewithpath=os.path.join(localpath,localfilename)
  477. if (debugging==True): print 'Attempting to download "' + localfilename + '" to "' + localfilewithpath + '" from: ' + url
  478. #dialogbox('To: ' + localfilewithpath,'Download File: ' + localfilename,'From: ' + url,'[COLOR red]This is still being tested.[/COLOR]')
  479. if os.path.isfile(localfilewithpath):
  480. if (debugging==True): print 'File to be downloaded already esists.'
  481. notification('Download: '+localfilename,'File already exists.')#This function may never happen.
  482. return
  483. dialog = xbmcgui.Dialog()
  484. if dialog.yesno('Download File', 'Do you wish to download this file?','File: ' + localfilename,'To: ' + localpath):
  485. notification('Attempting to Download File',localfilename + '[CR] This function is still being tested.')#This function may never happen.
  486. dp = xbmcgui.DialogProgress()
  487. dp.create('Downloading', '', localfilename)
  488. start_time = time.time()
  489. urllib.urlretrieve(url, localfilewithpath, lambda nb, bs, fs: _pbhookb_frodo(nb, bs, fs, dp, start_time)) #urllib.urlretrieve(url, localfilewithpath)
  490. ##urllib.urlretrieve(url, localfilewithpath, lambda nb, bs, fs: _pbhookb_frodo(nb, bs, fs, dlg, start_time)) #urllib.urlretrieve(url, localfilewithpath)
  491. notification('Download File','Download Complete.[CR] ' + localfilename,15000)
  492. dialogbox_ok('File Size: ' + str(os.path.getsize(localfilewithpath)) + ' (bytes)','Download Complete','Note:','Make sure the size seems right.')
  493. #total_size += os.path.getsize(fp)
  494. #notification('Download File','Sorry this feature is not yet implimented.')#This function may never happen.
  495. def _pbhookb_frodo(numblocks, blocksize, filesize, dlg, start_time):
  496. try:
  497. percent = min(numblocks * blocksize * 100 / filesize, 100)
  498. currently_downloaded = float(numblocks) * blocksize / (1024 * 1024)
  499. kbps_speed = numblocks * blocksize / (time.time() - start_time)
  500. if kbps_speed > 0:
  501. eta = (filesize - numblocks * blocksize) / kbps_speed
  502. else:
  503. eta = 0
  504. kbps_speed /= 1024
  505. total = float(filesize) / (1024 * 1024)
  506. mbs = '%.02f MB of %.02f MB' % (currently_downloaded, total)
  507. est = 'Speed: %.02f Kb/s ' % kbps_speed
  508. est += 'ETA: %02d:%02d' % divmod(eta, 60)
  509. dlg.update(percent, mbs, est)
  510. except:
  511. percent = 100
  512. dlg.update(percent)
  513. if dlg.iscanceled(): ## used for xbmcgui.DialogProgress() but causes an error with xbmcgui.DialogProgressBG()
  514. dlg.close()
  515. raise StopDownloading('Stopped Downloading')
  516. def filename_filter_out_year(name=''):
  517. years=re.compile(' \((\d+)\)').findall('__'+name+'__')
  518. for year in years:
  519. name=name.replace(' ('+year+')','')
  520. name=name.strip()
  521. return name
  522. def filename_filter_colorcodes(name=''):
  523. if ('[/color]' in name): name=name.replace('[/color]','')
  524. if ('[/COLOR]' in name): name=name.replace('[/COLOR]','')
  525. if ('[color lime]' in name): name=name.replace('[color lime]','')
  526. if ('[COLOR lime]' in name): name=name.replace('[COLOR lime]','')
  527. if ('[COLOR green]' in name): name=name.replace('[COLOR green]','')
  528. if ('[COLOR yellow]' in name): name=name.replace('[COLOR yellow]','')
  529. if ('[COLOR red]' in name): name=name.replace('[COLOR red]','')
  530. if ('[b]' in name): name=name.replace('[b]','')
  531. if ('[B]' in name): name=name.replace('[B]','')
  532. if ('[/b]' in name): name=name.replace('[/b]','')
  533. if ('[/B]' in name): name=name.replace('[/B]','')
  534. if ('[cr]' in name): name=name.replace('[cr]','')
  535. if ('[CR]' in name): name=name.replace('[CR]','')
  536. if ('[i]' in name): name=name.replace('[i]','')
  537. if ('[I]' in name): name=name.replace('[I]','')
  538. if ('[/i]' in name): name=name.replace('[/i]','')
  539. if ('[/I]' in name): name=name.replace('[/I]','')
  540. if ('[uppercase]' in name): name=name.replace('[uppercase]','')
  541. if ('[UPPERCASE]' in name): name=name.replace('[UPPERCASE]','')
  542. if ('[lowercase]' in name): name=name.replace('[lowercase]','')
  543. if ('[LOWERCASE]' in name): name=name.replace('[LOWERCASE]','')
  544. name=name.strip()
  545. #if ('' in name): name=name.replace('','')
  546. #if ('' in name): name=name.replace('','')
  547. #if ('' in name): name=name.replace('','')
  548. return name
  549. def Download_PrepExt(url,ext='.flv'):
  550. if '.zip' in url: ext='.zip' #Compressed Files
  551. elif '.rar' in url: ext='.rar'
  552. elif '.z7' in url: ext='.z7'
  553. elif '.png' in url: ext='.png' #images
  554. elif '.jpg' in url: ext='.jpg'
  555. elif '.gif' in url: ext='.gif'
  556. elif '.bmp' in url: ext='.bmp'
  557. elif '.jpeg' in url: ext='.jpeg'
  558. elif '.mp4' in url: ext='.mp4' #Videos
  559. elif '.mpeg' in url: ext='.mpeg'
  560. elif '.avi' in url: ext='.avi'
  561. elif '.flv' in url: ext='.flv'
  562. elif '.wmv' in url: ext='.wmv'
  563. elif '.mp3' in url: ext='.mp3' #others
  564. elif '.txt' in url: ext='.txt'
  565. #else: ext='.flv' #Default File Extention ('.flv')
  566. return ext
  567. def download_file_prep(url,name='none',name2='none',show='none',filext='none'):
  568. #
  569. if filext=='none':
  570. if '.zip' in url: filext='.zip' #Compressed Files
  571. elif '.rar' in url: filext='.rar'
  572. elif '.z7' in url: filext='.z7'
  573. elif '.png' in url: filext='.png' #images
  574. elif '.jpg' in url: filext='.jpg'
  575. elif '.gif' in url: filext='.gif'
  576. elif '.mp4' in url: filext='.mp4' #Videos
  577. elif '.mpeg' in url: filext='.mpeg'
  578. elif '.avi' in url: filext='.avi'
  579. elif '.flv' in url: filext='.flv'
  580. elif '.wmv' in url: filext='.wmv'
  581. elif '.mp3' in url: filext='.mp3' #others
  582. elif '.txt' in url: filext='.txt'
  583. else: filext='.flv' #Default File Extention ('.flv')
  584. try: name=filename_filter_colorcodes(name)
  585. except: name=''
  586. try: name2=filename_filter_colorcodes(name2)
  587. except: name2=name
  588. try: show=filename_filter_colorcodes(show)
  589. except: show=name
  590. filname = name + filext
  591. dialog = xbmcgui.Dialog()
  592. if dialog.yesno('Local Path', 'Where would you like to download to?', '', filname, 'Shows', 'Movies'):
  593. localpath = getset('folder-movie')#__settings__.getSetting('folder-movie')
  594. else:
  595. localpath = getset('folder-show')#__settings__.getSetting('folder-show')
  596. if (debugging==True): print localpath
  597. #download_file(url,name,filname,localpath) ## For nightly builds 13.x+
  598. download_file_frodo(url,name,filname,localpath) ## For Frodo builds 12.x
  599. #
  600. #def downloadfile(url,name):
  601. # import SimpleDownloader as downloader
  602. # downloader = downloader.SimpleDownloader()
  603. # url='http://www.xbmcswift.com/en/develop/api.html'
  604. # dlfold='/tmp'
  605. # #dlfold='F:\\xbmc\\theanimehighway\\'
  606. # params = { "url": url, "download_path": dlfold, "Title": name }
  607. # #params = { "url": url, "download_path": "F:\\xbmc\\theanimehighway\\", "Title": name, "live": "true", "duration": "20" }
  608. # filenm = name + ".txt"
  609. # #filenm = name + ".mp4"
  610. # notification('file download: ' + name, 'Downloading "' + url + '" to "' + filenm + '"')
  611. # downloader.download(filenm, params)
  612. ### ############################################################################################################
  613. #def dialogboxyesno(txtMessage="",txtHeader="",txt3="",txt4=""):
  614. # dialog = xbmcgui.Dialog()
  615. # if dialog.yesno(txtHeader, txtMessage, txt3, txt4):
  616. def dialogbox_ok(txtMessage="",txtHeader="",txt3="",txt4=""):
  617. dialog = xbmcgui.Dialog()
  618. ok = dialog.ok(txtHeader, txtMessage, txt3, txt4)
  619. #keyboard = xbmc.Keyboard(txtMessage, txtHeader, passwordField)#("text to show","header text", True="password field"/False="show text")
  620. #import win64clipboard as wc
  621. def copy_to_clipboard(msg):
  622. notification('Copy-to-Clipboard','Sorry this feature is not yet implimented.')
  623. #
  624. #
  625. #if sys.platform == 'win32':
  626. # wc.OpenClipboard()
  627. # wc.EmptyClipboard()
  628. # wc.SetClipboardData(win32con.CF_TEXT, msg)
  629. # wc.CloseClipboard()
  630. #
  631. #
  632. def showkeyboard(txtMessage="",txtHeader="",passwordField=False):
  633. if txtMessage=='None': txtMessage=''
  634. keyboard = xbmc.Keyboard(txtMessage, txtHeader, passwordField)#("text to show","header text", True="password field"/False="show text")
  635. keyboard.doModal()
  636. if keyboard.isConfirmed():
  637. return keyboard.getText()
  638. else:
  639. return False # return ''
  640. def dialogbox_number(Header="",n='',type=0):
  641. #Types: #0 : ShowAndGetNumber #1 : ShowAndGetDate #2 : ShowAndGetTime #3 : ShowAndGetIPAddress dialog = xbmcgui.Dialog()
  642. dlg=xbmcgui.Dialog()
  643. if (n==''): r=dlg.numeric(1,Header)
  644. else: r=dlg.numeric(1,Header,n)
  645. return r
  646. ### ############################################################################################################
  647. def checkForPartNo(url,partInfo=''):
  648. url=urllib.unquote_plus(url)
  649. if '_part_' in urllib.unquote_plus(url):
  650. try:
  651. matchaptn=re.compile('_part_(.+?).').findall(url)
  652. partInfo=' - Part # ' + matchaptn[0]
  653. except:
  654. partInfo=' - Part # ' + 'Unknown'
  655. elif '-part-' in urllib.unquote_plus(url):
  656. try:
  657. matchaptn=re.compile('-part-(.+?).').findall(url)
  658. partInfo=' - Part # ' + matchaptn[0]
  659. except:
  660. partInfo=' - Part # ' + 'Unknown'
  661. elif 'part' in urllib.unquote_plus(url):
  662. try:
  663. matchaptn=re.compile('part(.+?).').findall(url)
  664. partInfo=' - Part # ' + matchaptn[0]
  665. except:
  666. temp=''
  667. return partInfo
  668. ### ############################################################################################################
  669. def aSortMeth(sM,h=int(sys.argv[1])):
  670. xbmcplugin.addSortMethod(handle=h, sortMethod=sM)
  671. def set_view(content='none',view_mode=50,do_sort=False):
  672. if (debugging==True): print 'content type: ',content
  673. if (debugging==True): print 'view mode: ',view_mode
  674. h=int(sys.argv[1])
  675. if (content is not 'none'): xbmcplugin.setContent(h, content)
  676. #types: # set_view()
  677. # 50 CommonRootView
  678. # 51 FullWidthList
  679. # 500 ThumbnailView
  680. # 501 PosterWrapView
  681. # 508 PosterWrapView2_Fanart
  682. # 505 WideIconView
  683. #
  684. #
  685. # set content type so library shows more views and info
  686. if (tfalse(addst("auto-view"))==True):
  687. xbmc.executebuiltin("Container.SetViewMode(%s)" % view_mode)
  688. # set sort methods - probably we don't need all of them
  689. #aSortMeth(xbmcplugin.SORT_METHOD_NONE)
  690. aSortMeth(xbmcplugin.SORT_METHOD_UNSORTED)
  691. aSortMeth(xbmcplugin.SORT_METHOD_TITLE)
  692. aSortMeth(xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE)
  693. aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_TITLE)
  694. aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE)
  695. aSortMeth(xbmcplugin.SORT_METHOD_LABEL)
  696. aSortMeth(xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
  697. aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_RATING)
  698. aSortMeth(xbmcplugin.SORT_METHOD_DATE)
  699. aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_YEAR)
  700. #aSortMeth(xbmcplugin.SORT_METHOD_PROGRAM_COUNT)
  701. aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
  702. aSortMeth(xbmcplugin.SORT_METHOD_GENRE)
  703. #
  704. aSortMeth(xbmcplugin.SORT_METHOD_FILE)
  705. #aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
  706. #aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_RATING)
  707. #aSortMeth(xbmcplugin.SORT_METHOD_STUDIO)
  708. #aSortMeth(xbmcplugin.SORT_METHOD_STUDIO_IGNORE_THE)
  709. #aSortMeth(xbmcplugin.SORT_METHOD_PLAYLIST_ORDER)
  710. aSortMeth(xbmcplugin.SORT_METHOD_EPISODE)
  711. aSortMeth(xbmcplugin.SORT_METHOD_DURATION)
  712. #aSortMeth(xbmcplugin.SORT_METHOD_BITRATE)
  713. #
  714. if (do_sort == True):
  715. #aSortMeth(h, xbmcplugin.SORT_METHOD_TITLE)#xbmcplugin.SORT_METHOD_LABEL
  716. xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_TITLE)#xbmcplugin.SORT_METHOD_LABEL
  717. #
  718. ####xbmcplugin.addSortMethod(handle=h, sortMethod=xbmcplugin.SORT_METHOD_TRACKNUM)
  719. # #SORT_METHOD_NONE, SORT_METHOD_UNSORTED, SORT_METHOD_VIDEO_TITLE,
  720. # # SORT_METHOD_TRACKNUM, SORT_METHOD_FILE, SORT_METHOD_TITLE
  721. # # SORT_METHOD_TITLE_IGNORE_THE, SORT_METHOD_LABEL
  722. # # SORT_METHOD_LABEL_IGNORE_THE, SORT_METHOD_VIDEO_SORT_TITLE,
  723. # # SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE
  724. ### ############################################################################################################
  725. ### from theanimehighway.py ###
  726. #def showurl(name,url,scr=ICON0,imgfan=fanart0,type2=0,mode=0):
  727. # copy_to_clipboard(url)
  728. # if (debugging==True): print url, name, scr, imgfan
  729. # kmsg=showkeyboard(url, name)
  730. def showurl(name,url,scr=ICON,imgfan=fanart,type2=0,mode=0):
  731. copy_to_clipboard(url)
  732. if (debugging==True): print url, name, scr, imgfan
  733. kmsg=showkeyboard(url, name)
  734. ### ############################################################################################################
  735. def metaArt_empty():
  736. saved_fans = cache.get('MetaArt_')
  737. fans = []
  738. cache.set('MetaArt_', str(fans))
  739. notification('[B][COLOR orange]Fanart[/COLOR][/B]','[B] Your Cached Fanart(s) Have Been Wiped Clean. Bye Bye.[/B]')
  740. def emptyFavorites():
  741. saved_favs = cache.get('favourites_')
  742. favs = []
  743. cache.set('favourites_', str(favs))
  744. notification('[B][COLOR orange]Favorites[/COLOR][/B]','[B] Your Favorites Have Been Wiped Clean. Bye Bye.[/B]')
  745. def addfavorite(name,url,scr=ICON0,imgfan=fanart0,tp2=0,mode=0):
  746. if (debugging==True): print name,url,scr,imgfan,tp2,mode
  747. saved_favs = cache.get('favourites_')
  748. favs = []
  749. if saved_favs:
  750. favs = eval(saved_favs)
  751. if favs:
  752. if (name,url,scr,imgfan,tp2,mode) in favs:
  753. notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Already in your Favorites[/B]')
  754. #xbmc.executebuiltin("XBMC.Notification([B][COLOR orange]"+name.upper()+"[/COLOR][/B],[B] Already in your Favourites[/B],5000,"")")
  755. return
  756. favs.append((name,url,scr,imgfan,tp2,mode))
  757. cache.set('favourites_', str(favs))
  758. notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Added to Favorites[/B]')
  759. #xbmc.executebuiltin("XBMC.Notification([B][COLOR orange]"+name.upper()+"[/COLOR][/B],[B] Added to Favourites[/B],5000,"")")
  760. def removefavorite(name,url,scr=ICON0,imgfan=fanart0,tp2=0,mode=0):#,scr,imgfan
  761. if (debugging==True): print name,url,scr,imgfan,tp2,mode
  762. saved_favs = cache.get('favourites_')
  763. if saved_favs:
  764. favs = eval(saved_favs)
  765. if (name,url,scr,imgfan,tp2,mode) in favs:
  766. favs.remove((name,url,scr,imgfan,tp2,mode))
  767. cache.set('favourites_', str(favs))
  768. notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Removed from Favorites[/B]')
  769. if (debugging==True): print name+' Removed from Favorites.'
  770. #set_view('tvshows',int(getset('viewmode-favs')),True)
  771. #VaddDir('[COLOR maroon] Visit with [COLOR tan]Highway[/COLOR] and others @ [COLOR white]#XBMCHUB[/COLOR] on [COLOR white]irc.freenode.net[/COLOR]:6667 [/COLOR]', '', 0, ICON, fanart, False)
  772. #LastPage=page_last_update()
  773. #xbmc.executebuiltin("XBMC.Container.Update(%s)" % (LastPage))
  774. xbmc.executebuiltin("XBMC.Container.Refresh")
  775. #VaddDir('[COLOR maroon] Visit with [COLOR tan]Highway[/COLOR] and others @ [COLOR white]#XBMCHUB[/COLOR] on [COLOR white]irc.freenode.net[/COLOR]:6667 [/COLOR]', '', 0, ICON, fanart, False)
  776. ##xbmc.Container.Refresh
  777. #xbmc.sleep(4000)
  778. elif ((name) in favs):
  779. favs.remove((name))
  780. cache.set('favourites_', str(favs))
  781. notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Removed from Favorites[/B]')
  782. if (debugging==True): print name+' Removed from Favorites. (Hopefully)'
  783. xbmc.executebuiltin("XBMC.Container.Refresh")
  784. elif favs:
  785. tf=False
  786. for (_name,_url,_scr,_imgfan,_tp2,_mode) in favs:
  787. if (name==_name):
  788. favs.remove((name,_url,_scr,_imgfan,_tp2,_mode))
  789. cache.set('favourites_', str(favs))
  790. notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Removed from Favorites[/B]')
  791. if (debugging==True): print name+' Removed from Favorites. (Hopefully)'
  792. tf=True
  793. xbmc.executebuiltin("XBMC.Container.Refresh")
  794. return
  795. if (tf==False): notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] not found in your Favorites[/B]')
  796. else:
  797. notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] not found in your Favorites[/B]')
  798. #xbmc.executebuiltin("XBMC.Notification([B][COLOR orange]"+name.upper()+"[/COLOR][/B],[B] Removed from Favourites[/B],5000,"")")
  799. def metaArt_add(show_name,show_title_thetvdb,show_id,url_thetvdb,show_fanart,show_poster,show_bannner,show_desc,show_genres,show_status,show_language,show_network,show_rating):#metaArt_add(match_showname,match_showid,match_thetvdb_url,match_fanart,match_poster,match_banner)
  800. ##if (debugging==True): print name,url,scr,imgfan,tp2,mode
  801. saved_fans = cache.get('MetaArt_')
  802. fans = []
  803. if saved_fans:
  804. fans = eval(saved_fans)
  805. if fans:
  806. if (show_name,show_id,url_thetvdb,show_fanart,show_poster,show_bannner,show_desc) in fans:
  807. #notification('[B][COLOR orange]'+show_name.upper()+'[/COLOR][/B]','[B] Already in your Cached Fanart(s).[/B]')
  808. return
  809. fans.append((show_name,show_title_thetvdb,show_id,url_thetvdb,show_fanart,show_poster,show_ban

Large files files are truncated, but you can click here to view the full file