From b455077ff8087611792793f329a13bc0e344a746 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 10 Feb 2020 21:29:30 +0000 Subject: [PATCH] Allow searching past the first page of songs Previously the first ten songs were just repeated --- openlp/plugins/songs/forms/songselectform.py | 4 +++- openlp/plugins/songs/lib/songselect.py | 9 +++++++-- .../functional/openlp_plugins/songs/test_songselect.py | 10 +++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/songs/forms/songselectform.py b/openlp/plugins/songs/forms/songselectform.py index 678d57570..d454d45d0 100644 --- a/openlp/plugins/songs/forms/songselectform.py +++ b/openlp/plugins/songs/forms/songselectform.py @@ -344,7 +344,9 @@ class SongSelectForm(QtWidgets.QDialog, Ui_SongSelectDialog, RegistryProperties) self.song_count += 1 self.result_count_label.setText(translate('SongsPlugin.SongSelectForm', 'Found {count:d} song(s)').format(count=self.song_count)) - item_title = song['title'] + ' (' + ', '.join(song['authors']) + ')' + item_title = song['title'] + if song['authors']: + item_title += ' (' + ', '.join(song['authors']) + ')' song_item = QtWidgets.QListWidgetItem(item_title, self.search_results_widget) song_item.setData(QtCore.Qt.UserRole, song) diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index 2f4ac5e62..7720501f8 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -175,7 +175,7 @@ class SongSelectImport(object): songs = [] while self.run_search: if current_page > 1: - params['page'] = current_page + params['CurrentPage'] = current_page try: results_page = BeautifulSoup(self.opener.open(SEARCH_URL + '?' + urlencode(params)).read(), 'lxml') search_results = results_page.find_all('div', 'song-result') @@ -196,9 +196,14 @@ class SongSelectImport(object): songs.append(song) break for result in search_results: + authors = result.find('p', 'song-result-subtitle').string + if authors: + authors = unescape(authors).strip().split(', ') + else: + authors = "" song = { 'title': unescape(result.find('p', 'song-result-title').find('a').string).strip(), - 'authors': unescape(result.find('p', 'song-result-subtitle').string).strip().split(', '), + 'authors': authors, 'link': BASE_URL + result.find('p', 'song-result-title').find('a')['href'] } if callback: diff --git a/tests/functional/openlp_plugins/songs/test_songselect.py b/tests/functional/openlp_plugins/songs/test_songselect.py index b2259f3d4..82e475646 100644 --- a/tests/functional/openlp_plugins/songs/test_songselect.py +++ b/tests/functional/openlp_plugins/songs/test_songselect.py @@ -246,15 +246,15 @@ class TestSongSelectImport(TestCase, TestMixin): # first search result mocked_result1 = MagicMock() mocked_result1.find.side_effect = [ - MagicMock(find=MagicMock(return_value=MagicMock(string='Title 1'))), MagicMock(string='James, John'), + MagicMock(find=MagicMock(return_value=MagicMock(string='Title 1'))), MagicMock(find=MagicMock(return_value={'href': '/url1'})) ] # second search result mocked_result2 = MagicMock() mocked_result2.find.side_effect = [ - MagicMock(find=MagicMock(return_value=MagicMock(string='Title 2'))), MagicMock(string='Philip'), + MagicMock(find=MagicMock(return_value=MagicMock(string='Title 2'))), MagicMock(find=MagicMock(return_value={'href': '/url2'})) ] # rest of the stuff @@ -291,22 +291,22 @@ class TestSongSelectImport(TestCase, TestMixin): # first search result mocked_result1 = MagicMock() mocked_result1.find.side_effect = [ - MagicMock(find=MagicMock(return_value=MagicMock(string='Title 1'))), MagicMock(string='James, John'), + MagicMock(find=MagicMock(return_value=MagicMock(string='Title 1'))), MagicMock(find=MagicMock(return_value={'href': '/url1'})) ] # second search result mocked_result2 = MagicMock() mocked_result2.find.side_effect = [ - MagicMock(find=MagicMock(return_value=MagicMock(string='Title 2'))), MagicMock(string='Philip'), + MagicMock(find=MagicMock(return_value=MagicMock(string='Title 2'))), MagicMock(find=MagicMock(return_value={'href': '/url2'})) ] # third search result mocked_result3 = MagicMock() mocked_result3.find.side_effect = [ - MagicMock(find=MagicMock(return_value=MagicMock(string='Title 3'))), MagicMock(string='Luke, Matthew'), + MagicMock(find=MagicMock(return_value=MagicMock(string='Title 3'))), MagicMock(find=MagicMock(return_value={'href': '/url3'})) ] # rest of the stuff