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/30 12:08] – Wulf Rajek | python:deezer-album-tracker [2024/04/21 20:05] (current) – Wulf Rajek | ||
---|---|---|---|
Line 25: | Line 25: | ||
Example output: | Example output: | ||
< | < | ||
- | $ ./dat.py --days 7 | + | $ /dat.py --days 7 |
Albums released in the past 7 days: | Albums released in the past 7 days: | ||
- | Release Date: 2024-03-29 | ||
- | Artist: Beyoncé | ||
- | Album Name: COWBOY CARTER | ||
- | Link: https:// | ||
- | Release Date: 2024-03-29 | + | Release Date: 2024-04-19 |
- | Artist: | + | Artist: |
- | Album Name: Lonely Cowboy | + | Album Name: Better Days (feat. Dorothy) (1 track) |
- | Link: https:// | + | Link: https:// |
- | Release Date: 2024-03-29 | + | Release Date: 2024-04-19 |
- | Artist: | + | Artist: |
- | Album Name: Be Okay | + | Album Name: Nova (3 tracks) |
- | Link: https:// | + | Link: https:// |
+ | |||
+ | Release Date: 2024-04-19 | ||
+ | Artist: Taylor Swift | ||
+ | Album Name: THE TORTURED POETS DEPARTMENT [EXPLICIT] (16 tracks) | ||
+ | Link: https:// | ||
</ | </ | ||
Line 87: | 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 100: | Line 103: | ||
" | " | ||
" | " | ||
- | }, | + | }, |
" | " | ||
" | " | ||
Line 116: | 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): | ||
with open(CONFIG_FILE, | with open(CONFIG_FILE, | ||
json.dump(config, | json.dump(config, | ||
+ | |||
def send_email(body): | def send_email(body): | ||
Line 151: | 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 159: | Line 165: | ||
return data.get(' | return data.get(' | ||
return '' | return '' | ||
+ | |||
def get_artist_id(artist_name): | def get_artist_id(artist_name): | ||
Line 169: | Line 176: | ||
return artist[' | return artist[' | ||
return None | return None | ||
+ | |||
def get_albums(artist_ids, | def get_albums(artist_ids, | ||
Line 178: | Line 186: | ||
today = datetime.today().strftime(' | today = datetime.today().strftime(' | ||
- | | + | |
for artist_id in artist_ids: | for artist_id in artist_ids: | ||
url = base_url.format(artist_id) | url = base_url.format(artist_id) | ||
Line 188: | Line 196: | ||
for album in data[' | for album in data[' | ||
release_date = datetime.strptime(album[' | release_date = datetime.strptime(album[' | ||
- | if datetime.strptime(earliest_release, | + | 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 208: | 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 217: | 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 228: | Line 246: | ||
else: | else: | ||
print(" | print(" | ||
+ | |||
def delete_artist(search_term): | def delete_artist(search_term): | ||
Line 237: | 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 272: | Line 296: | ||
albums = get_albums(artist_ids, | albums = get_albums(artist_ids, | ||
- | | + | |
for album in albums: | for album in albums: | ||
- | | + | |
- | | + | |
- | | + | |
- | print("Album Name:", | + | if album[' |
- | | + | output += " [EXPLICIT]" |
- | | + | |
- | | + | |
- | print() | + | if album[' |
+ | output += " | ||
+ | output += ")" | ||
+ | | ||
+ | output += f" | ||
+ | | ||
+ | | ||
if args.email: | if args.email: | ||
- | | + | |
- | | + | |
if __name__ == " | if __name__ == " | ||
main() | main() | ||
+ | |||
</ | </ | ||
python/deezer-album-tracker.1711800538.txt.gz · Last modified: 2024/03/30 12:08 by Wulf Rajek