NextFire / apple-music-discord-rpc

🎵 Discord Rich Presence Client for the macOS Apple Music app and iTunes
MIT License
511 stars 33 forks source link

Increase album search accuracy #62

Closed TheMoonThatRises closed 1 year ago

TheMoonThatRises commented 1 year ago

Increases the accuracy of finding the correct song and therefore album art. This is done by including the song name into the search query and changing the entity to song. Also when searching through the returned result, it will also check the artist to further prevent false finds. This pull request also fixes searches where the song/artist/album includes an asterisk, in which iTunes will not return a result. It appears that removing the asterisks from the query string works, but it should probably be tested more. This may fix #46, #56.

NextFire commented 1 year ago

I have some issues with this local track:

Title: Hacking to the Gate Artist: いとうかなこ Album: Hacking to the Gate

iTunes API result:

{
    "resultCount": 6,
    "results": [
        {
            "artistId": 472181752,
            "artistName": "Super Sparkle",
            "artistViewUrl": "https://music.apple.com/us/artist/super-sparkle/472181752?uo=4",
            "artworkUrl100": "https://is2-ssl.mzstatic.com/image/thumb/Music128/v4/80/72/bb/8072bb42-bb54-5b7c-16b5-c4512a6dc041/D000000001200.jpg/100x100bb.jpg",
            "artworkUrl30": "https://is2-ssl.mzstatic.com/image/thumb/Music128/v4/80/72/bb/8072bb42-bb54-5b7c-16b5-c4512a6dc041/D000000001200.jpg/30x30bb.jpg",
            "artworkUrl60": "https://is2-ssl.mzstatic.com/image/thumb/Music128/v4/80/72/bb/8072bb42-bb54-5b7c-16b5-c4512a6dc041/D000000001200.jpg/60x60bb.jpg",
            "collectionCensoredName": "Sparkle Anime \"Puella Magi Madoka Magica 2\" / \"Steins; Gate\"etc Selection (Bells Music)",
            "collectionExplicitness": "notExplicit",
            "collectionId": 468992128,
            "collectionName": "Sparkle Anime \"Puella Magi Madoka Magica 2\" / \"Steins; Gate\"etc Selection (Bells Music)",
            "collectionPrice": 3.99,
            "collectionViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate-originally-performed-by-kanako/468992128?i=468992170&uo=4",
            "country": "USA",
            "currency": "USD",
            "discCount": 1,
            "discNumber": 1,
            "isStreamable": true,
            "kind": "song",
            "previewUrl": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview125/v4/8a/6f/9f/8a6f9f9a-a436-0ac2-ae8c-78f612d5f0f4/mzaf_6963254498296693274.plus.aac.p.m4a",
            "primaryGenreName": "Instrumental",
            "releaseDate": "2011-09-21T12:00:00Z",
            "trackCensoredName": "Hacking to the Gate (Originally Performed By Kanako Ito \"Steins;gate\") [ベル ミュージック]",
            "trackCount": 6,
            "trackExplicitness": "notExplicit",
            "trackId": 468992170,
            "trackName": "Hacking to the Gate (Originally Performed By Kanako Ito \"Steins;gate\")",
            "trackNumber": 3,
            "trackPrice": 0.69,
            "trackTimeMillis": 253269,
            "trackViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate-originally-performed-by-kanako/468992128?i=468992170&uo=4",
            "wrapperType": "track"
        },
        {
            "artistId": 182925379,
            "artistName": "ITO KANAKO",
            "artistViewUrl": "https://music.apple.com/us/artist/ito-kanako/182925379?uo=4",
            "artworkUrl100": "https://is1-ssl.mzstatic.com/image/thumb/Music125/v4/6f/dc/94/6fdc944e-be75-0959-e858-d9b4ff8751c5/kanakoito.jpg/100x100bb.jpg",
            "artworkUrl30": "https://is1-ssl.mzstatic.com/image/thumb/Music125/v4/6f/dc/94/6fdc944e-be75-0959-e858-d9b4ff8751c5/kanakoito.jpg/30x30bb.jpg",
            "artworkUrl60": "https://is1-ssl.mzstatic.com/image/thumb/Music125/v4/6f/dc/94/6fdc944e-be75-0959-e858-d9b4ff8751c5/kanakoito.jpg/60x60bb.jpg",
            "collectionCensoredName": "TVアニメ『シュタインズ・ゲート』OPテーママキシシングル「Hacking to the Gate」 - EP",
            "collectionExplicitness": "notExplicit",
            "collectionId": 586910744,
            "collectionName": "TVアニメ『シュタインズ・ゲート』OPテーママキシシングル「Hacking to the Gate」 - EP",
            "collectionViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate/586910744?i=586911330&uo=4",
            "country": "USA",
            "currency": "USD",
            "discCount": 1,
            "discNumber": 1,
            "isStreamable": true,
            "kind": "song",
            "previewUrl": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview115/v4/ab/ba/0f/abba0fea-cc42-66b9-531d-5498c67e52c1/mzaf_16393654909704704856.plus.aac.p.m4a",
            "primaryGenreName": "Anime",
            "releaseDate": "2011-04-20T12:00:00Z",
            "trackCensoredName": "Hacking to the Gate",
            "trackCount": 4,
            "trackExplicitness": "notExplicit",
            "trackId": 586911330,
            "trackName": "Hacking to the Gate",
            "trackNumber": 1,
            "trackTimeMillis": 256467,
            "trackViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate/586910744?i=586911330&uo=4",
            "wrapperType": "track"
        },
        {
            "artistId": 369652316,
            "artistName": "Vega Orgel",
            "artistViewUrl": "https://music.apple.com/us/artist/vega-orgel/369652316?uo=4",
            "artworkUrl100": "https://is5-ssl.mzstatic.com/image/thumb/Music/0d/1a/0b/mzi.dbsqpyjw.jpg/100x100bb.jpg",
            "artworkUrl30": "https://is5-ssl.mzstatic.com/image/thumb/Music/0d/1a/0b/mzi.dbsqpyjw.jpg/30x30bb.jpg",
            "artworkUrl60": "https://is5-ssl.mzstatic.com/image/thumb/Music/0d/1a/0b/mzi.dbsqpyjw.jpg/60x60bb.jpg",
            "collectionCensoredName": "Music Box Collection 9171",
            "collectionExplicitness": "notExplicit",
            "collectionId": 452629403,
            "collectionName": "Music Box Collection 9171",
            "collectionPrice": 2.97,
            "collectionViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate-originally-performed-by-kanako-ito/452629403?i=452629408&uo=4",
            "country": "USA",
            "currency": "USD",
            "discCount": 1,
            "discNumber": 1,
            "isStreamable": true,
            "kind": "song",
            "previewUrl": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview115/v4/c9/af/df/c9afdff8-7e73-0411-ec85-08bc310a08ca/mzaf_11792644222104097518.plus.aac.p.m4a",
            "primaryGenreName": "Instrumental",
            "releaseDate": "2011-07-20T12:00:00Z",
            "trackCensoredName": "Hacking to the Gate (Originally Performed by Kanako Ito)",
            "trackCount": 3,
            "trackExplicitness": "notExplicit",
            "trackId": 452629408,
            "trackName": "Hacking to the Gate (Originally Performed by Kanako Ito)",
            "trackNumber": 3,
            "trackPrice": 0.99,
            "trackTimeMillis": 252447,
            "trackViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate-originally-performed-by-kanako-ito/452629403?i=452629408&uo=4",
            "wrapperType": "track"
        },
        {
            "artistId": 182925379,
            "artistName": "ITO KANAKO",
            "artistViewUrl": "https://music.apple.com/us/artist/ito-kanako/182925379?uo=4",
            "artworkUrl100": "https://is1-ssl.mzstatic.com/image/thumb/Music125/v4/6f/dc/94/6fdc944e-be75-0959-e858-d9b4ff8751c5/kanakoito.jpg/100x100bb.jpg",
            "artworkUrl30": "https://is1-ssl.mzstatic.com/image/thumb/Music125/v4/6f/dc/94/6fdc944e-be75-0959-e858-d9b4ff8751c5/kanakoito.jpg/30x30bb.jpg",
            "artworkUrl60": "https://is1-ssl.mzstatic.com/image/thumb/Music125/v4/6f/dc/94/6fdc944e-be75-0959-e858-d9b4ff8751c5/kanakoito.jpg/60x60bb.jpg",
            "collectionCensoredName": "TVアニメ『シュタインズ・ゲート』OPテーママキシシングル「Hacking to the Gate」 - EP",
            "collectionExplicitness": "notExplicit",
            "collectionId": 586910744,
            "collectionName": "TVアニメ『シュタインズ・ゲート』OPテーママキシシングル「Hacking to the Gate」 - EP",
            "collectionViewUrl": "https://music.apple.com/us/album/%E3%83%AA%E3%83%A9%E3%82%A4%E3%82%A2%E3%83%B3%E3%82%B9/586910744?i=586911331&uo=4",
            "country": "USA",
            "currency": "USD",
            "discCount": 1,
            "discNumber": 1,
            "isStreamable": true,
            "kind": "song",
            "previewUrl": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview125/v4/93/c1/ce/93c1ce85-40b9-9b60-05a8-7dc31d46f549/mzaf_12439917224228808399.plus.aac.p.m4a",
            "primaryGenreName": "Anime",
            "releaseDate": "2011-04-20T12:00:00Z",
            "trackCensoredName": "リライアンス",
            "trackCount": 4,
            "trackExplicitness": "notExplicit",
            "trackId": 586911331,
            "trackName": "リライアンス",
            "trackNumber": 2,
            "trackTimeMillis": 314320,
            "trackViewUrl": "https://music.apple.com/us/album/%E3%83%AA%E3%83%A9%E3%82%A4%E3%82%A2%E3%83%B3%E3%82%B9/586910744?i=586911331&uo=4",
            "wrapperType": "track"
        },
        {
            "artistId": 182925379,
            "artistName": "ITO KANAKO",
            "artistViewUrl": "https://music.apple.com/us/artist/ito-kanako/182925379?uo=4",
            "artworkUrl100": "https://is3-ssl.mzstatic.com/image/thumb/Music6/v4/46/eb/01/46eb01a0-253d-bf9b-66a2-61aae9b366c6/FVCG1265.jpg/100x100bb.jpg",
            "artworkUrl30": "https://is3-ssl.mzstatic.com/image/thumb/Music6/v4/46/eb/01/46eb01a0-253d-bf9b-66a2-61aae9b366c6/FVCG1265.jpg/30x30bb.jpg",
            "artworkUrl60": "https://is3-ssl.mzstatic.com/image/thumb/Music6/v4/46/eb/01/46eb01a0-253d-bf9b-66a2-61aae9b366c6/FVCG1265.jpg/60x60bb.jpg",
            "collectionArtistId": 92345680,
            "collectionArtistName": "Various Artists",
            "collectionCensoredName": "Steins;Gate Symphonic Reunion",
            "collectionExplicitness": "notExplicit",
            "collectionId": 722724150,
            "collectionName": "Steins;Gate Symphonic Reunion",
            "collectionPrice": 15.99,
            "collectionViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate-sypmhonic-ver/722724150?i=722724356&uo=4",
            "country": "USA",
            "currency": "USD",
            "discCount": 2,
            "discNumber": 2,
            "isStreamable": true,
            "kind": "song",
            "previewUrl": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview125/v4/b2/1e/c6/b21ec63f-323a-9dee-a0e8-0f1ead1a2ea8/mzaf_3811307671322321509.plus.aac.p.m4a",
            "primaryGenreName": "Anime",
            "releaseDate": "2013-09-25T12:00:00Z",
            "trackCensoredName": "Hacking to the Gate (Sypmhonic Ver.)",
            "trackCount": 12,
            "trackExplicitness": "notExplicit",
            "trackId": 722724356,
            "trackName": "Hacking to the Gate (Sypmhonic Ver.)",
            "trackNumber": 1,
            "trackPrice": 1.29,
            "trackTimeMillis": 258360,
            "trackViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate-sypmhonic-ver/722724150?i=722724356&uo=4",
            "wrapperType": "track"
        },
        {
            "artistId": 182925379,
            "artistName": "ITO KANAKO",
            "artistViewUrl": "https://music.apple.com/us/artist/ito-kanako/182925379?uo=4",
            "artworkUrl100": "https://is3-ssl.mzstatic.com/image/thumb/Music6/v4/46/eb/01/46eb01a0-253d-bf9b-66a2-61aae9b366c6/FVCG1265.jpg/100x100bb.jpg",
            "artworkUrl30": "https://is3-ssl.mzstatic.com/image/thumb/Music6/v4/46/eb/01/46eb01a0-253d-bf9b-66a2-61aae9b366c6/FVCG1265.jpg/30x30bb.jpg",
            "artworkUrl60": "https://is3-ssl.mzstatic.com/image/thumb/Music6/v4/46/eb/01/46eb01a0-253d-bf9b-66a2-61aae9b366c6/FVCG1265.jpg/60x60bb.jpg",
            "collectionArtistId": 92345680,
            "collectionArtistName": "Various Artists",
            "collectionCensoredName": "Steins;Gate Symphonic Reunion",
            "collectionExplicitness": "notExplicit",
            "collectionId": 722724150,
            "collectionName": "Steins;Gate Symphonic Reunion",
            "collectionPrice": 15.99,
            "collectionViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate-instrumental-symphonic-ver/722724150?i=722724365&uo=4",
            "country": "USA",
            "currency": "USD",
            "discCount": 2,
            "discNumber": 2,
            "isStreamable": true,
            "kind": "song",
            "previewUrl": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview115/v4/bb/ad/e1/bbade13f-9fc8-68b9-624a-12e4ae6e16ba/mzaf_14164127618144598681.plus.aac.p.m4a",
            "primaryGenreName": "Anime",
            "releaseDate": "2013-09-25T12:00:00Z",
            "trackCensoredName": "Hacking to the Gate (Instrumental) [Symphonic Ver.]",
            "trackCount": 12,
            "trackExplicitness": "notExplicit",
            "trackId": 722724365,
            "trackName": "Hacking to the Gate (Instrumental) [Symphonic Ver.]",
            "trackNumber": 7,
            "trackPrice": 1.29,
            "trackTimeMillis": 257613,
            "trackViewUrl": "https://music.apple.com/us/album/hacking-to-the-gate-instrumental-symphonic-ver/722724150?i=722724365&uo=4",
            "wrapperType": "track"
        }
    ]
}

The second result should be the one that is selected. None of them is chosen with the current filtering.

TheMoonThatRises commented 1 year ago

Hm, apparently iTunes stores the artist's name in english, which messes with the filter. I have removed the filter, which will fix the problem. Let me know if you encounter any more problems with the changes.

NextFire commented 1 year ago

lgtm, thanks!