From ebfdbd3079f531f149d45b03e3babfd022bd4076 Mon Sep 17 00:00:00 2001 From: m-kro Date: Tue, 14 Jan 2025 20:55:02 +0100 Subject: [PATCH] update to python3 and use other audio source #1 Signed-off-by: m-kro --- addon.xml | 4 ++-- default.py | 33 +++++++++++++-------------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/addon.xml b/addon.xml index 7a298dc..fc59db4 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ - + - + diff --git a/default.py b/default.py index d1189e9..a46df33 100644 --- a/default.py +++ b/default.py @@ -1,8 +1,6 @@ -# https://docs.python.org/2.7/ import os import sys -import urllib -import urlparse +import urllib.request, urllib.parse, urllib.error # http://mirrors.kodi.tv/docs/python-docs/ import xbmcaddon import xbmcgui @@ -14,7 +12,7 @@ def build_url(query): base_url = sys.argv[0] - return base_url + '?' + urllib.urlencode(query) + return base_url + '?' + urllib.parse.urlencode(query) def get_page(url): # download the source HTML for the page using requests @@ -27,17 +25,14 @@ def parse_page(page): # the sample below is specific for the page we are scraping # you will need to view the source of the page(s) you are # planning to scrape to find the content you want to display - # this will return all the elements on the page: - # some_text - for item in page.find_all('a'): - # the item contains a link to an album cover - if item['href'].find('.jpg') > 1: - # format the url for the album cover to include the site url and url encode any spaces - album_cover = '{0}{1}'.format(sample_page, item['href'].replace(' ', '%20')) + # this will return all the elements on the page: + # + for item in page.find_all('source', attrs={}): # the item contains a link to a song containing '.mp3' - if item['href'].find('.mp3') > 1: - # update dictionary with the album cover url, song filename, and song url - songs.update({index: {'album_cover': album_cover, 'title': item['href'], 'url': '{0}{1}'.format(sample_page, item['href'])}}) + if item.has_attr('src') and item['src'].find('.mp3') > 1: + # update dictionary with the song filename, and song url + # Github way of download URLs + songs.update({index: {'title': item['src'], 'url': '{0}{1}'.format(sample_page, item['src'])}}) index += 1 return songs @@ -46,9 +41,7 @@ def build_song_list(songs): # iterate over the contents of the dictionary songs to build the list for song in songs: # create a list item using the song filename for the label - li = xbmcgui.ListItem(label=songs[song]['title'], thumbnailImage=songs[song]['album_cover']) - # set the fanart to the albumc cover - li.setProperty('fanart_image', songs[song]['album_cover']) + li = xbmcgui.ListItem(label=songs[song]['title']) # set the list item to playable li.setProperty('IsPlayable', 'true') # build the plugin url for Kodi @@ -70,12 +63,12 @@ def play_song(url): xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item) def main(): - args = urlparse.parse_qs(sys.argv[2][1:]) + args = urllib.parse.parse_qs(sys.argv[2][1:]) mode = args.get('mode', None) # initial launch of add-on if mode is None: - # get the HTML for http://www.theaudiodb.com/testfiles/ + # get the HTML for https://audio-samples.github.io/ page = get_page(sample_page) # get the content needed from the page content = parse_page(page) @@ -87,6 +80,6 @@ def main(): play_song(args['url'][0]) if __name__ == '__main__': - sample_page = 'http://www.theaudiodb.com/testfiles/' + sample_page = 'https://audio-samples.github.io/' addon_handle = int(sys.argv[1]) main() \ No newline at end of file