python:deezer-album-tracker
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python:deezer-album-tracker [2024/03/29 19:13] – Wulf Rajek | python:deezer-album-tracker [2024/04/21 20:05] (current) – Wulf Rajek | ||
---|---|---|---|
Line 25: | Line 25: | ||
Example output: | Example output: | ||
< | < | ||
- | $ ./dat.py | + | $ / |
- | Albums released in the past 6 months: | + | Albums released in the past 7 days: |
- | Release Date: 2024-01-12 | + | |
- | Artist: Papa Roach | + | |
- | Album Name: Scars (feat. Chris Daughtry) (Live) | + | |
- | Release Date: 2023-11-03 | + | Release Date: 2024-04-19 |
- | Artist: | + | Artist: |
- | Album Name: Counterfeit Countdown | + | Album Name: Better Days (feat. Dorothy) (1 track) |
+ | Link: https:// | ||
+ | |||
+ | Release Date: 2024-04-19 | ||
+ | Artist: Distilled Harmony | ||
+ | Album Name: Nova (3 tracks) | ||
+ | Link: https:// | ||
+ | |||
+ | Release Date: 2024-04-19 | ||
+ | Artist: Taylor Swift | ||
+ | Album Name: THE TORTURED POETS DEPARTMENT [EXPLICIT] (16 tracks) | ||
+ | Link: https:// | ||
- | Release Date: 2023-10-31 | ||
- | Artist: Papa Roach | ||
- | Album Name: Leave a Light On (Talk Away The Dark) | ||
</ | </ | ||
Line 83: | Line 88: | ||
import time | import time | ||
import argparse | import argparse | ||
- | from fuzzywuzzy import fuzz | + | from fuzzywuzzy import fuzz, process |
- | from fuzzywuzzy import | + | |
import os | import os | ||
# Constants for file paths | # Constants for file paths | ||
- | CONFIG_FILE | + | CONFIG_FILENAME |
+ | SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
+ | CONFIG_FILE = os.path.join(SCRIPT_DIR, | ||
def load_config(): | def load_config(): | ||
Line 96: | Line 103: | ||
" | " | ||
" | " | ||
- | }, | + | }, |
" | " | ||
" | " | ||
Line 112: | Line 119: | ||
with open(CONFIG_FILE, | with open(CONFIG_FILE, | ||
return json.load(config_file) | return json.load(config_file) | ||
+ | |||
def save_config(config): | def save_config(config): | ||
Line 117: | Line 125: | ||
json.dump(config, | json.dump(config, | ||
- | def send_email(subject, | + | |
+ | def send_email(body): | ||
config = load_config() | config = load_config() | ||
email_config = config.get(' | email_config = config.get(' | ||
Line 128: | Line 137: | ||
sender_email = email_config.get(' | sender_email = email_config.get(' | ||
sender_password = email_config.get(' | sender_password = email_config.get(' | ||
+ | email_subject = config.get(' | ||
msg = MIMEMultipart() | msg = MIMEMultipart() | ||
msg[' | msg[' | ||
msg[' | msg[' | ||
- | msg[' | + | msg[' |
body = MIMEText(body) | body = MIMEText(body) | ||
Line 146: | Line 156: | ||
server.login(sender_email, | server.login(sender_email, | ||
server.send_message(msg) | server.send_message(msg) | ||
+ | |||
def get_artist_name(artist_id): | def get_artist_name(artist_id): | ||
Line 154: | Line 165: | ||
return data.get(' | return data.get(' | ||
return '' | return '' | ||
+ | |||
def get_artist_id(artist_name): | def get_artist_id(artist_name): | ||
Line 165: | Line 177: | ||
return None | return None | ||
- | def get_albums(artist_ids, | + | |
- | config = load_config() | + | def get_albums(artist_ids, |
base_url = " | base_url = " | ||
earliest_release = (datetime.now() - timedelta(days=lookupdays)).strftime(' | earliest_release = (datetime.now() - timedelta(days=lookupdays)).strftime(' | ||
Line 172: | Line 184: | ||
request_count = 0 | request_count = 0 | ||
start_time = time.time() | start_time = time.time() | ||
+ | |||
+ | today = datetime.today().strftime(' | ||
for artist_id in artist_ids: | for artist_id in artist_ids: | ||
Line 182: | Line 196: | ||
for album in data[' | for album in data[' | ||
release_date = datetime.strptime(album[' | release_date = datetime.strptime(album[' | ||
- | if release_date | + | if (datetime.strptime(earliest_release, |
+ | | ||
+ | trackresponse = requests.get(album[' | ||
+ | request_count += 1 | ||
+ | if trackresponse.status_code == 200: | ||
+ | tracklist = trackresponse.json() | ||
+ | trackamount = tracklist[' | ||
+ | else: | ||
+ | trackamount = 0 | ||
albums.append({ | albums.append({ | ||
' | ' | ||
' | ' | ||
- | ' | + | ' |
+ | ' | ||
+ | ' | ||
+ | ' | ||
}) | }) | ||
- | | + | |
# Deezer rate limit is 50 requests / 5 seconds. Limiting to 40/5 here: | # Deezer rate limit is 50 requests / 5 seconds. Limiting to 40/5 here: | ||
# Check if 40 requests have been made in less than 5 seconds | # Check if 40 requests have been made in less than 5 seconds | ||
Line 198: | Line 224: | ||
request_count = 0 | request_count = 0 | ||
start_time = time.time() | start_time = time.time() | ||
- | | + | |
return sorted(albums, | return sorted(albums, | ||
+ | |||
def list_artists(): | def list_artists(): | ||
Line 207: | Line 234: | ||
for artist_id, artist_name in sorted_artists.items(): | for artist_id, artist_name in sorted_artists.items(): | ||
print(f" | print(f" | ||
+ | |||
def add_artist(artist_name): | def add_artist(artist_name): | ||
Line 218: | Line 246: | ||
else: | else: | ||
print(" | print(" | ||
+ | |||
def delete_artist(search_term): | def delete_artist(search_term): | ||
Line 227: | Line 256: | ||
for index, (artist_name, | for index, (artist_name, | ||
print(f" | print(f" | ||
- | | + | |
- | if 0 <= choice_index < len(choices): | + | if choice_input.isnumeric(): |
- | artist_name = choices[choice_index][0] | + | choice_index = int(choice_input) - 1 |
- | artist_id = [key for key, value in subscribed_artists.items() if value == artist_name][0] | + | if 0 <= choice_index < len(choices): |
- | del config[artist_id] | + | artist_name = choices[choice_index][0] |
- | save_config(config) | + | artist_id = [key for key, value in subscribed_artists.items() if value == artist_name][0] |
- | print(f" | + | del config[' |
+ | save_config(config) | ||
+ | print(f" | ||
+ | else: | ||
+ | print(" | ||
else: | else: | ||
- | print(" | + | print(" |
def main(): | def main(): | ||
Line 257: | Line 291: | ||
artist_ids = config.get(' | artist_ids = config.get(' | ||
if args.days: | if args.days: | ||
- | lookupdays=int(args.days) | + | lookupdays = int(args.days) |
else: | else: | ||
- | lookupdays=config.get(' | + | lookupdays = config.get(' |
- | albums = get_albums(artist_ids, | + | albums = get_albums(artist_ids, |
- | | + | |
for album in albums: | for album in albums: | ||
- | | + | |
- | | + | |
- | | + | |
- | print() | + | if album[' |
+ | output += " [EXPLICIT]" | ||
+ | if album[' | ||
+ | output += f" ({album[' | ||
+ | if album[' | ||
+ | output += " | ||
+ | output += ")" | ||
+ | | ||
+ | output += f" | ||
+ | output += " | ||
+ | | ||
if args.email: | if args.email: | ||
- | | + | |
- | | + | |
- | email_body = f" | + | |
- | send_email(email_subject, | + | |
if __name__ == " | if __name__ == " | ||
main() | main() | ||
+ | |||
</ | </ | ||
python/deezer-album-tracker.1711739623.txt.gz · Last modified: 2024/03/29 19:13 by Wulf Rajek