Maybe by the title it's clear that I don't really know what I'm doing, but.. this really does seem like something that should be possible. I've been beating my head into the wall, but it can't seem to wrap my head around this one. The code should be referencing a local csv file of release ids and checking if these ids have other versions available. To be clear, this is what I'm looking for on the release page:
-a Release like this: https://www.discogs.com/release/6271225 has 3 Other Versions (4 total) & a master page and id.
-a Release like this: https://www.discogs.com/release/8749474 has no Other Versions & no master page or master id.
How would you write a code that checks ONLY the Release Page and returns whether or not Other Versions exist . It should probably ignore the master page and id, right? Anyone have any ideas? Thanks in advance ☺️
I've tried a lot of variations on this:
import requests
import time
api_url = "https://api.discogs.com"
release_id = 6271225
r = requests.get(f"{api_url}/releases/{release_id}")
data = r.json()
master_id = data['master_id']
r = requests.get(f"{api_url}/masters/{master_id}/versions")
versions_data = r.json()
if len(versions_data["versions"]) > 1:
# Print the release ID and number of versions
print(f"Release {release_id} has {len(versions_data['versions'])} versions.")
else:
print(f"Release {release_id} has no versions.")
time.sleep(5)
But haven't these iterations are either 100% missing the Other Versions, or they break when a release doesn't have a Master page. Help, please :)
CodePudding user response:
When no master id is available, is it safe to say that there is no other version?
If so, then just change your code a bit to this:
import requests
import time
api_url = "https://api.discogs.com"
release_id = 6271225
r = requests.get(f"{api_url}/releases/{release_id}")
data = r.json()
num_versions = 0
if "master_id" in data:
master_id = data['master_id']
r = requests.get(f"{api_url}/masters/{master_id}/versions")
versions_data = r.json()
num_versions = len(versions_data["versions"])
if num_versions > 1:
# Print the release ID and number of versions
print(f"Release {release_id} has {len(versions_data['versions'])} versions.")
else:
print(f"Release {release_id} has no versions.")
time.sleep(5)