Last active
February 14, 2025 19:06
-
-
Save cofob/457c64884a2c946f994bbc8d8f7a3711 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tidalapi==0.8.3 | |
import tidalapi, json | |
# 1. Авторизация | |
session = tidalapi.Session() | |
# Выполняем вход | |
session.login_oauth_simple() | |
print(session.check_login()) | |
# 2. Получение лайкнутых треков | |
favorite_tracks = session.user.favorites.tracks() # список объектов треков пользователя | |
# Если треков очень много, возможно понадобится повторный вызов с offset, | |
# в библиотеке tidalapi это обычно скрыто, но можно проверить длину списка и догрузить при необходимости. | |
# 3. Извлечение уникальных ID альбомов | |
album_ids = set() | |
for track in favorite_tracks: | |
album_id = track.album.id # получаем ID альбома, к которому относится трек | |
album_ids.add(album_id) | |
print(f"Found {len(album_ids)} albums") | |
# 4. Сохранение ID альбомов в JSON-файл | |
album_ids_list = list(album_ids) | |
with open('albums.json', 'w', encoding='utf-8') as f: | |
json.dump({"album_ids": album_ids_list}, f, ensure_ascii=False, indent=2) | |
# 5. Лайк всех альбомов | |
for alb_id in album_ids_list: | |
print(f"Liking {alb_id}") | |
try: | |
session.user.favorites.add_album(alb_id) # Добавляем альбом в "избранное" | |
except Exception as e: | |
print(f"Failed to like album {alb_id}: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment