Individual artist for each track on compilation #133
-
How can I access each individual artist for each track on various artists' compilations? I can find the position, title, and duration but not the artist(s) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hey @kenzoJEP It should work just like this for track in release.tracklist:
print(track.artists) There's also print(track.credits) # this is an list of Artist objects Also could you tell us the specific compilation/release you are trying to access? Cheers! |
Beta Was this translation helpful? Give feedback.
-
Hi Anssi
Thanks for your reply.
for track in release.tracklist:
print(track.artists)
Yes, this works as you say it does.
I went wrong as I assigned variables:-
artists = release.artists # [<Artist 194 'Various'>]
track = release.tracklist
for trk in track:
print(trk.position + ' ' + trk.artists + ' ' + trk.title + ' ' +
trk.duration)
An exception was raised as artists are not in track.
This is the compilation I was using to test:-
https://www.discogs.com/fr/release/2635858-Various-We-Got-A-Party-The-Best-Of-Ron-Records-Volume-One
This leaves me with another problem as trk.artists gives the output of
[<Artist 18394 'Professor Longhair'>]
and I want Professor Longhair. I have tried using
trk_artist = re.findall(r"'([^']*)'", str(trk.artists))
but the output is ['Professor Longhair'] - Close but no cigar.
Do you know of a way to get the desired output?
Thanks,
John
…On Wed, 7 Jun 2023 at 16:31, Anssi Ahola ***@***.***> wrote:
Hey @kenzoJEP <https://github.com/kenzoJEP>
Could you show the code you are using when trying to access the artist(s) ?
It *should* work just like this
for track in release.tracklist:
print(track.artists)
There's also credits property you can check
print(track.credits) # this is an list of Artist objects
Also could you tell us the specific compilation/release you are trying to
access?
Could help us track down the issue.
Cheers!
-Anssi
—
Reply to this email directly, view it on GitHub
<#133 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A2ETXKOXWIGZKSR4P3AEL2TXKCNELANCNFSM6AAAAAAY5ZS75Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi
Great help - just what I was looking for!
Thanks,
John
…On Thu, 8 Jun 2023 at 14:30, Anssi Ahola ***@***.***> wrote:
The artists property of an track is actually an ListField of Track
objects, which is basically an array of Track objects
When you print the track.artists it uses the __repr__ method
<https://github.com/joalla/discogs_client/blob/6292146201aebb49cdef9a639cc1ddf1a5d8941d/discogs_client/models.py#L876-L877>
of the Track object to print an string representation of that object.
i.e. Multiple track artists would print out like so
[<Artist 1373771 'Spectral Lore'>, <Artist 3020852 'Mare Cognitum'>]
You can access the artist name like so
for track in release.tracklist:
artist: Artist = track.artists[0] # I added the Artist type here to aid with code completion
print(track.position + ' ' + artist.name + ' ' + track.title + ' ' + track.duration)
Output
A1 Professor Longhair Go To The Mardi Gras 2:46
A2 Irma Thomas Don't Mess With My Man 2:07
.
.
.
*Note: This assumes that track.artists always has at least one artist,
some guard clauses here might be a good idea*
Hope that helps!
—
Reply to this email directly, view it on GitHub
<#133 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A2ETXKLZKNSI6OUTFFU6QQDXKHHZFANCNFSM6AAAAAAY5ZS75Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Hey @kenzoJEP
Could you show the code you are using when trying to access the artist(s) ?
It should work just like this
There's also
credits
property you can checkAlso could you tell us the specific compilation/release you are trying to access?
Could help us track down the issue.
Cheers!
-Anssi