Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Application ID 49a5ba91
- Application Keys d31dde72176c31c2fe25bafca534cd01
- '''
- # Import Libraries
- import urllib
- import urllib2
- import os
- import xbmcaddon
- import xbmcgui
- import xbmcvfs
- import json
- import sys
- import xbmc
- import re
- # Used to identify the path from Addon.xml to save temp items in userdata\addondata folder
- __addon__ = xbmcaddon.Addon()
- __addonid__ = __addon__.getAddonInfo('id') #should be script.scores
- __cwd__ = xbmc.translatePath(__addon__.getAddonInfo('path')).decode("utf-8")
- __profile__ = xbmc.translatePath(__addon__.getAddonInfo('profile')).decode("utf-8")
- __language__ = __addon__.getLocalizedString
- # get the track information from tag
- def search_term():
- full_name = xbmc.Player().getMusicInfoTag().getArtist()
- list_name = re.sub("[^\w]", " ", full_name).split()
- last_name = list_name[-1]
- composition = xbmc.Player().getMusicInfoTag().getAlbum()
- title = xbmc.Player().getMusicInfoTag().getTitle()
- search_term = full_name + " " + title + " " + composition
- print ('search term', search_term)
- return search_term
- def locate_image(*args):
- Metadata_URL = 'http://www.peachnote.com/rest/api/v0/scoreSearchMeta?app_id=49a5ba91&app_key=d31dde72176c31c2fe25bafca534cd01&limit=1&q=' + search_term()
- response = urllib.urlopen(Metadata_URL)
- Metadata = response.read()
- response.close()
- unpacked_info = json.loads(Metadata)
- scoreId = unpacked_info['items'][0]['scoreId']
- total_pages = unpacked_info['items'][0]['pageCount']
- for i in args:
- global page
- page = i
- print ('scoreId is ', scoreId)
- Image_URL = 'http://www.peachnote.com/rest/api/v0/image?sid=' + scoreId + '&page=' + str(page) + '&w=300'
- print ('image url is ', Image_URL)
- return Image_URL, total_pages, page
- def create_file():
- # This should create folder to store temp file - THIS WORKS - HOOORAY
- path = xbmc.translatePath('special://profile/addon_data/%s' % __addonid__)
- if not xbmcvfs.exists(path):
- xbmcvfs.mkdir(path)
- # This should set the destination for the scanned file - THIS WORKS - EVEN BIGGER HOORAY
- imagefile = os.path.join(path, 'score.png')
- # scan the image - retrieve, from (Base_URL) to (imagefile) - THIS WORKS (WOW)
- return imagefile
- class MyClass(xbmcgui.WindowXMLDialog):
- def __init__( self, xmlFile, resourcePath ):
- urllib.urlretrieve(locate_image(1)[0], create_file())
- self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, create_file()))
- def onClick(self, action):
- page = locate_image()[2]
- if action == 1001:
- page = page +1
- locate_image(page)
- urllib.urlretrieve(locate_image(page)[0], create_file())
- self.addControl = (xbmcgui.ControlImage(5, 10, 500, 650, create_file()))
- print ('onClick returns: ', page)
- mydisplay = MyClass("custom1.xml" , __addon__.getAddonInfo('path'))
- mydisplay.doModal()
- del mydisplay
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement