Ok so I checked out beets and it seems like a great tool, but not what I’m looking for. I’m just trying to automate the process of manually searching Discogs for myself for the songs in my DJ Library.
In any case, could anyone help me with this script. I must reiterate I know nothing about coding, python etc. I just know that I asked ChatGPT and I got something back. It is frustrating me though.
import requests
# Function to query the Discogs API for release years based on artist and song title
def query_discogs_release_years(token, artist, title):
base_url = "https://api.discogs.com/database/search"
# Set up the query parameters
params = {
"artist": artist,
"track": title,
"token": token,
"type": "release",
"per_page": 100,
"page": 1,
}
while True:
# Make the request to the Discogs API
response = requests.get(base_url, params=params)
if response.status_code != 200:
print(f"Error fetching data from Discogs API: {response.status_code}")
return
results = response.json().get("results", [])
if not results:
break
# Print each result's year and title, but only if the year is not None
for result in results:
year = result.get("year")
title = result.get("title")
if year: # Check if year is not None
print(f"Year: {year}, Title: {title}")
# Prepare for the next page of results
params["page"] += 1
# Main function to prompt the user and run the query
def main():
# Prompt for the artist and title
artist = input("Enter the artist name: ")
title = input("Enter the song title: ")
# Query the Discogs API
query_discogs_release_years('DISCOGS_TOKEN', artist, title)
if __name__ == "__main__":
main()
So GPT uses a hashtag line to add notes to the code I guess to show me what each bit does, I think that’s why it might look clunky here. Anyway, this code returns data however the last line says ‘Error fetching data from Discogs API: 404’. I’m not sure why and I imagine that might be an issue getting the script to run.
I am for the testing of the script using 1 song. I manually searched it on Discogs and proved the release year (the very first) to be 1955. The song is ‘Love Is A Many-Splendored Thing’, and the artist is ‘The Four Aces’. Previously, I’d have an issue where I’d get wrong info back or nothing at all. With the above code I get a massive list of release years for the song in question and I have been able to at least table out the data returned and I can tell the year I am looking for (the earliest of all of them) is in the list.
Initially when I started to try and make this script, asking GPT to make the script return the earliest year gave me different results. Sometimes it would say ‘None’ or it would give me a year from the 2000s or 1978. I figured out based on how the data is returned from the API, if either of those values was first in the list (None, 2000+ or 1978) it would give me that specifically as the “earliest” year.
I then got GPT to write a different script that allows me to paste the date dump I got from the other script and sort in ascending year and it does that, however, when I ask GPT to combine both scripts where it gets the info and finds the earliest year, it give me nothing back which is frustrating.
Does anyone have any ideas? Can anyone help?