-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add brand account setup script (#520)
- Loading branch information
Showing
15 changed files
with
309 additions
and
262 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ name: Build Documentation | |
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- ytmusicapi/** | ||
- docs/** | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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