Re: automatically adding artists' subscriptions via python-musicbrainz2 or musicbrainzngs [solved]
Maximilian Bräutigam <[email protected]> Fri, 20 Mar 2015 11:42:57 +0100
| Newsgroups | gmane.comp.audio.musicbrainz.devel |
|---|---|
| Message-ID | <[email protected]> |
Am 19.03.2015 um 15:45 schrieb Maximilian Bräutigam: > Hi Alastair, > > thanks a lot for your answer. I was really afraid that the solution will > be so bloated since it means a lot of traffic and requests on the mb > database. Anyway, I do not see a better solution and just wanted to get > a second opinion on this. > > Thank you very much again! > Best wishes, > Max > > Am 19.03.2015 um 15:35 schrieb Alastair Porter: >> Hi Max, >> >> You're right, the API doesn't support subscribing to entities, so we >> don't expose that in musicbrainzngs. >> >> Subscribing is just a matter of visiting a specific url: >> https://musicbrainz.org/account/subscriptions/artist/add?id=859749 >> while you are logged in. If you're comfortable with python-requests or >> scrapy you could do this yourself. >> >> Unfortunately the biggest problem is that these urls take row ids >> instead of musicbrainz ids. We spoke about it a bit >> (http://chatlogs.musicbrainz.org/musicbrainz-devel/2015/2015-03/2015-03-19.html#T14-20-26-909477) >> and the easiest way is probably to load the artist page, find the >> subscribe link, and click on it automatically. >> Meanwhile, we've filed some issues >> (http://tickets.musicbrainz.org/browse/MBS-8305) to make this easier in >> the future. >> >> Alastair >> >> On Thu, Mar 19, 2015 at 3:00 PM, Maximilian Bräutigam <[email protected] >> <mailto:[email protected]>> wrote: >> >> Dear all, >> >> I generated a huge list (python pickled) of artists' IDs to which I want >> to subscribe. Unfortunately, I cannot find the entry to do this. >> Obviously, with python-musicbrainzngs I can add them to my collection, >> but I want to subscribe to them. >> >> Any comments, tips, and remarks are highly appreciated. >> >> Best wishes, >> Max Just for completeness, here is what I did: $ ./artistid2rownumber.py > rows $ wget --save-cookies cookies.txt --keep-session-cookies \ --post-data 'username=eew4Weap&password=W4fkaVfj' \ https://musicbrainz.org/login $ ./subscribe.sh It took about 1 hour or so for 1800 subscriptions. Best wishes, Max _______________________________________________ MusicBrainz-devel mailing list [email protected] http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel
subscribe.sh
(application/x-shellscript, 340 B)
#!/bin/bash
# get in the row numbers somehow:
list=`sed 's/.*;//' rows`
for i in $list
do
# the cookie with the login info is crucial:
wget --load-cookies cookies.txt "http://musicbrainz.org/account/subscriptions/artist/add?id=${i}"
# musicbrainz accepts 45 requests per 20 s, just to be on the safe side:
sleep 0.5s
done
artistid2rownumber.py
(text/x-python, 645 B)
#!/usr/bin/env python3
import csv
import urllib.request
import re
# get in the musicbrainz artist ids somehow:
d = csv.reader(open("artists.csv", "r"), delimiter=";")
# artist_id in the site's code is the row in the database that is needed:
reg = re.compile("artist_id=(\d*)")
for i in d:
try:
# get the artist's page; i[1] is the musicbrainz artist id
f = urllib.request.urlopen("http://musicbrainz.org/artist/"+i[1])
s = f.read().decode('utf-8')
m = reg.search(s)
# simply print out artist's name and row in the mb db
print(i[0]+";"+m.group(1))
except:
raise("Error on: "+i)