Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

YouTube Playlist Randomizer

Truly shuffle your YouTube playlist and save the new order permanently — because YouTube's built-in shuffle always plays in the same sequence and doesn't actually randomize your playlist.

⚠️ Important: Daily API Quota Limit

The YouTube Data API has a daily quota of 10,000 units. Each playlist item update costs 50 units, which means a maximum of 200 songs can be updated per day.

Playlist size Days needed
Up to 200 songs 1 day
201–400 songs 2 days
401–600 songs 3 days
and so on...

The script handles this automatically. When the daily quota is exhausted, it saves its progress to a progress.json file and exits gracefully. The next day, simply run the script again — it will detect the saved progress and ask if you want to resume from where it left off. The shuffle order is preserved across runs, so your playlist will end up in a single consistent random order.

The quota resets daily at midnight Pacific Time.


How It Works

The script uses the YouTube Data API to fetch all videos in your playlist, shuffles them randomly, and writes the new order back to YouTube. Your playlist will be permanently reordered.

Prerequisites

  • Python 3.x
  • A Google account that owns the playlist

Installation

1. Install dependencies

pip install google-auth google-auth-oauthlib google-api-python-client

2. Set up Google Cloud credentials

Follow the steps below to create a client_secret.json file, which the script needs to access the YouTube API on your behalf.


Google Cloud Setup

Note: As of March 2026, this is the exact flow. Google occasionally changes their UI, so some labels may differ slightly.

Step 1 — Enable YouTube Data API

  1. Go to console.cloud.google.com
  2. Click APIs & Services
  3. Click + Enable APIs and services at the top
  4. Search for youtube in the search box
  5. Select YouTube Data API v3 from the results

    If no result appears, search again and click YouTube Data API v3

  6. Click the Enable button

Step 2 — Create Credentials

  1. After enabling, click Create credentials (shown in the banner at the top)
  2. Leave YouTube Data API v3 selected in the Select an API dropdown
  3. Select User data and click Next
  4. Fill in the OAuth consent screen:
    • App name: YouTube Playlist Randomizer (or any name you like)
    • User support email: your email address
    • Developer contact information: your email address
    • Leave the logo as-is, click Save and continue
  5. Scopes — skip this step, click Save and continue
  6. Application type: select Desktop app
  7. Client name: youtube-playlist-randomizer (or any name)
  8. Click Create
  9. Click Download next to the generated Client ID and save the file as client_secret.json in the same folder as youtube_playlist_randomizer.py
  10. Click Done

Important: Wait 5–60 minutes after this step before running the script. Google needs time to finish provisioning your project.

Step 3 — Add Yourself as a Test User

Since the app is in testing mode, you must explicitly allow your own account.

  1. In APIs & Services, click OAuth consent screen
  2. Click Audience
  3. Under Test users, click + Add user
  4. Enter your email address and click Save

Troubleshooting: If you see a 403 error saying the app can only be accessed by developer-approved testers, you either haven't added yourself as a test user yet, or Google hasn't finished provisioning. Wait a bit longer and try again.


OAuth Consent Screen — Alternative Flow

If you see a Get started button instead of the steps above, follow this flow:

  1. Go to APIs & ServicesOAuth consent screen
  2. Click Get started
  3. App name: youtube-playlist-randomizer
  4. User support email: your email
  5. Audience: select External

    Internal is only available for Google Workspace accounts

  6. Contact information: your email
  7. Check I agree and click Continue, then Create
  8. Continue from Step 3 above (Add Yourself as a Test User)

Prepare Your Playlist

Before running the script, set your playlist sort order to Manual on YouTube — the API can only reorder items when manual sorting is enabled.

  1. Open your playlist on YouTube
  2. Click the Sort menu (top right of the playlist)
  3. Select Manual sorting

You only need to do this once. The setting is saved permanently.


Usage

  1. Open a terminal and navigate to the script folder:

    cd path/to/youtube-playlist-randomizer
  2. Run the script:

    python youtube_playlist_randomizer.py
  3. When prompted, paste your playlist URL or just the ID:

    URL or ID of playlist: https://www.youtube.com/playlist?list=PLxxxxxxxx
    

    Both formats work:

    • Full URL: https://www.youtube.com/playlist?list=PLxxxxxxxx
    • Just the ID: PLxxxxxxxx
  4. A browser window will open. Sign in with your Google account and grant access.

    You may see a warning that the app is in testing mode — click Continue to proceed.

  5. The script will shuffle and update your playlist. Progress is shown in the terminal:

    1/42 updated
    2/42 updated
    ...
    42/42 updated
    

Troubleshooting

Error Cause Fix
403 access_denied Your account is not added as a test user Add your email in OAuth consent screen → Audience → Test users
Playlist sort type need to be MANUAL Playlist is not set to manual sorting On YouTube, open the playlist → Sort → Manual sorting
Invalid Value on playlist ID Wrong or placeholder playlist ID Make sure you entered a real playlist URL or ID

About

A python script to "really" randomize youtube music playlists.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages