Page:
Step 3 Create the Playlist
Pages
Home da
Home ms
Home
Setup and Run da
Setup and Run ms
Setup and Run
Step 1 Scrape the Billboard da
Step 1 Scrape the Billboard ms
Step 1 Scrape the Billboard
Step 2 YouTube Music Authentication da
Step 2 YouTube Music Authentication ms
Step 2 YouTube Music Authentication
Step 3 Create the Playlist da
Step 3 Create the Playlist ms
Step 3 Create the Playlist
Step 4 Search and Add Songs da
Step 4 Search and Add Songs ms
Step 4 Search and Add Songs
Clone
2
Step 3 Create the Playlist
Tirsvad edited this page 2026-10-28 08:14:04 +01:00
Table of Contents
Step 3 - Create the Playlist
🌐 English · Dansk · Bahasa Melayu
What the step does
The program creates a private playlist named {date} Billboard 100, for example 2026-04-18 Billboard 100, with yt.create_playlist(title, description, privacy_status="PRIVATE"). Before it creates anything it loops through yt.get_library_playlists(); if a playlist with the same title exists, it uses that one.
python -m musical_time_machine --create-playlist
A live run with the author's browser.json: the first run creates the playlist, the second run creates nothing:
The screenshot shows the tests of this step with a fake YouTube Music: the first call creates one playlist, the second call for the same date creates none.
What we gained
- Idempotence. An operation you can run twice with the same result is safe to repeat. Checking for an existing playlist first means a crash or a second run never fills the library with duplicates.
- One place for a name. The playlist title and description are built from templates in
constants.pyby one function, so the check and the creation can never disagree about the title. - Reading an API's real answer.
create_playlistreturns the playlist id on success but an error dictionary on failure; the adapter checks which one it got and raises a clear error. - Privacy by default. Creating the playlist as
PRIVATEmeans a test run never publishes anything.

