Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tempo information to track metadata #368

Merged
merged 8 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"access_token": "BQBOFvTjRqI66SdCAo12CxZIMju5q7CUVspG68WVrnZLPdtcd4wZVq5Ky9rdHrAfCUVlS1zus9tbzu-qP9vPmZ9tAYAKbQd26A7d7UReHyzcHSqLq60", "token_type": "Bearer", "expires_in": 3600, "expires_at": 1703941566}
SathyaBhat marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions spotify_dl/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def fetch_tracks(sp, item_type, item_id):
track_album_info = track_info.get("album")
track_num = track_info.get("track_number")
spotify_id = track_info.get("id")
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
track_name = track_info.get("name")
track_artist = ", ".join(
[artist["name"] for artist in track_info.get("artists")]
Expand Down Expand Up @@ -86,6 +88,7 @@ def fetch_tracks(sp, item_type, item_id):
"genre": genre,
"spotify_id": spotify_id,
"track_url": None,
"tempo": tempo,
}
)
offset += 1
Expand Down Expand Up @@ -141,6 +144,8 @@ def fetch_tracks(sp, item_type, item_id):
)
track_num = item["track_number"]
spotify_id = item.get("id")
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
songs_list.append(
{
"name": track_name,
Expand All @@ -154,6 +159,7 @@ def fetch_tracks(sp, item_type, item_id):
"cover": cover,
"genre": genre,
"spotify_id": spotify_id,
"tempo": tempo,
}
)
offset += 1
Expand Down Expand Up @@ -182,6 +188,8 @@ def fetch_tracks(sp, item_type, item_id):
album_total = album_info.get("total_tracks")
track_num = items["track_number"]
spotify_id = items["id"]
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
if len(items["album"]["images"]) > 0:
cover = items["album"]["images"][0]["url"]
else:
Expand All @@ -203,6 +211,7 @@ def fetch_tracks(sp, item_type, item_id):
"genre": genre,
"track_url": None,
"spotify_id": spotify_id,
"tempo": tempo,
}
)

Expand Down
4 changes: 3 additions & 1 deletion spotify_dl/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def write_tracks(tracks_file, song_dict):
i = 0
writer = csv.writer(file_out, delimiter=";")
for url_dict in song_dict["urls"]:
# for track in url_dict['songs']:
for track in url_dict["songs"]:
track_url = track["track_url"] # here
track_name = track["name"]
track_artist = track["artist"]
track_num = track["num"]
track_album = track["album"]
track_tempo = track["tempo"]
track["save_path"] = url_dict["save_path"]
track_db.append(track)
track_index = i
Expand All @@ -81,6 +81,7 @@ def write_tracks(tracks_file, song_dict):
track_url,
str(track_num),
track_album,
str(track_tempo),
str(track_index),
]
try:
Expand Down Expand Up @@ -119,6 +120,7 @@ def set_tags(temp, filename, kwargs):
)

song_file["genre"] = song.get("genre")
song_file["bpm"] = str(song.get("tempo"))
song_file.save()
song_file = MP3(filename, ID3=ID3)
cover = song.get("cover")
Expand Down
Loading