Advertisement
WelshPaul

Draft Score Code

Apr 28th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. '''
  2. Application ID 49a5ba91
  3. Application Keys d31dde72176c31c2fe25bafca534cd01
  4. '''
  5.  
  6. # Import Libraries
  7. import urllib
  8. import urllib2
  9. import os
  10. import xbmcaddon
  11. import xbmcgui
  12. import xbmcvfs
  13. import json
  14. import sys
  15. import xbmc
  16. import re
  17.  
  18. # Used to identify the path from Addon.xml to save temp items in userdata\addondata folder
  19. __addon__ = xbmcaddon.Addon()
  20. __addonid__ = __addon__.getAddonInfo('id') #should be script.scores
  21. __cwd__ = xbmc.translatePath(__addon__.getAddonInfo('path')).decode("utf-8")
  22. __profile__ = xbmc.translatePath(__addon__.getAddonInfo('profile')).decode("utf-8")
  23. __language__ = __addon__.getLocalizedString
  24.  
  25.  
  26. # get the track information from tag
  27. def search_term():
  28. full_name = xbmc.Player().getMusicInfoTag().getArtist()
  29. list_name = re.sub("[^\w]", " ", full_name).split()
  30. last_name = list_name[-1]
  31. composition = xbmc.Player().getMusicInfoTag().getAlbum()
  32. title = xbmc.Player().getMusicInfoTag().getTitle()
  33. search_term = full_name + " " + title + " " + composition
  34. print ('search term', search_term)
  35. return search_term
  36.  
  37. def locate_image(*args):
  38. Metadata_URL = 'http://www.peachnote.com/rest/api/v0/scoreSearchMeta?app_id=49a5ba91&app_key=d31dde72176c31c2fe25bafca534cd01&limit=1&q=' + search_term()
  39. response = urllib.urlopen(Metadata_URL)
  40. Metadata = response.read()
  41. response.close()
  42. unpacked_info = json.loads(Metadata)
  43. scoreId = unpacked_info['items'][0]['scoreId']
  44. total_pages = unpacked_info['items'][0]['pageCount']
  45. for i in args:
  46. global page
  47. page = i
  48. print ('scoreId is ', scoreId)
  49. Image_URL = 'http://www.peachnote.com/rest/api/v0/image?sid=' + scoreId + '&page=' + str(page) + '&w=300'
  50. print ('image url is ', Image_URL)
  51. return Image_URL, total_pages, page
  52.  
  53. def create_file():
  54. # This should create folder to store temp file - THIS WORKS - HOOORAY
  55. path = xbmc.translatePath('special://profile/addon_data/%s' % __addonid__)
  56. if not xbmcvfs.exists(path):
  57. xbmcvfs.mkdir(path)
  58. # This should set the destination for the scanned file - THIS WORKS - EVEN BIGGER HOORAY
  59. imagefile = os.path.join(path, 'score.png')
  60. # scan the image - retrieve, from (Base_URL) to (imagefile) - THIS WORKS (WOW)
  61. return imagefile
  62.  
  63. class MyClass(xbmcgui.WindowXMLDialog):
  64. def __init__( self, xmlFile, resourcePath ):
  65. urllib.urlretrieve(locate_image(1)[0], create_file())
  66. self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, create_file()))
  67.  
  68. def onClick(self, action):
  69. page = locate_image()[2]
  70. if action == 1001:
  71. page = page +1
  72. locate_image(page)
  73. urllib.urlretrieve(locate_image(page)[0], create_file())
  74. self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, create_file()))
  75. print ('onClick returns: ', page)
  76.  
  77. mydisplay = MyClass("custom1.xml" , __addon__.getAddonInfo('path'))
  78. mydisplay.doModal()
  79.  
  80. del mydisplay
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement