I’m working on a script to automate tagging and ordering my music library. I love artworks so I had to find a way to take them from the net.
I found 2 ways to get it: the first is based on opensource databases, the others use the proprietary API of iTunes.
1. Musicbrainz (opensource)
musicbrainz.org offers an open database where can can find a lot of infos about songs such as releases, artists, labels and more.
So if we can find our artworks we have to follow these simple steps:
- We looking for a release of our song with a GET request. In our example we want to find info about The Police – Every Breath You Take
https://musicbrainz.org/ws/2/release?query=track:%22every%breath%you%take%22AND%20artist:%22the%20police%22
The data originally are formatted in XML, but I prefer json so I specified the format in the parameter fmt=json.
Here it is the partial response from the server:{ "created": "2018-10-09T10:21:03.833Z", "count": 23, "offset": 0, "releases": [{ "id": "3f463683-6fb2-4598-8335-f6a8d77da8f4", "score": 100, "count": 1, "title": "Every Breath You Take", "status": "Official", "text-representation": { "language": "eng", "script": "Latn" }, "artist-credit": [{ "artist": { "id": "9e0e2b01-41db-4008-bd8b-988977d6019a", "name": "The Police", "sort-name": "Police, The", "disambiguation": "British rock band" } }], "release-group": { "id": "8c102670-f3d4-45e9-be3b-72c96ef69c88", "type-id": "d6038452-8ee0-3f68-affc-2de9a1ede0b9", "title": "Every Breath You Take", "primary-type": "Single" }, "date": "1983-05-20", "country": "GB", "release-events": [{ "date": "1983-05-20", "area": { "id": "8a754a16-0027-3a29-b6d7-2b40ea0481ed", "name": "United Kingdom", "sort-name": "United Kingdom", "iso-3166-1-codes": ["GB"] } }], "label-info": [{ "catalog-number": "AM 117", "label": { "id": "35515729-1f2c-4cc9-9390-9af2764bc56c", "name": "A&M Records" } }], "track-count": 2, "media": [{ "format": "7\" Vinyl", "disc-count": 0, "track-count": 2 }] }, ... ... ] }
In the response there are a lot of releases, we take the first one for example -> 3f463683-6fb2-4598-8335-f6a8d77da8f4
- With the release id we have to request our artwork images from another musicbrainz domain: http://coverartarchive.org.
http://coverartarchive.org/release/3f463683-6fb2-4598-8335-f6a8d77da8f4
Response:{ "images": [{ "types": ["Front"], "front": true, "back": false, "edit": 24308332, "image": "http://coverartarchive.org/release/3f463683-6fb2-4598-8335-f6a8d77da8f4/5520130272.jpg", "comment": "", "approved": true, "id": "5520130272", "thumbnails": { "large": "http://coverartarchive.org/release/3f463683-6fb2-4598-8335-f6a8d77da8f4/5520130272-500.jpg", "small": "http://coverartarchive.org/release/3f463683-6fb2-4598-8335-f6a8d77da8f4/5520130272-250.jpg" } }], "release": "http://musicbrainz.org/release/3f463683-6fb2-4598-8335-f6a8d77da8f4" }
Great!! A lot of images here! 😀
So you just have to choose what size you want!
2. iTunes (closed)
With iTunes the work is even easier. With only one request like this one we have the response below.
https://itunes.apple.com/search?term=the police every breath you take&country=it
Response:
{ "resultCount": 50, "results": [{ "wrapperType": "track", "kind": "song", "artistId": "93818", "collectionId": 14923444, "trackId": 14923456, "artistName": "The Police", "collectionName": "The Very Best of Sting and the Police", "trackName": "Every Breath You Take", "collectionCensoredName": "The Very Best of Sting and the Police", "trackCensoredName": "Every Breath You Take", "collectionArtistId": "94804", "collectionArtistName": "Sting & The Police", "collectionArtistViewUrl": "https://itunes.apple.com/it/artist/sting/94804?uo=4", "artistViewUrl": "https://itunes.apple.com/it/artist/the-police/93818?uo=4", "collectionViewUrl": "https://itunes.apple.com/it/album/every-breath-you-take/14923444?i=14923456&uo=4", "trackViewUrl": "https://itunes.apple.com/it/album/every-breath-you-take/14923444?i=14923456&uo=4", "previewUrl": "https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/Music6/v4/20/fc/fa/20fcfac4-2f1e-5080-8927-ca3f099c11c6/mzaf_6903737133226138543.plus.aac.p.m4a", "artworkUrl30": "https://is2-ssl.mzstatic.com/image/thumb/Music/v4/a5/ad/76/a5ad763f-0e12-5bc9-c564-a6a236933e31/source/30x30bb.jpg", "artworkUrl60": "https://is2-ssl.mzstatic.com/image/thumb/Music/v4/a5/ad/76/a5ad763f-0e12-5bc9-c564-a6a236933e31/source/60x60bb.jpg", "artworkUrl100": "https://is2-ssl.mzstatic.com/image/thumb/Music/v4/a5/ad/76/a5ad763f-0e12-5bc9-c564-a6a236933e31/source/100x100bb.jpg", "collectionPrice": 19.99, "trackPrice": 0.99, "releaseDate": "1983-01-06T08:00:00Z", "collectionExplicitness": "notExplicit", "trackExplicitness": "notExplicit", "discCount": 1, "discNumber": 1, "trackCount": 18, "trackNumber": 4, "trackTimeMillis": 251347, "country": "ITA", "currency": "EUR", "primaryGenreName": "Rock", "isStreamable": true }, ... ] }
iTunes returns a lot of info related to its store, artworks too! 🙂
There are only small images…the biggest is 100×100 pixels…but with a small trick you can get bigger images
Original size:
https://is2-ssl.mzstatic.com/image/thumb/Music/v4/a5/ad/76/a5ad763f-0e12-5bc9-c564-a6a236933e31/source/100×100bb.jpg
Custom size:
https://is2-ssl.mzstatic.com/image/thumb/Music/v4/a5/ad/76/a5ad763f-0e12-5bc9-c564-a6a236933e31/source/500×500bb.jpg
You can choose the size you want!
(size 500×500)
Conclusions
What method to choose? Based on your philosophy 🙂
Musicbrainz is an open database maintained by users, not related to commercial company such as Apple®.
It does not always find the release we want, but it can be an opportunity to help the community and upload it yourself 🙂
https://musicbrainz.org/doc/How_to_Contribute
Apple is an closed database, it has almost everything you’re looking for you music library…but they’re free to close this resource when they want or ask for money for it.
It’s never too late to help build a free database for everyone!
Happy scraping to all!
Leave a Comment