From e59b65d5e099971a7c994314b27c7d35148e4563 Mon Sep 17 00:00:00 2001 From: Giovanni Fulco Date: Thu, 2 Feb 2023 19:43:09 +0100 Subject: [PATCH] [Feature] Search Album --- main.py | 73 ++++++++++++++++++++------- resources/language/English/strings.po | 6 ++- resources/language/French/strings.po | 8 ++- resources/language/German/strings.po | 8 ++- 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 7980f10..e4f14e6 100644 --- a/main.py +++ b/main.py @@ -107,6 +107,11 @@ def root(params): 'callback': 'search', 'thumb': None }, + 'searchalbum': { + 'name': Addon().get_localized_string(30045), + 'callback': 'search_album', + 'thumb': None + }, } # Iterate through categories @@ -578,27 +583,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)) diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index cf0e1e6..136d178 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -154,7 +154,7 @@ msgid "Browse" msgstr "" msgctxt "#30039" -msgid "Search" +msgid "Search Songs" msgstr "" msgctxt "#30040" @@ -176,3 +176,7 @@ msgstr "" msgctxt "#30044" msgid "Scrobble to Last.FM" msgstr "" + +msgctxt "#30045" +msgid "Search Albums" +msgstr "" diff --git a/resources/language/French/strings.po b/resources/language/French/strings.po index 88f7515..ecf0aef 100644 --- a/resources/language/French/strings.po +++ b/resources/language/French/strings.po @@ -153,8 +153,8 @@ msgid "Browse" msgstr "Parcourir" msgctxt "#30039" -msgid "Search" -msgstr "Rechercher" +msgid "Search Songs" +msgstr "Rechercher Chansons" msgctxt "#30040" @@ -176,3 +176,7 @@ msgstr "" msgctxt "#30044" msgid "Scrobble to Last.FM" msgstr "" + +msgctxt "#30045" +msgid "Search Albums" +msgstr "Rechercher Albums" diff --git a/resources/language/German/strings.po b/resources/language/German/strings.po index 46ba647..4c74bc7 100644 --- a/resources/language/German/strings.po +++ b/resources/language/German/strings.po @@ -153,8 +153,8 @@ msgid "Browse" msgstr "Durchsuchen" msgctxt "#30039" -msgid "Search" -msgstr "Suche" +msgid "Search Songs" +msgstr "Suche Lieder" msgctxt "#30040" msgid "useGET" @@ -175,3 +175,7 @@ msgstr "" msgctxt "#30044" msgid "Scrobble to Last.FM" msgstr "" + +msgctxt "#30045" +msgid "Search Albums" +msgstr "Suche Albums"