diff --git a/app/src/androidTest/java/org/xbmc/kore/tests/ui/RestoreSearchQueryViewPagerTest.java b/app/src/androidTest/java/org/xbmc/kore/tests/ui/RestoreSearchQueryViewPagerTest.java index b152c16..1ecbc40 100644 --- a/app/src/androidTest/java/org/xbmc/kore/tests/ui/RestoreSearchQueryViewPagerTest.java +++ b/app/src/androidTest/java/org/xbmc/kore/tests/ui/RestoreSearchQueryViewPagerTest.java @@ -49,8 +49,8 @@ public class RestoreSearchQueryViewPagerTest { private final int ARTIST_SEARCH_QUERY_LIST_SIZE = 2; private final String ALBUMS_SEARCH_QUERY = "tes"; private final int ALBUM_SEARCH_QUERY_LIST_SIZE = 3; - private final int ARTIST_COMPLETE_LIST_SIZE = 227; - private final int ALBUM_COMPLETE_LIST_SIZE = 232; + private final int ARTIST_COMPLETE_LIST_SIZE = 228; + private final int ALBUM_COMPLETE_LIST_SIZE = 234; private LoaderIdlingResource loaderIdlingResource; diff --git a/app/src/test/java/org/xbmc/kore/provider/mediaprovider/AlbumsTest.java b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/AlbumsTest.java new file mode 100644 index 0000000..ab9bd23 --- /dev/null +++ b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/AlbumsTest.java @@ -0,0 +1,120 @@ +/* + * Copyright 2016 Martijn Brekhof. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.xbmc.kore.provider.mediaprovider; + +import android.database.Cursor; +import android.net.Uri; + +import org.junit.Test; +import org.xbmc.kore.provider.MediaContract; +import org.xbmc.kore.testutils.CursorUtils; +import org.xbmc.kore.testutils.TestUtils; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class AlbumsTest extends AbstractTestClass { + + @Test + public void queryAllAlbumsTest() { + Uri uri = MediaContract.Albums.buildAlbumsListUri(hostInfo.getId()); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.Album.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 234, cursor.getCount()); + int columnIndex = cursor.getColumnIndex(MediaContract.AlbumsColumns.ALBUMID); + TestUtils.testCursorContainsRange(cursor, columnIndex, 1, 75); + TestUtils.testCursorContainsRange(cursor, columnIndex, 77, 82); + TestUtils.testCursorContainsRange(cursor, columnIndex, 84, 235); + } + + @Test + public void queryAlbumTest() { + Uri uri = MediaContract.Albums.buildAlbumUri(hostInfo.getId(), TestValues.Album.albumId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.Album.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + TestValues.Album.test(cursor); + } + + @Test + public void queryAlbumsForArtistTest() { + Uri uri = MediaContract.AlbumArtists.buildAlbumsForArtistListUri(hostInfo.getId(), + TestValues.Artist.artistId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.Album.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + TestValues.Album.test(cursor); + } + + @Test + public void queryAlbumsForArtistWithVariousArtistsTest() { + Uri uri = MediaContract.AlbumArtists.buildAlbumsForArtistListUri(hostInfo.getId(), + TestValues.AlbumWithVariousArtists.artistId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.AlbumWithVariousArtists.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 2, cursor.getCount()); + cursor.moveToFirst(); + + assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, + cursor.getColumnIndex(MediaContract.Albums.ALBUMID), + TestValues.AlbumWithVariousArtists.albumId)); + TestValues.AlbumWithVariousArtists.test(cursor); + + assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, + cursor.getColumnIndex(MediaContract.Albums.ALBUMID), + TestValues.AlbumWithVariousArtistsNoSongArtists.albumId)); + TestValues.AlbumWithVariousArtistsNoSongArtists.test(cursor); + } + + @Test + public void queryAlbumWithoutArtist() { + Uri uri = MediaContract.Albums.buildAlbumUri(hostInfo.getId(), + TestValues.AlbumWithoutArtist.albumId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.AlbumWithoutArtist.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + TestValues.AlbumWithoutArtist.test(cursor); + } + + @Test + public void queryAlbumWithMultipleArtists() { + Uri uri = MediaContract.Albums.buildAlbumUri(hostInfo.getId(), + TestValues.AlbumWithMultipleArtists.albumId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.AlbumWithMultipleArtists.PROJECTION, + null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + TestValues.AlbumWithMultipleArtists.test(cursor); + } +} \ No newline at end of file diff --git a/app/src/test/java/org/xbmc/kore/provider/mediaprovider/ArtistsTest.java b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/ArtistsTest.java new file mode 100644 index 0000000..bfab5ac --- /dev/null +++ b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/ArtistsTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2016 Martijn Brekhof. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.xbmc.kore.provider.mediaprovider; + +import android.database.Cursor; +import android.net.Uri; + +import org.junit.Test; +import org.xbmc.kore.provider.MediaContract; +import org.xbmc.kore.testutils.TestUtils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + + +public class ArtistsTest extends AbstractTestClass { + + @Test + public void queryAllArtistsTest() { + Uri uri = MediaContract.Artists.buildArtistsListUri(hostInfo.getId()); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.Artist.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 228, cursor.getCount()); + TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.ArtistsColumns.ARTISTID), + 1, 94); + //Artist id 95 should be missing + TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.ArtistsColumns.ARTISTID), + 96, 228); + } + + @Test + public void queryArtistTest() { + Uri uri = MediaContract.Artists.buildArtistUri(hostInfo.getId(), TestValues.Artist.artistId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.Artist.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + TestValues.Artist.test(cursor); + } +} \ No newline at end of file diff --git a/app/src/test/java/org/xbmc/kore/provider/mediaprovider/GenresTest.java b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/GenresTest.java new file mode 100644 index 0000000..4b39fae --- /dev/null +++ b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/GenresTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2016 Martijn Brekhof. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.xbmc.kore.provider.mediaprovider; + +import android.database.Cursor; +import android.net.Uri; + +import org.junit.Test; +import org.xbmc.kore.provider.MediaContract; +import org.xbmc.kore.testutils.TestUtils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class GenresTest extends AbstractTestClass { + @Test + public void queryAllGenresTest() { + Uri uri = MediaContract.AudioGenres.buildAudioGenresListUri(hostInfo.getId()); + + Cursor cursor = shadowContentResolver.query(uri, + new String[] {MediaContract.AudioGenresColumns.GENREID}, + null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 39, cursor.getCount()); + TestUtils.testCursorContainsRange(cursor, + cursor.getColumnIndex(MediaContract.AudioGenresColumns.GENREID), + 1, 39); + } + + @Test + public void queryAlbumsForGenreTest() { + int genreId = 13; + Uri uri = MediaContract.AlbumGenres.buildAlbumsForGenreListUri(hostInfo.getId(), genreId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.Album.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 31, cursor.getCount()); + TestUtils.testCursorContainsNumbers(cursor, cursor.getColumnIndex(MediaContract.Albums.ALBUMID), + 28, 43, 47, 66, 100); + TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.Albums.ALBUMID), + 50, 55); + TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.Albums.ALBUMID), + 201, 220); + } +} \ No newline at end of file diff --git a/app/src/test/java/org/xbmc/kore/provider/mediaprovider/MediaProviderMusicTest.java b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/MediaProviderMusicTest.java deleted file mode 100644 index 838f151..0000000 --- a/app/src/test/java/org/xbmc/kore/provider/mediaprovider/MediaProviderMusicTest.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright 2016 Martijn Brekhof. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.xbmc.kore.provider.mediaprovider; - -import android.database.Cursor; -import android.net.Uri; - -import org.junit.Test; -import org.xbmc.kore.provider.MediaContract; -import org.xbmc.kore.testutils.CursorUtils; -import org.xbmc.kore.testutils.TestUtils; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; - -public class MediaProviderMusicTest extends AbstractTestClass { - - @Test - public void queryAllArtistsTest() { - Uri uri = MediaContract.Artists.buildArtistsListUri(hostInfo.getId()); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.Artist.PROJECTION, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 227, cursor.getCount()); - TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.ArtistsColumns.ARTISTID), - 1, 94); - //Artist id 95 should be missing - TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.ArtistsColumns.ARTISTID), - 96, 228); - } - - @Test - public void queryArtistTest() { - Uri uri = MediaContract.Artists.buildArtistUri(hostInfo.getId(), TestValues.Artist.artistId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.Artist.PROJECTION, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.Artist.test(cursor); - } - - @Test - public void queryAllAlbumsTest() { - Uri uri = MediaContract.Albums.buildAlbumsListUri(hostInfo.getId()); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.Album.PROJECTION, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 232, cursor.getCount()); - int columnIndex = cursor.getColumnIndex(MediaContract.AlbumsColumns.ALBUMID); - TestUtils.testCursorContainsRange(cursor, columnIndex, 1, 75); - TestUtils.testCursorContainsRange(cursor, columnIndex, 77, 82); - TestUtils.testCursorContainsRange(cursor, columnIndex, 84, 234); - } - - @Test - public void queryAlbumTest() { - Uri uri = MediaContract.Albums.buildAlbumUri(hostInfo.getId(), TestValues.Album.albumId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.Album.PROJECTION, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.Album.test(cursor); - } - - @Test - public void queryAlbumsForArtistTest() { - Uri uri = MediaContract.AlbumArtists.buildAlbumsForArtistListUri(hostInfo.getId(), - TestValues.Artist.artistId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.Album.PROJECTION, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.Album.test(cursor); - } - - @Test - public void queryAlbumsForGenreTest() { - int genreId = 13; - Uri uri = MediaContract.AlbumGenres.buildAlbumsForGenreListUri(hostInfo.getId(), genreId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.Album.PROJECTION, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 31, cursor.getCount()); - TestUtils.testCursorContainsNumbers(cursor, cursor.getColumnIndex(MediaContract.Albums.ALBUMID), - 28, 43, 47, 66, 100); - TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.Albums.ALBUMID), - 50, 55); - TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.Albums.ALBUMID), - 201, 220); - } - - @Test - public void queryAlbumSongsTest() { - Uri uri = MediaContract.Songs.buildAlbumSongsListUri(hostInfo.getId(), TestValues.Album.albumId); - - Cursor cursor = shadowContentResolver.query(uri, new String[] {MediaContract.Songs.SONGID}, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 17, cursor.getCount()); - TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.SongsColumns.SONGID), - 96, 112); - } - - @Test - public void queryAlbumWithoutArtist() { - Uri uri = MediaContract.Albums.buildAlbumUri(hostInfo.getId(), - TestValues.AlbumWithoutArtist.albumId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.AlbumWithoutArtist.PROJECTION, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.AlbumWithoutArtist.test(cursor); - } - - @Test - public void queryAlbumWithMultipleArtists() { - Uri uri = MediaContract.Albums.buildAlbumUri(hostInfo.getId(), - TestValues.AlbumWithMultipleArtists.albumId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.AlbumWithMultipleArtists.PROJECTION, - null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.AlbumWithMultipleArtists.test(cursor); - } - - @Test - public void queryArtistSongsTest() { - Uri uri = MediaContract.Songs.buildArtistSongsListUri(hostInfo.getId(), TestValues.ArtistSong.artistId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.ArtistSong.PROJECTION, null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 17, cursor.getCount()); - TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.SongsColumns.SONGID), - 96, 112); - assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), - TestValues.ArtistSong.songId)); - } - - @Test - public void querySongWithArtistWithoutAlbumTest() { - Uri uri = MediaContract.Songs.buildArtistSongsListUri(hostInfo.getId(), - TestValues.SongWithArtistWithoutAlbum.artistId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.SongWithArtistWithoutAlbum.PROJECTION, - null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.SongWithArtistWithoutAlbum.test(cursor); - } - - @Test - public void queryFirstArtistSongWithMultipleArtistsTest() { - Uri uri = MediaContract.Songs.buildArtistSongsListUri(hostInfo.getId(), - TestValues.SongWithMultipleArtists.firstArtistId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.SongWithMultipleArtists.PROJECTION, - null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.SongWithMultipleArtists.test(cursor); - } - - @Test - public void querySecondArtistSongWithMultipleArtistsTest() { - Uri uri = MediaContract.Songs.buildArtistSongsListUri(hostInfo.getId(), - TestValues.SongWithMultipleArtists.secondArtistId); - - Cursor cursor = shadowContentResolver.query(uri, TestValues.SongWithMultipleArtists.PROJECTION, - null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.SongWithMultipleArtists.test(cursor); - } - - @Test - public void queryThirdArtistSongWithMultipleArtistsTest() { - Uri uri = MediaContract.Songs.buildArtistSongsListUri(hostInfo.getId(), - TestValues.SongWithMultipleArtists.thirdArtistId); - - Cursor cursor = shadowContentResolver.query(uri, - TestValues.SongWithMultipleArtists.PROJECTION, - null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.SongWithMultipleArtists.test(cursor); - } - - @Test - public void queryAllSongsTest() { - Uri uri = MediaContract.Songs.buildSongsListUri(hostInfo.getId()); - - Cursor cursor = shadowContentResolver.query(uri, - TestValues.ArtistSong.PROJECTION, - null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1804, cursor.getCount()); - TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), - 1, 1804); - - //Test if list also contains a song WITH an album AND an artist - assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), - TestValues.SongWithAlbumAndArtist.songId)); - TestValues.SongWithAlbumAndArtist.test(cursor); - - //Test if list also contains a song WITHOUT an album but WITH an artist - assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), - TestValues.SongWithArtistWithoutAlbum.songId)); - TestValues.SongWithArtistWithoutAlbum.test(cursor); - - //Test if list also contains a song WITH an album but WITHOUT an artist - assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), - TestValues.SongWithAlbumWithoutArtist.songId)); - TestValues.SongWithAlbumWithoutArtist.test(cursor); - - //Test if list contains a song WITH MULTIPLE artists - assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), - TestValues.SongWithMultipleArtists.songId)); - TestValues.SongWithMultipleArtists.test(cursor); - } - - @Test - public void queryAlbumWithMultipleArtistsTest() { - Uri uri = MediaContract.Albums.buildAlbumUri(hostInfo.getId(), - TestValues.AlbumWithMultipleArtists.albumId); - - Cursor cursor = shadowContentResolver.query(uri, - TestValues.AlbumWithMultipleArtists.PROJECTION, - null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 1, cursor.getCount()); - assertTrue(cursor.moveToFirst()); - TestValues.AlbumWithMultipleArtists.test(cursor); - } - - @Test - public void queryAllGenresTest() { - Uri uri = MediaContract.AudioGenres.buildAudioGenresListUri(hostInfo.getId()); - - Cursor cursor = shadowContentResolver.query(uri, - new String[] {MediaContract.AudioGenresColumns.GENREID}, - null, null, null); - - assertNotNull(cursor); - assertEquals("cursor size ", 39, cursor.getCount()); - TestUtils.testCursorContainsRange(cursor, - cursor.getColumnIndex(MediaContract.AudioGenresColumns.GENREID), - 1, 39); - } -} \ No newline at end of file diff --git a/app/src/test/java/org/xbmc/kore/provider/mediaprovider/SongsTest.java b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/SongsTest.java new file mode 100644 index 0000000..894cdfe --- /dev/null +++ b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/SongsTest.java @@ -0,0 +1,182 @@ +/* + * Copyright 2016 Martijn Brekhof. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.xbmc.kore.provider.mediaprovider; + +import android.database.Cursor; +import android.net.Uri; + +import org.junit.Test; +import org.xbmc.kore.provider.MediaContract; +import org.xbmc.kore.provider.MediaProvider; +import org.xbmc.kore.testutils.CursorUtils; +import org.xbmc.kore.testutils.TestUtils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class SongsTest extends AbstractTestClass { + @Test + public void queryAlbumSongsTest() { + Uri uri = MediaContract.Songs.buildAlbumSongsListUri(hostInfo.getId(), TestValues.Album.albumId); + + Cursor cursor = shadowContentResolver.query(uri, new String[] {MediaProvider.Qualified.SONGS_SONGID}, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 17, cursor.getCount()); + TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.SongsColumns.SONGID), + 96, 112); + } + + @Test + public void queryArtistSongsTest() { + Uri uri = MediaContract.Songs.buildArtistSongsListUri(hostInfo.getId(), TestValues.ArtistSong.artistId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.ArtistSong.PROJECTION, null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 17, cursor.getCount()); + TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.SongsColumns.SONGID), + 96, 112); + assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), + TestValues.ArtistSong.songId)); + + assertTrue(cursor.moveToFirst()); + do { + String displayArtist = + cursor.getString(cursor.getColumnIndex(MediaProvider.Qualified.SONGS_DISPLAYARTIST)); + assertEquals( "Found " + displayArtist + ", but should be " + TestValues.ArtistSong.displayArtist, + displayArtist, TestValues.ArtistSong.displayArtist); + } while (cursor.moveToNext()); + } + + @Test + public void queryArtistsSongWithArtistWithoutAlbumTest() { + Uri uri = MediaContract.Songs.buildArtistSongsListUri(hostInfo.getId(), + TestValues.SongWithArtistWithoutAlbum.artistId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.SongWithArtistWithoutAlbum.PROJECTION, + null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + TestValues.SongWithArtistWithoutAlbum.test(cursor); + } + + @Test + public void queryFirstArtistSongWithMultipleArtistsTest() { + testMultipleArtistInArtistSongsList(TestValues.SongWithMultipleArtists.firstArtistId, + TestValues.SongWithMultipleArtists.songId); + } + + @Test + public void querySecondArtistSongWithMultipleArtistsTest() { + testMultipleArtistInArtistSongsList(TestValues.SongWithMultipleArtists.secondArtistId, + TestValues.SongWithMultipleArtists.songId); + } + + @Test + public void queryThirdArtistSongWithMultipleArtistsTest() { + testMultipleArtistInArtistSongsList(TestValues.SongWithMultipleArtists.thirdArtistId, + TestValues.SongWithMultipleArtists.songId); + } + + @Test + public void queryAllSongsTest() { + Uri uri = MediaContract.Songs.buildSongsListUri(hostInfo.getId()); + + Cursor cursor = shadowContentResolver.query(uri, + TestValues.ArtistSong.PROJECTION, + null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 1810, cursor.getCount()); + TestUtils.testCursorContainsRange(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), + 1, 1810); + } + + @Test + public void queryAllSongsSongWithAlbumAndArtistTest() { + Uri uri = MediaContract.Songs.buildSongsListUri(hostInfo.getId()); + + Cursor cursor = shadowContentResolver.query(uri, + TestValues.ArtistSong.PROJECTION, + null, null, null); + + assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), + TestValues.SongWithAlbumAndArtist.songId)); + TestValues.SongWithAlbumAndArtist.test(cursor); + } + + @Test + public void queryAllSongsSongWithArtistWithoutAlbumTest() { + Uri uri = MediaContract.Songs.buildSongsListUri(hostInfo.getId()); + + Cursor cursor = shadowContentResolver.query(uri, + TestValues.ArtistSong.PROJECTION, + null, null, null); + + assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), + TestValues.SongWithArtistWithoutAlbum.songId)); + assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), + TestValues.SongWithArtistWithoutAlbum.songId)); + TestValues.SongWithArtistWithoutAlbum.test(cursor); + } + + @Test + public void queryAllSongsSongWithAlbumWithoutArtistTest() { + Uri uri = MediaContract.Songs.buildSongsListUri(hostInfo.getId()); + + Cursor cursor = shadowContentResolver.query(uri, + TestValues.ArtistSong.PROJECTION, + null, null, null); + + assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), + TestValues.SongWithAlbumWithoutArtist.songId)); + TestValues.SongWithAlbumWithoutArtist.test(cursor); + } + + @Test + public void queryAllSongsSongWithMultipleArtistsTest() { + Uri uri = MediaContract.Songs.buildSongsListUri(hostInfo.getId()); + + Cursor cursor = shadowContentResolver.query(uri, + TestValues.ArtistSong.PROJECTION, + null, null, null); + + assertTrue(CursorUtils.moveCursorToFirstOccurrence(cursor, cursor.getColumnIndex(MediaContract.Songs.SONGID), + TestValues.SongWithMultipleArtists.songId)); + TestValues.SongWithMultipleArtists.test(cursor); + } + + + private void testMultipleArtistInArtistSongsList(int artistId, int songId) { + Uri uri = MediaContract.Songs.buildArtistSongsListUri(hostInfo.getId(), + artistId); + + Cursor cursor = shadowContentResolver.query(uri, TestValues.SongWithMultipleArtists.PROJECTION, + null, null, null); + + assertNotNull(cursor); + assertEquals("cursor size ", 2, cursor.getCount()); + CursorUtils.moveCursorToFirstOccurrence(cursor, + cursor.getColumnIndex(MediaContract.Songs.SONGID), + songId); + TestValues.SongWithMultipleArtists.test(cursor); + } +} \ No newline at end of file diff --git a/app/src/test/java/org/xbmc/kore/provider/mediaprovider/TestValues.java b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/TestValues.java index f240567..d69041d 100644 --- a/app/src/test/java/org/xbmc/kore/provider/mediaprovider/TestValues.java +++ b/app/src/test/java/org/xbmc/kore/provider/mediaprovider/TestValues.java @@ -104,16 +104,53 @@ public class TestValues { } } + public static class AlbumWithVariousArtists { + public static int artistId = 229; + public static int albumId = 235; + public static String title = "Various Artists Album"; + public static String displayArtist = "Various artists"; + + public static String[] PROJECTION = new String[] {MediaContract.Albums.DISPLAYARTIST, + MediaContract.Albums.ALBUMID, + MediaContract.Albums.TITLE, + MediaContract.AlbumArtists.ARTISTID}; + + public static void test(Cursor cursor) { + assertEquals(albumId, cursor.getInt(cursor.getColumnIndex(MediaContract.Albums.ALBUMID))); + assertEquals(title, cursor.getString(cursor.getColumnIndex(MediaContract.Albums.TITLE))); + assertEquals(displayArtist, cursor.getString(cursor.getColumnIndex(MediaContract.Albums.DISPLAYARTIST))); + assertEquals(artistId, cursor.getInt(cursor.getColumnIndex(MediaContract.AlbumArtists.ARTISTID))); + } + } + + public static class AlbumWithVariousArtistsNoSongArtists { + public static int artistId = 229; + public static int albumId = 236; + public static String title = "Various Artists Album No Song Artist"; + public static String displayArtist = "Various artists"; + + public static String[] PROJECTION = AlbumWithVariousArtists.PROJECTION; + + public static void test(Cursor cursor) { + assertEquals(albumId, cursor.getInt(cursor.getColumnIndex(MediaContract.Albums.ALBUMID))); + assertEquals(title, cursor.getString(cursor.getColumnIndex(MediaContract.Albums.TITLE))); + assertEquals(displayArtist, cursor.getString(cursor.getColumnIndex(MediaContract.Albums.DISPLAYARTIST))); + assertEquals(artistId, cursor.getInt(cursor.getColumnIndex(MediaContract.AlbumArtists.ARTISTID))); + } + } + public static class ArtistSong { public static int songId = 96; public static int artistId = Artist.artistId; public static int albumId = Album.albumId; public static String title = "Intro & Main Title"; - public static String[] PROJECTION = new String[] { MediaContract.Songs.SONGID, - MediaContract.Songs.TITLE, - MediaContract.Songs.ALBUMID, - MediaContract.SongArtists.ARTISTID, - MediaContract.Artists.ARTIST }; + public static String displayArtist = "Bernstein, Charles"; + public static String[] PROJECTION = new String[] {MediaContract.Songs.SONGID, + MediaContract.Songs.TITLE, + MediaContract.Songs.ALBUMID, + MediaContract.Songs.DISPLAYARTIST, + MediaContract.SongArtists.ARTISTID, + MediaContract.AlbumArtists.ARTISTID }; public static void test(Cursor cursor) { assertEquals(songId, cursor.getInt(cursor.getColumnIndex(MediaContract.Songs.SONGID))); @@ -128,12 +165,14 @@ public class TestValues { public static int artistId = 195; public static int albumId = 201; public static String title = "The Lone Ranger (William Tell Overture)"; + public static String displayartist = "ABC Orch"; public static String[] PROJECTION = ArtistSong.PROJECTION; public static void test(Cursor cursor) { assertEquals(songId, cursor.getInt(cursor.getColumnIndex(MediaContract.Songs.SONGID))); assertEquals(title, cursor.getString(cursor.getColumnIndex(MediaContract.Songs.TITLE))); + assertEquals(displayartist, cursor.getString(cursor.getColumnIndex(MediaContract.Songs.DISPLAYARTIST))); assertEquals(albumId, cursor.getInt(cursor.getColumnIndex(MediaContract.Songs.ALBUMID))); assertEquals(artistId, cursor.getInt(cursor.getColumnIndex(MediaContract.SongArtists.ARTISTID))); } @@ -161,12 +200,14 @@ public class TestValues { public static int artistId = 73; public static int albumId = 76; public static String title = "Unknown"; + public static String displayartist = "The Artist"; public static String[] PROJECTION = ArtistSong.PROJECTION; public static void test(Cursor cursor) { assertEquals(songId, cursor.getInt(cursor.getColumnIndex(MediaContract.Songs.SONGID))); assertEquals(title, cursor.getString(cursor.getColumnIndex(MediaContract.Songs.TITLE))); + assertEquals(displayartist, cursor.getString(cursor.getColumnIndex(MediaContract.Songs.DISPLAYARTIST))); assertEquals(albumId, cursor.getInt(cursor.getColumnIndex(MediaContract.Songs.ALBUMID))); assertEquals(artistId, cursor.getInt(cursor.getColumnIndex(MediaContract.SongArtists.ARTISTID))); } @@ -179,6 +220,7 @@ public class TestValues { public static int thirdArtistId = 228; public static int albumId = 234; public static String title = "threeartists"; + public static String displayartist = "First artist / Second artist / Third artist"; public static String[] PROJECTION = ArtistSong.PROJECTION; @@ -186,6 +228,7 @@ public class TestValues { assertEquals(songId, cursor.getInt(cursor.getColumnIndex(MediaContract.Songs.SONGID))); assertEquals(title, cursor.getString(cursor.getColumnIndex(MediaContract.Songs.TITLE))); assertEquals(albumId, cursor.getInt(cursor.getColumnIndex(MediaContract.Songs.ALBUMID))); + assertEquals(displayartist, cursor.getString(cursor.getColumnIndex(MediaContract.Songs.DISPLAYARTIST))); } } } diff --git a/app/src/testUtils/assets/AudioLibrary.GetAlbums.json b/app/src/testUtils/assets/AudioLibrary.GetAlbums.json index 12b0f1d..f228fca 100644 --- a/app/src/testUtils/assets/AudioLibrary.GetAlbums.json +++ b/app/src/testUtils/assets/AudioLibrary.GetAlbums.json @@ -7573,6 +7573,64 @@ "", "" ] + }, + { + "mood" : [], + "displayartist" : "Various artists", + "artist" : [ + "Various artists" + ], + "fanart" : "", + "genreid" : [], + "albumlabel" : "", + "theme" : [], + "genre" : [], + "thumbnail" : "", + "style" : [], + "description" : "", + "musicbrainzalbumartistid" : [ + "" + ], + "label" : "Various Artists Album", + "title" : "Various Artists Album", + "albumid" : 235, + "musicbrainzalbumid" : "", + "year" : 0, + "artistid" : [ + 229 + ], + "rating" : 0, + "type" : "", + "playcount" : 0 + }, + { + "albumlabel" : "", + "albumid" : 236, + "playcount" : 0, + "genreid" : [], + "displayartist" : "Various artists", + "musicbrainzalbumartistid" : [ + "" + ], + "musicbrainzalbumid" : "", + "label" : "Various Artists Album No Song Artist", + "mood" : [], + "type" : "", + "title" : "Various Artists Album No Song Artist", + "style" : [], + "year" : 0, + "fanart" : "", + "genre" : [], + "artist" : [ + "Various artists" + ], + "artistid" : [ + 229 + ], + "theme" : [], + "description" : "", + "thumbnail" : "", + "rating" : 0 } ] } diff --git a/app/src/testUtils/assets/AudioLibrary.GetArtists.json b/app/src/testUtils/assets/AudioLibrary.GetArtists.json index 85b43f6..3027274 100644 --- a/app/src/testUtils/assets/AudioLibrary.GetArtists.json +++ b/app/src/testUtils/assets/AudioLibrary.GetArtists.json @@ -4542,6 +4542,26 @@ "formed" : "", "style" : [], "fanart" : "" + }, + { + "instrument" : [], + "artist" : "Various artists", + "fanart" : "", + "mood" : [], + "disbanded" : "", + "thumbnail" : "", + "formed" : "", + "genre" : [], + "died" : "", + "description" : "", + "style" : [], + "label" : "Various artists", + "yearsactive" : [], + "artistid" : 229, + "born" : "", + "musicbrainzartistid" : [ + "" + ] } ], "limits" : { diff --git a/app/src/testUtils/assets/AudioLibrary.GetSongs.json b/app/src/testUtils/assets/AudioLibrary.GetSongs.json index c00163b..112ffa0 100644 --- a/app/src/testUtils/assets/AudioLibrary.GetSongs.json +++ b/app/src/testUtils/assets/AudioLibrary.GetSongs.json @@ -75155,12 +75155,240 @@ "duration" : 5, "album" : "ThreeArtistsAlbum", "musicbrainzalbumid" : "" + }, + { + "lyrics" : "", + "album" : "Various Artists Album", + "duration" : 5, + "artistid" : [ + 226 + ], + "year" : 0, + "comment" : "", + "musicbrainzalbumid" : "", + "label" : "firstsong", + "genre" : [], + "albumartistid" : [ + 229 + ], + "fanart" : "", + "lastplayed" : "", + "file" : "/Users/martijn/Projects/dummymediafiles/media/music/Various Artists/Various Artists Album/01-firstartist.mp3", + "playcount" : 0, + "displayartist" : "First artist", + "musicbrainzartistid" : [], + "albumartist" : [ + "Various artists" + ], + "rating" : 0, + "musicbrainztrackid" : "", + "title" : "firstsong", + "musicbrainzalbumartistid" : [], + "artist" : [ + "First artist" + ], + "genreid" : [], + "albumid" : 235, + "track" : 1, + "disc" : 0, + "thumbnail" : "", + "songid" : 1805 + }, + { + "artistid" : [ + 227 + ], + "duration" : 5, + "album" : "Various Artists Album", + "lyrics" : "", + "year" : 0, + "label" : "secondsong", + "genre" : [], + "albumartistid" : [ + 229 + ], + "musicbrainzalbumid" : "", + "comment" : "", + "lastplayed" : "", + "file" : "/Users/martijn/Projects/dummymediafiles/media/music/Various Artists/Various Artists Album/02-secondartist.mp3", + "fanart" : "", + "musicbrainzartistid" : [], + "displayartist" : "Second artist", + "playcount" : 0, + "albumartist" : [ + "Various artists" + ], + "rating" : 0, + "musicbrainzalbumartistid" : [], + "artist" : [ + "Second artist" + ], + "genreid" : [], + "musicbrainztrackid" : "", + "title" : "secondsong", + "songid" : 1806, + "track" : 2, + "albumid" : 235, + "disc" : 0, + "thumbnail" : "" + }, + { + "albumartist" : [ + "Various artists" + ], + "rating" : 0, + "playcount" : 0, + "musicbrainzartistid" : [], + "displayartist" : "Third artist", + "track" : 3, + "albumid" : 235, + "disc" : 0, + "thumbnail" : "", + "songid" : 1807, + "musicbrainztrackid" : "", + "title" : "thirdsong", + "genreid" : [], + "musicbrainzalbumartistid" : [], + "artist" : [ + "Third artist" + ], + "year" : 0, + "lyrics" : "", + "album" : "Various Artists Album", + "artistid" : [ + 228 + ], + "duration" : 5, + "fanart" : "", + "lastplayed" : "", + "file" : "/Users/martijn/Projects/dummymediafiles/media/music/Various Artists/Various Artists Album/03-thirdartist.mp3", + "comment" : "", + "musicbrainzalbumid" : "", + "label" : "thirdsong", + "genre" : [], + "albumartistid" : [ + 229 + ] + }, + { + "duration" : 5, + "rating" : 0, + "musicbrainzartistid" : [], + "thumbnail" : "", + "artistid" : [ + 0 + ], + "artist" : [ + "" + ], + "comment" : "", + "genre" : [], + "albumartistid" : [ + 229 + ], + "album" : "Various Artists Album No Song Artist", + "title" : "first song album artist no song artist", + "fanart" : "", + "lyrics" : "", + "year" : 0, + "songid" : 1808, + "disc" : 0, + "musicbrainzalbumartistid" : [], + "albumartist" : [ + "Various artists" + ], + "musicbrainzalbumid" : "", + "label" : "first song album artist no song artist", + "file" : "/Users/martijn/Projects/dummymediafiles/media/music/unknown/Various Artists Album with Album Artist but no Artist/01-first_album_artist_no_song_artist.mp3", + "musicbrainztrackid" : "", + "lastplayed" : "", + "displayartist" : "", + "genreid" : [], + "playcount" : 0, + "track" : 1, + "albumid" :236 + }, + { + "duration" : 5, + "rating" : 0, + "musicbrainzartistid" : [], + "thumbnail" : "", + "artistid" : [ + 0 + ], + "artist" : [ + "" + ], + "comment" : "", + "genre" : [], + "albumartistid" : [ + 229 + ], + "album" : "Various Artists Album No Song Artist", + "title" : "second song album artist no song artist", + "fanart" : "", + "lyrics" : "", + "year" : 0, + "songid" : 1809, + "disc" : 0, + "musicbrainzalbumartistid" : [], + "albumartist" : [ + "Various artists" + ], + "musicbrainzalbumid" : "", + "label" : "second song album artist no song artist", + "file" : "/Users/martijn/Projects/dummymediafiles/media/music/unknown/Various Artists Album with Album Artist but no Artist/02-second_album_artist_no_song_artist.mp3", + "musicbrainztrackid" : "", + "lastplayed" : "", + "displayartist" : "", + "genreid" : [], + "playcount" : 0, + "track" : 2, + "albumid" : 236 + }, + { + "duration" : 5, + "rating" : 0, + "musicbrainzartistid" : [], + "thumbnail" : "", + "artistid" : [ + 0 + ], + "artist" : [ + "" + ], + "comment" : "", + "genre" : [], + "albumartistid" : [ + 229 + ], + "album" : "Various Artists Album No Song Artist", + "title" : "third song album artist no song artist", + "fanart" : "", + "lyrics" : "", + "year" : 0, + "songid" : 1810, + "disc" : 0, + "musicbrainzalbumartistid" : [], + "albumartist" : [ + "Various artists" + ], + "musicbrainzalbumid" : "", + "label" : "third song album artist no song artist", + "file" : "/Users/martijn/Projects/dummymediafiles/media/music/unknown/Various Artists Album with Album Artist but no Artist/03-third_album_artist_no_song_artist.mp3", + "musicbrainztrackid" : "", + "lastplayed" : "", + "displayartist" : "", + "genreid" : [], + "playcount" : 0, + "track" : 3, + "albumid" : 236 } ], "limits" : { - "end" : 1804, + "end" : 1809, "start" : 0, - "total" : 1804 + "total" : 1810 } }, "jsonrpc" : "2.0" diff --git a/tools/json/JsonTools.pm b/tools/json/JsonTools.pm index f8d4c92..f2452d6 100644 --- a/tools/json/JsonTools.pm +++ b/tools/json/JsonTools.pm @@ -29,6 +29,7 @@ sub sendJsonRequest($$) { my $json = shift; my $jsonrequest = encode_json($json); + my $req = HTTP::Request->new( 'POST', $url ); $req->header( 'Content-Type' => 'application/json-rpc' ); $req->content( $jsonrequest ); diff --git a/tools/json/gentestnumbers.pl b/tools/json/gentestnumbers.pl index 4b24113..05a013c 100755 --- a/tools/json/gentestnumbers.pl +++ b/tools/json/gentestnumbers.pl @@ -43,7 +43,7 @@ sub printRanges($\@) { } if ( $count == 0 ) { - print $current; + print $current if defined $current; } else { print $current - $count . "-" . $current; } @@ -280,4 +280,4 @@ printAlbumCornerCases(); printSongTestNumbers(13, 13); -printSongCornerCases(); \ No newline at end of file +printSongCornerCases(); diff --git a/tools/json/getmusic.pl b/tools/json/getmusic.pl index 35f7a35..0111167 100755 --- a/tools/json/getmusic.pl +++ b/tools/json/getmusic.pl @@ -20,6 +20,7 @@ use warnings; use Types::Serialiser; use JsonTools qw(sendJsonRequest writeJsonFile); +use Data::Dumper; my $url = "http://127.0.0.1:8080/jsonrpc"; @@ -121,7 +122,7 @@ sub getGenres() { } sub getAlbums($) { - my $artist = shift; + my $artistid = shift; my $jsonrequest = { "jsonrpc" => "2.0", "method" => "AudioLibrary.GetAlbums", @@ -152,18 +153,39 @@ sub getAlbums($) { "id" => "libAlbums" }; - if ( defined $artist ) { - $jsonrequest->{"params"}{"filter"} = { - "field" => "artist", - "operator" => "is", - "value" => "$artist" - }; + if ( defined $artistid ) { + $jsonrequest->{"params"}->{"filter"}->{"artistid"} = $artistid; } return sendJsonRequest($url, $jsonrequest); } writeJsonFile("AudioLibrary.GetGenres.json", getGenres()); -writeJsonFile("AudioLibrary.GetArtists.json", getArtists()); -writeJsonFile("AudioLibrary.GetAlbums.json", getAlbums(undef)); + +my $artists = getArtists(); +writeJsonFile("AudioLibrary.GetArtists.json", $artists); + +my $json_albums; +my %albums_seen; #Need to filter out duplicates of various artist albums +my $count = 0; +for my $artist (@{$artists->{"result"}->{"artists"}}) { + my $albums = getAlbums($artist->{"artistid"}); + if ( ! defined $json_albums ) { + $count = 1; + $json_albums = $albums; + } else { + for my $album (@{$albums->{"result"}->{"albums"}}) { + my $albumid = $album->{"albumid"}; + if ( ! exists $albums_seen{$albumid} ) { + $count++; + push $json_albums->{"result"}->{"albums"}, $album; + $albums_seen{$albumid} = ""; + } + } + } +} + +$json_albums->{"result"}{"limits"} = {"end" => $count, "start" => 0, "total" => $count}; + +writeJsonFile("AudioLibrary.GetAlbums.json", $json_albums); writeJsonFile("AudioLibrary.GetSongs.json", getSongs(undef));