Advertisement
stoli

Untitled

Mar 22nd, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.00 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. __script__ = "Logo Downloader"
  4. __author__ = "Ppic"
  5. __url__ = "http://code.google.com/p/passion-xbmc/"
  6. __svn_url__ = ""
  7. __credits__ = "Team XBMC PASSION, http://passion-xbmc.org/"
  8. __platform__ = "xbmc media center, [LINUX, OS X, WIN32, XBOX]"
  9. __date__ = "02-03-2010"
  10. __version__ = "2.3.0"
  11. __svn_revision__ = "$Revision: 000 $"
  12. __XBMC_Revision__ = "30000" #XBMC Babylon
  13. __useragent__ = "Logo downloader %s" % __version__
  14.  
  15. ##################################### HOW TO USE / INTEGRATE IN SKIN #####################################
  16. # for automatically download the script from xbmc, include this in your addon.xml:
  17. #
  18. # <requires>
  19. # <import addon="script.logo-downloader" version="2.0.0"/>
  20. # </requires>
  21. #
  22. # for solo mode (usually used from videoinfodialog) , $INFO[ListItem.TVShowTitle] is required.
  23. # exemple to launch:
  24. # <onclick>XBMC.RunScript(script.logo-downloader,mode=solo,logo=True,clearart=True,showthumb=True,showname=$INFO[ListItem.TVShowTitle])</onclick>
  25. #
  26. # for bulk mode, no particular info needed, just need a button to launch from where you want.
  27. # exemple to launch:
  28. # <onclick>XBMC.RunScript(script.logo-downloader,mode=bulk,clearart=True,logo=True,showthumb=True)</onclick>
  29. #
  30. # you can replace boolean by skin settings to activate / deactivate images types.
  31. ###########################################################################################################
  32.  
  33. import urllib
  34. import os
  35. import re
  36. from traceback import print_exc
  37. import xbmc
  38. import xbmcgui
  39. import shutil
  40. import xbmcaddon
  41.  
  42. addon = xbmcaddon.Addon("script.logo-downloader")
  43. SOURCEPATH = addon.getAddonInfo('path')
  44. RESOURCES_PATH = os.path.join( SOURCEPATH , "resources" )
  45. DIALOG_DOWNLOAD = xbmcgui.DialogProgress()
  46. ACTION_PREVIOUS_MENU = 10
  47. sys.path.append( os.path.join( RESOURCES_PATH, "lib" ) )
  48. from file_item import Thumbnails
  49. thumbnails = Thumbnails()
  50.  
  51. if xbmc.executehttpapi( "GetLogLevel()" ).strip("<li>") == "2": DEBUG = True
  52. else: DEBUG = True
  53.  
  54. def footprints():
  55. print "### %s starting ..." % __script__
  56. print "### author: %s" % __author__
  57. print "### URL: %s" % __url__
  58. print "### credits: %s" % __credits__
  59. print "### date: %s" % __date__
  60. print "### version: %s" % __version__
  61.  
  62. def get_html_source( url , save=False):
  63. """ fetch the html source """
  64. class AppURLopener(urllib.FancyURLopener):
  65. version = __useragent__
  66. urllib._urlopener = AppURLopener()
  67.  
  68. try:
  69. if os.path.isfile( url ): sock = open( url, "r" )
  70. else:
  71. urllib.urlcleanup()
  72. sock = urllib.urlopen( url )
  73.  
  74. htmlsource = sock.read()
  75. if save: file( os.path.join( CACHE_PATH , save ) , "w" ).write( htmlsource )
  76. sock.close()
  77. return htmlsource
  78. except:
  79. print_exc()
  80. print "### ERROR impossible d'ouvrir la page %s" % url
  81. xbmcgui.Dialog().ok("ERROR" , "site unreacheable")
  82. return False
  83.  
  84. class downloader:
  85. def __init__(self):
  86. print "### DEBUG: %s" % DEBUG
  87. print "### logo downloader initializing..."
  88. self.clearart = False
  89. self.logo = False
  90. self.show_thumb = False
  91. self.banner = False
  92. self.poster = False
  93. self.mode = ""
  94. self.reinit()
  95. if DEBUG:
  96. print sys.argv
  97. try: print("arg 0: %s" % sys.argv[0])
  98. except: print "no arg0"
  99. try: print("arg 1: %s" % sys.argv[1])
  100. except: print "no arg1"
  101. try: print("arg 2: %s" % sys.argv[2])
  102. except: print "no arg2"
  103. try: print("arg 3: %s" % sys.argv[3])
  104. except: print "no arg3"
  105. try: print("arg 4: %s" % sys.argv[4])
  106. except: print "no arg4"
  107. try: print("arg 5: %s" % sys.argv[5])
  108. except: print "no arg5"
  109. try: print("arg 6: %s" % sys.argv[6])
  110. except: print "no arg6"
  111. try: print("arg 7: %s" % sys.argv[7])
  112. except: print "no arg7"
  113.  
  114. for item in sys.argv:
  115. match = re.search("mode=(.*)" , item)
  116. if match: self.mode = match.group(1)
  117. match = re.search("clearart=(.*)" , item)
  118. if match:
  119. if not match.group(1) == "False": self.clearart = match.group(1)
  120. else: pass
  121. match = re.search("logo=(.*)" , item)
  122. if match:
  123. if not match.group(1) == "False": self.logo = match.group(1)
  124. else: pass
  125. match = re.search("showthumb=(.*)" , item)
  126. if match:
  127. if not match.group(1) == "False": self.show_thumb = match.group(1)
  128. else: pass
  129. match = re.search("showname=" , item)
  130. if match: self.show_name = item.replace( "showname=" , "" )
  131. else: pass
  132. match = re.search("banner=(.*)" , item)
  133. if match:
  134. if not match.group(1) == "False": self.banner = match.group(1)
  135. else: pass
  136. match = re.search("poster=(.*)" , item)
  137. if match:
  138. if not match.group(1) == "False": self.poster = match.group(1)
  139. else: pass
  140.  
  141. if self.mode == "solo":
  142. if DEBUG: print "### Start Solo Mode"
  143. self.solo_mode()
  144. elif self.mode == "bulk":
  145. if DEBUG: print "### Start Bulk Mode"
  146. self.bulk_mode()
  147.  
  148. def solo_mode(self):
  149. self.get_tvid_path()
  150. self.id_verif()
  151. if self.tvdbid:
  152. self.type_list = []
  153. if self.logo:self.type_list.append ("logo")
  154. if self.clearart:self.type_list.append ("clearart")
  155. if self.show_thumb:self.type_list.append ("showthumb")
  156. if self.banner:self.type_list.append ("banner")
  157. if self.poster:self.type_list.append ("poster")
  158.  
  159. if self.choice_type():
  160. self.image_list = False
  161. if self.logo:
  162. if self.logo == "True": self.filename = "logo.png"
  163. else: self.filename = self.logo
  164. self.get_lockstock_xml()
  165. self.search_logo()
  166. elif self.clearart:
  167. if self.clearart == "True": self.filename = "clearart.png"
  168. else: self.filename = self.clearart
  169. self.get_lockstock_xml()
  170. self.search_clearart()
  171. elif self.show_thumb:
  172. if self.show_thumb == "True": self.filename = "folder.jpg"
  173. else: self.filename = self.show_thumb
  174. self.get_lockstock_xml()
  175. self.search_show_thumb()
  176. elif self.banner:
  177. if self.banner == "True": self.filename = "folder.jpg"
  178. else: self.filename = self.banner
  179. self.get_tvdb_xml()
  180. self.search_banner()
  181. elif self.poster:
  182. if self.poster == "True": self.filename = "folder.jpg"
  183. else: self.filename = self.poster
  184. self.get_tvdb_xml()
  185. self.search_poster()
  186.  
  187. if self.image_list:
  188. if self.choose_image():
  189. if DEBUG: self.print_class_var()
  190. if self.download_image(): xbmcgui.Dialog().ok("Success" , "Download successfull" )
  191. else: xbmcgui.Dialog().ok("Error" , "Error downloading file" )
  192. else: xbmcgui.Dialog().ok("ERROR" , "no tvdb id found !" )
  193.  
  194. def bulk_mode(self):
  195. if DEBUG: print "### get tvshow list"
  196. DIALOG_PROGRESS = xbmcgui.DialogProgress()
  197. DIALOG_PROGRESS.create( "SCRIPT LOGO DOWNLOADER", "checking database ...")
  198. self.logo_found = 0
  199. self.logo_download = 0
  200. self.thumb_found = 0
  201. self.thumb_download = 0
  202. self.clearart_found = 0
  203. self.clearart_download = 0
  204. self.poster_found = 0
  205. self.poster_download = 0
  206. self.banner_found = 0
  207. self.banner_download = 0
  208. self.TV_listing()
  209.  
  210. print "###clearart#%s###" % self.clearart
  211. print "###logo#%s###" % self.logo
  212. print "###show_thumb#%s###" % self.show_thumb
  213.  
  214. for currentshow in self.TVlist:
  215. print "####################"
  216. if DIALOG_PROGRESS.iscanceled():
  217. DIALOG_PROGRESS.close()
  218. xbmcgui.Dialog().ok('CANCELED','Operation canceled by user.')
  219. break
  220. try:
  221. self.show_path = currentshow["path"]
  222. self.tvdbid = currentshow["id"]
  223. self.show_name = currentshow["name"]
  224. print "### show_name: %s" % self.show_name
  225. if DEBUG: print "### tvdbid: %s" % self.tvdbid ,"### show_path: %s" % self.show_path
  226. if DEBUG: print u"### check id"
  227. self.id_verif()
  228.  
  229. if self.logo:
  230. if DEBUG: print "### Search logo for %s" % self.show_name
  231. if self.logo == "True": self.filename = "logo.png"
  232. else: self.filename = self.logo
  233. if not os.path.exists( os.path.join( self.show_path , self.filename ) ):
  234. if DEBUG: print "### get lockstock xml"
  235. self.get_lockstock_xml()
  236. if self.search_logo():
  237. if DEBUG: print "### found logo for %s" % self.show_name
  238. if self.download_image():
  239. self.logo_download = self.logo_download +1
  240. if DEBUG: print "### logo downloaded for %s" % self.show_name
  241. else:
  242. if DEBUG: print "### %s already exist, skipping" % self.filename
  243. self.logo_found = self.logo_found + 1
  244. self.image_url = False
  245. self.filename = False
  246.  
  247. if self.clearart or self.show_thumb and not self.lockstock_xml:
  248. if DEBUG: print "### get xbmcstuff xml"
  249. self.get_xbmcstuff_xml()
  250.  
  251. if self.clearart:
  252. if DEBUG: print "### Search clearart for %s" % self.show_name
  253. if self.clearart == "True": self.filename = "clearart.png"
  254. else: self.filename = self.clearart
  255. if not os.path.exists( os.path.join( self.show_path , self.filename ) ):
  256. if self.search_clearart():
  257. if DEBUG: print "### found clearart for %s" % self.show_name
  258. if self.download_image():
  259. self.clearart_download = self.clearart_download +1
  260. if DEBUG: print "### clearart downloaded for %s" % self.show_name
  261. else:
  262. self.clearart_found = self.clearart_found +1
  263. if DEBUG: print "### %s already exist, skipping" % self.filename
  264. self.image_url = False
  265. self.filename = False
  266.  
  267. if self.show_thumb:
  268. if DEBUG: print "### Search showthumb for %s" % self.show_name
  269. if self.show_thumb == "True": self.filename = "folder.jpg"
  270. else: self.filename = self.show_thumb
  271. if not os.path.exists( os.path.join( self.show_path , self.filename ) ):
  272. if self.search_show_thumb():
  273. if DEBUG: print "### found show thumb for %s" % self.show_name
  274. if self.download_image():
  275. self.thumb_download = self.thumb_download +1
  276. if DEBUG: print "### showthumb downloaded for %s" % self.show_name
  277. else:
  278. self.thumb_found = self.thumb_found + 1
  279. if DEBUG: print "### %s already exist, skipping" % self.filename
  280. self.image_url = False
  281. self.filename = False
  282.  
  283. if self.poster or self.banner:
  284. if DEBUG: print "### get tvdb xml"
  285. self.get_tvdb_xml()
  286.  
  287. if self.poster:
  288. if DEBUG: print "### Search poster for %s" % self.show_name
  289. if self.poster == "True": self.filename = "folder.jpg"
  290. else: self.filename = self.poster
  291. if not os.path.exists( os.path.join( self.show_path , self.filename ) ):
  292. if self.search_poster():
  293. if DEBUG: print "### found show thumb for %s" % self.show_name
  294. if self.download_image():
  295. self.poster_download = self.poster_download +1
  296. if DEBUG: print "### poster downloaded for %s" % self.show_name
  297. else:
  298. self.poster_found = self.poster_found + 1
  299. if DEBUG: print "### %s already exist, skipping" % self.filename
  300. self.image_url = False
  301. self.filename = False
  302.  
  303. if self.banner:
  304. if DEBUG: print "### Search banner for %s" % self.show_name
  305. if self.banner == "True": self.filename = "folder.jpg"
  306. else: self.filename = self.banner
  307. if not os.path.exists( os.path.join( self.show_path , self.filename ) ):
  308. if self.search_banner():
  309. if DEBUG: print "### found show thumb for %s" % self.show_name
  310. if self.download_image():
  311. self.banner_download = self.banner_download +1
  312. if DEBUG: print "### banner downloaded for %s" % self.show_name
  313. else:
  314. self.banner_found = self.banner_found + 1
  315. if DEBUG: print "### %s already exist, skipping" % self.filename
  316. self.image_url = False
  317. self.filename = False
  318.  
  319. self.reinit()
  320. except:
  321. print "error with: %s" % currentshow
  322. print_exc()
  323. DIALOG_PROGRESS.close()
  324. print "total tvshow = %s" % len(self.TVlist)
  325. print "logo found = %s" % self.logo_found
  326. print "logo download = %s" % self.logo_download
  327. print "thumb found = %s" % self.thumb_found
  328. print "thumb download = %s" % self.thumb_download
  329. print "clearart found = %s" % self.clearart_found
  330. print "clearart download = %s" % self.clearart_download
  331. print "banner found = %s" % self.banner_found
  332. print "banner download = %s" % self.banner_download
  333. print "poster found = %s" % self.poster_found
  334. print "poster download = %s" % self.poster_download
  335. msg = "DOWNLOADED: "
  336. msg2 ="FOUND: "
  337. if self.logo:
  338. msg = msg + "logo: %s " % self.logo_download
  339. msg2 = msg2 + "logo: %s " % self.logo_found
  340. if self.clearart:
  341. msg = msg + "clearart: %s " % self.clearart_download
  342. msg2 = msg2 + "clearart: %s " % self.clearart_found
  343. if self.show_thumb:
  344. msg = msg + "thumb: %s " % self.thumb_download
  345. msg2 = msg2 + "thumb: %s " % self.thumb_found
  346. if self.poster:
  347. msg = msg + "poster: %s " % self.poster_download
  348. msg2 = msg2 + "poster: %s " % self.poster_found
  349. if self.banner:
  350. msg = msg + "banner: %s " % self.banner_download
  351. msg2 = msg2 + "banner: %s " % self.banner_found
  352.  
  353. xbmcgui.Dialog().ok('SUMMARY %s TVSHOWS' % len(self.TVlist) , msg , msg2 )
  354. xbmcgui.Dialog().ok('LOGO DOWNLOADER NEEDS YOU', "Please help us to get more art on" , "http://fanart.tv / www.tvdb.com".upper() )
  355. def reinit(self):
  356. if DEBUG: print "### reinit"
  357. self.show_path = False
  358. self.tvdbid = False
  359. self.show_name = ""
  360. self.xbmcstuff_xml = False
  361. self.lockstock_xml = False
  362. self.tvdb_xml = False
  363.  
  364. def print_class_var(self):
  365. try: print "###show name: %s" % self.show_name
  366. except: print "###show name:"
  367. try: print "###mode: %s" % self.mode
  368. except: print "###mode:"
  369. try: print "###clearart: %s" % self.clearart
  370. except: print "###clearart:"
  371. try: print "###logo: %s" % self.logo
  372. except: print "###logo:"
  373. try: print "###thumb: %s" % self.show_thumb
  374. except: print "###thumb:"
  375. try: print "###show path: %s" % self.show_path
  376. except: print "###show path:"
  377. try: print "###id: %s" % self.tvdbid
  378. except: print "###id:"
  379. try: print "###lockstock xml: %s" % self.lockstock_xml
  380. except: print "###lockstock xml:"
  381. try: print "###image list: %s" % self.image_list
  382. except: print "###image list:"
  383. try: print "###image url: %s" % self.image_url
  384. except: print "###image url:"
  385. try: print "###filename: %s" % self.filename
  386. except: print "###filename:"
  387. try: print "###xbmcstuff_xml: %s" % self.xbmcstuff_xml
  388. except: print "###xbmcstuff_xml:"
  389.  
  390. def TV_listing(self):
  391. # sql statement for tv shows
  392. sql_data = "select tvshow.c00 , tvshow.c12 , path.strPath from tvshow , path , tvshowlinkpath where path.idPath = tvshowlinkpath.idPath AND tvshow.idShow = tvshowlinkpath.idShow"
  393. xml_data = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % urllib.quote_plus( sql_data ), )
  394. if DEBUG: print "### xml data: %s" % xml_data
  395. match = re.findall( "<field>(.*?)</field><field>(.*?)</field><field>(.*?)</field>", xml_data, re.DOTALL )
  396.  
  397. try:
  398. self.TVlist = []
  399. for import_base in match:
  400. try:
  401. if DEBUG: print import_base
  402. TVshow = {}
  403. TVshow["name"] = repr(import_base[0]).strip("'u")
  404. TVshow["id"] = repr(import_base[1]).strip("'u")
  405. TVshow["path"] = import_base[2]
  406. self.TVlist.append(TVshow)
  407. except: print_exc()
  408. except:
  409. print_exc()
  410. print "### no tvshow found in db"
  411.  
  412. def get_tvid_path( self ):
  413. sql_data = 'select tvshow.c12 , path.strpath from tvshow,tvshowlinkpath,path where tvshow.idShow=tvshowlinkpath.idshow and tvshowlinkpath.idpath=path.idpath and tvshow.c00=\"%s\"' % (self.show_name)
  414. xml_data = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % urllib.quote_plus( sql_data ), )
  415. match = re.findall( "<field>(.*?)</field><field>(.*?)</field>", xml_data, re.DOTALL )
  416. try:
  417. self.tvdbid = match[0][0]
  418. self.show_path = match[0][1]
  419. except:
  420. print_exc()
  421. if DEBUG:
  422. print "sql dat: %s" % sql_data
  423. print "xml dat: %s" % xml_data
  424.  
  425. def id_verif(self):
  426. if self.tvdbid[0:2] == "tt" or self.tvdbid == "" :
  427. print "### IMDB id found (%s) or no id found in db, checking for nfo" % self.show_path
  428. try: self.tvdbid = self.get_nfo_id()
  429. except:
  430. self.tvdbid = False
  431. print "### Error checking for nfo: %stvshow.nfo" % self.show_path.replace("\\\\" , "\\")
  432. print_exc()
  433.  
  434. def get_nfo_id( self ):
  435. nfo= os.path.join(self.show_path , "tvshow.nfo")
  436. print "### nfo file: %s" % nfo
  437. if os.path.isfile(nfo):
  438. nfo_read = file(nfo, "r" ).read()
  439. print nfo_read
  440. else: print "###tvshow.nfo not found !"
  441. tvdb_id = re.findall( "<tvdbid>(\d{1,10})</tvdbid>", nfo_read ) or re.findall( "<id>(\d{1,10})</id>", nfo_read )
  442. if tvdb_id:
  443. print "### tvdb id: %s" % tvdb_id[0]
  444. return tvdb_id[0]
  445. else:
  446. print "### no tvdb id found in: %s" % nfo
  447. return False
  448.  
  449. def get_lockstock_xml(self):
  450. self.lockstock_xml = get_html_source( "http://fanart.tv/api/fanart.php?id=" + self.tvdbid )
  451. if DEBUG: print self.lockstock_xml
  452.  
  453. # def get_xbmcstuff_xml(self):
  454. # self.xbmcstuff_xml = get_html_source ("http://www.xbmcstuff.com/tv_scraper.php?&id_scraper=p7iuVTQXQWGyWXPS&size=big&thetvdb=" + self.tvdbid )
  455.  
  456. def get_tvdb_xml(self):
  457. self.tvdb_xml = get_html_source ("http://www.thetvdb.com/api/F90E687D789D7F7C/series/%s/banners.xml" % self.tvdbid )
  458.  
  459. def search_logo( self ):
  460. match = re.findall("""<clearlogo url="(.*?)"/>""" , self.lockstock_xml)
  461. if match:
  462. if self.mode == "solo" : self.image_list = match
  463. if self.mode == "bulk" : self.image_url = match[0]
  464. return True
  465. else:
  466. print "### No logo found !"
  467. if self.mode == "solo": xbmcgui.Dialog().ok("Not Found" , "No logo found!" )
  468. self.image_list = False
  469. return False
  470.  
  471. def search_clearart( self ):
  472. match = re.findall("""<clearart url="(.*?)"/>""" , self.lockstock_xml)
  473. if match:
  474. if self.mode == "solo" : self.image_list = match
  475. if self.mode == "bulk" : self.image_url = match[0]
  476. return True
  477. else:
  478. print "### No clearart found !"
  479. if self.mode == "solo": xbmcgui.Dialog().ok("Not Found" , "No clearart found!" )
  480. self.image_list = False
  481. return False
  482.  
  483. def search_show_thumb( self ):
  484. match = re.findall("""<tvthumb url="(.*?)"/>""" , self.lockstock_xml)
  485. if match:
  486. if self.mode == "solo" : self.image_list = match
  487. if self.mode == "bulk" : self.image_url = match[0]
  488. return True
  489. else:
  490. print "### No show thumb found !"
  491. if self.mode == "solo": xbmcgui.Dialog().ok("Not Found" , "No show thumb found!" )
  492. self.image_list = False
  493. return False
  494.  
  495. def search_poster( self ):
  496. match = re.findall("<BannerPath>(.*?)</BannerPath>\s+<BannerType>poster</BannerType>" , self.tvdb_xml)
  497. if match:
  498. if self.mode == "solo" :
  499. self.image_list = []
  500. for i in match:
  501. self.image_list.append("http://www.thetvdb.com/banners/" + i)
  502. if self.mode == "bulk" : self.image_url = "http://www.thetvdb.com/banners/" + match[0]
  503.  
  504. return True
  505.  
  506. def search_banner( self ):
  507. match = re.findall("<BannerPath>(.*?)</BannerPath>\s+<BannerType>series</BannerType>" , self.tvdb_xml)
  508. if match:
  509. if self.mode == "solo" :
  510. self.image_list = []
  511. for i in match:
  512. self.image_list.append("http://www.thetvdb.com/banners/" + i)
  513. if self.mode == "bulk" : self.image_url = "http://www.thetvdb.com/banners/" + match[0]
  514.  
  515. return True
  516.  
  517. def choice_type(self):
  518. select = xbmcgui.Dialog().select("choose what to download" , self.type_list)
  519. if select == -1:
  520. print "### Canceled by user"
  521. xbmcgui.Dialog().ok("Canceled" , "Download canceled by user" )
  522. return False
  523. else:
  524. if self.type_list[select] == "logo" : self.clearart = self.show_thumb = self.banner = self.poster = False
  525. elif self.type_list[select] == "showthumb" : self.clearart = self.logo = self.banner = self.poster = False
  526. elif self.type_list[select] == "clearart" : self.logo = self.show_thumb = self.banner = self.poster = False
  527. elif self.type_list[select] == "banner" : self.logo = self.show_thumb = self.clearart = self.poster = False
  528. elif self.type_list[select] == "poster" : self.logo = self.show_thumb = self.banner = self.clearart = False
  529. return True
  530.  
  531. def choose_image(self):
  532. #select = xbmcgui.Dialog().select("Which one to download ?" , self.image_list)
  533. if DEBUG: print self.image_list
  534. self.image_url = MyDialog(self.image_list)
  535. if self.image_url: return True
  536. else: return False
  537. # if select == -1:
  538. # print "### Canceled by user"
  539. # xbmcgui.Dialog().ok("Canceled" , "Download canceled by user" )
  540. # self.image_url = False
  541. # return False
  542. # else:
  543. # self.image_url = self.image_list[select]
  544. # return True
  545.  
  546. def erase_current_cache(self):
  547. try:
  548.  
  549. if not self.filename == "folder.jpg": cached_thumb = thumbnails.get_cached_video_thumb( os.path.join( self.show_path , self.filename )).replace( "\\Video" , "").replace("tbn" , "png")
  550. else: cached_thumb = thumbnails.get_cached_video_thumb(self.show_path)
  551. print "### cache %s" % cached_thumb
  552. shutil.copy2( os.path.join( self.show_path , self.filename ) , cached_thumb )
  553. xbmc.executebuiltin( 'XBMC.ReloadSkin()' )
  554. except :
  555. print_exc()
  556. print "### cache erasing error"
  557.  
  558. def download_image( self ):
  559. DIALOG_DOWNLOAD.create( "Downloading: %s " % self.show_name , "Getting info ..." )
  560. destination = os.path.join( self.show_path , self.filename )
  561. print "### download :" + self.image_url
  562. if DEBUG: "### path: " + repr(destination).strip("'u")
  563.  
  564. try:
  565. def _report_hook( count, blocksize, totalsize ):
  566. percent = int( float( count * blocksize * 100 ) / totalsize )
  567. strProgressBar = str( percent )
  568. if DEBUG: print percent #DEBUG
  569. DIALOG_DOWNLOAD.update( percent , "Downloading: %s " % self.show_name , "Downloading: %s" % self.filename )
  570. if os.path.exists(self.show_path):
  571. fp , h = urllib.urlretrieve( self.image_url.replace(" ", "%20") , destination , _report_hook )
  572. if DEBUG: print h
  573. DIALOG_DOWNLOAD.close
  574. if self.mode == "solo": self.erase_current_cache()
  575. return True
  576. else : print "problem with path: %s" % self.show_path
  577. except :
  578. print "### Image download Failed !!! (download_logo)"
  579. print_exc()
  580. return False
  581.  
  582. class MainGui( xbmcgui.WindowXMLDialog ):
  583. def __init__( self, *args, **kwargs ):
  584. xbmcgui.WindowXMLDialog.__init__( self, *args, **kwargs )
  585. xbmc.executebuiltin( "Skin.Reset(AnimeWindowXMLDialogClose)" )
  586. xbmc.executebuiltin( "Skin.SetBool(AnimeWindowXMLDialogClose)" )
  587. self.listing = kwargs.get( "listing" )
  588.  
  589. def onInit(self):
  590. try :
  591. self.img_list = self.getControl(6)
  592. self.img_list.controlLeft(self.img_list)
  593. self.img_list.controlRight(self.img_list)
  594.  
  595. self.getControl(3).setVisible(False)
  596. except :
  597. print_exc()
  598. self.img_list = self.getControl(3)
  599.  
  600. self.getControl(5).setVisible(False)
  601.  
  602. for image in self.listing :
  603. listitem = xbmcgui.ListItem( image.split("/")[-1] )
  604. listitem.setIconImage( image )
  605. listitem.setLabel2(image)
  606. print image
  607. self.img_list.addItem( listitem )
  608. self.setFocus(self.img_list)
  609.  
  610. def onAction(self, action):
  611. #Close the script
  612. if action == ACTION_PREVIOUS_MENU :
  613. self.close()
  614.  
  615. def onClick(self, controlID):
  616. print controlID
  617. """
  618. Notice: onClick not onControl
  619. Notice: it gives the ID of the control not the control object
  620. """
  621. #action sur la liste
  622. if controlID == 6 or controlID == 3:
  623. #Renvoie l'item selectionne
  624. num = self.img_list.getSelectedPosition()
  625. print num
  626. self.selected_url = self.img_list.getSelectedItem().getLabel2()
  627. self.close()
  628.  
  629. def onFocus(self, controlID):
  630. pass
  631.  
  632. def MyDialog(tv_list):
  633. w = MainGui( "DialogSelect.xml", SOURCEPATH, listing=tv_list )
  634. w.doModal()
  635. try: return w.selected_url
  636. except:
  637. print_exc()
  638. return False
  639. del w
  640.  
  641. if ( __name__ == "__main__" ):
  642. footprints()
  643. downloader()
  644. print "### logo downloader exiting..."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement