add brand account setup script (#520)
This commit is contained in:
parent
b2113db0e1
commit
170eea358d
15 changed files with 309 additions and 262 deletions
56
tests/setup/setup_account.py
Normal file
56
tests/setup/setup_account.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import itertools
|
||||
from contextlib import suppress
|
||||
from pathlib import Path
|
||||
|
||||
from conftest import get_config
|
||||
|
||||
from ytmusicapi import YTMusic
|
||||
|
||||
config = get_config()
|
||||
|
||||
# To get started, go to https://www.youtube.com/account and create a new channel (=brand account)
|
||||
brand_account = "114511851949139689139"
|
||||
|
||||
# run ytmusicapi browser in tests/setup, paste headers from your test account
|
||||
yt_brand = YTMusic(Path(__file__).parent.joinpath("oauth.json").as_posix(), brand_account)
|
||||
|
||||
|
||||
def populate_account():
|
||||
"""idempotent requests to populate an account"""
|
||||
# library
|
||||
playlist_id = "RDCLAK5uy_l9ex2d91-Qb1i-W7d0MLCEl_ZjRXss0Dk" # fixed playlist with many artists
|
||||
yt_playlist = yt_brand.get_playlist(playlist_id)
|
||||
artists = [track["artists"] for track in yt_playlist["tracks"]]
|
||||
unique_artists = list(set(artist["id"] for artist in itertools.chain.from_iterable(artists)))
|
||||
with suppress(Exception):
|
||||
for artist in unique_artists:
|
||||
print(f"Adding artist {artist}")
|
||||
yt_brand.subscribe_artists([artist]) # add one by one to avoid "requested entity not found"
|
||||
|
||||
# add some albums, which also populates songs and artists as a side effect
|
||||
unique_albums = set(track["album"]["id"] for track in yt_playlist["tracks"])
|
||||
playlist_ids = [yt_brand.get_album(album)["audioPlaylistId"] for album in unique_albums if album]
|
||||
for playlist_id in playlist_ids:
|
||||
print(f"Adding album {playlist_id}")
|
||||
yt_brand.rate_playlist(playlist_id, "LIKE")
|
||||
|
||||
# like some songs
|
||||
for track in yt_playlist["tracks"]:
|
||||
print(f"liking track {track['videoId']}")
|
||||
yt_brand.rate_song(track["videoId"], "LIKE")
|
||||
|
||||
# create own playlist
|
||||
playlistId = yt_brand.create_playlist(
|
||||
title="ytmusicapi test playlist don't delete",
|
||||
description="description",
|
||||
source_playlist="PLJZsotfVeN2D3pHlgWT_FFSYsJe_thVmh",
|
||||
)
|
||||
print(f"Created playlist {playlistId}, don't forget to set this in test.cfg playlists/own")
|
||||
|
||||
# podcasts
|
||||
yt_brand.rate_playlist(config["podcasts"]["podcast_id"], rating="LIKE")
|
||||
yt_brand.add_playlist_items("SE", [config["podcasts"]["episode_id"]])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
populate_account()
|
||||
Loading…
Reference in a new issue