From 670bf0107b819c328d20bfd7c8940d977940385c Mon Sep 17 00:00:00 2001 From: warwickh Date: Fri, 3 Feb 2023 09:26:33 +1100 Subject: [PATCH] Update main.py Include feature from GioF71 [Feature] Search Album --- main.py | 73 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index 6f9fe5f..4f70b7b 100644 --- a/main.py +++ b/main.py @@ -108,6 +108,11 @@ def root(params): 'callback': 'search', 'thumb': None }, + 'searchalbum': { + 'name': Addon().get_localized_string(30045), + 'callback': 'search_album', + 'thumb': None + }, } # Iterate through categories @@ -579,27 +584,61 @@ def search(params): dialog = xbmcgui.Dialog() d = dialog.input(Addon().get_localized_string(30039), type=xbmcgui.INPUT_ALPHANUM) - if not d: - d = " " - - - # get connection - connection = get_connection() - - if connection==False: - return listing = [] - # Get items - items = connection.search2(query=d) - # Iterate through items - for item in items.get('searchResult2').get('song'): - entry = get_entry_track( item, params) - listing.append(entry) + if d: + # get connection + connection = get_connection() - if len(listing) == 1: - plugin.log('One single Media Folder found; do return listing from browse_indexes()...') + if connection == False: + return + + # Get items + items = connection.search2(query=d) + # Iterate through items + songs = items.get('searchResult2').get('song') + if songs: + for item in songs: + entry = get_entry_track( item, params) + listing.append(entry) + + if len(listing) == 0: + plugin.log('No songs found; do return listing from browse_indexes()...') + return browse_indexes(params) + else: + add_directory_items(create_listing(listing)) + + +@plugin.action() +def search_album(params): + + dialog = xbmcgui.Dialog() + d = dialog.input(Addon().get_localized_string(30045), type=xbmcgui.INPUT_ALPHANUM) + + listing = [] + + if d: + # get connection + connection = get_connection() + if connection==False: + return + # Get items, we are only looking for albums here + # so artistCount and songCount is set to 0 + items = connection.search2(query=d, artistCount=0, songCount=0) + # Iterate through items + + album_list = items.get('searchResult2').get('album') + if album_list: + for item in items.get('searchResult2').get('album'): + entry = get_entry_album( item, params) + listing.append(entry) + + # I believe it is ok to return an empty listing if + # the search gave no result + # maybe inform the user? + if len(listing) == 0: + plugin.log('No albums found; do return listing from browse_indexes()...') return browse_indexes(params) else: add_directory_items(create_listing(listing))