{"id":26187991,"url":"https://github.com/michaelcade/youtube-watch-later-mess","last_synced_at":"2025-04-15T00:56:01.093Z","repository":{"id":270849129,"uuid":"911642469","full_name":"MichaelCade/youtube-watch-later-mess","owner":"MichaelCade","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-03T15:01:34.000Z","size":14,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T00:55:56.232Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MichaelCade.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-03T13:56:54.000Z","updated_at":"2025-01-12T18:36:37.000Z","dependencies_parsed_at":"2025-01-03T15:20:01.175Z","dependency_job_id":"bcf1fe9f-b6fd-4f35-b5c1-bcafe9810142","html_url":"https://github.com/MichaelCade/youtube-watch-later-mess","commit_stats":null,"previous_names":["michaelcade/youtube-watch-later-mess"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelCade%2Fyoutube-watch-later-mess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelCade%2Fyoutube-watch-later-mess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelCade%2Fyoutube-watch-later-mess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelCade%2Fyoutube-watch-later-mess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MichaelCade","download_url":"https://codeload.github.com/MichaelCade/youtube-watch-later-mess/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986280,"owners_count":21194025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-11T23:54:07.577Z","updated_at":"2025-04-15T00:56:01.075Z","avatar_url":"https://github.com/MichaelCade.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sorting an overwhelming YouTube Watch Later Playlist \n\n## Purpose \nI have an overwhelming number of catch up, watch later videos in my YouTube account that I cannot seem to get to with all the new content being created. I could manually go through these and add to newly created playlists, all from within the website but where is the fun in that. \n\nMy thinking is that if I can take my 300+ videos and organise them, then maybe I can choose the relevant playlist to watch when I want vs forgetting content that has been added during the year. \n\n## Challenges\nMy initial thinking was this should be easy, use the YouTube API to get the list of videos from the Watch Later playlist and go to work on creating new playlists and adding these videos to. But this is not the case with the v3 YouTube Data API... I will let you google search this and prove me wrong. Which added an additional step to my process below, where I have to use the browser to grab this information. \n\n## Steps \nThis is a two step process, we need to gather our list of youtube watch later videos and then we can use our golang app to sort things. \n\n- Extracting and Managing YouTube \"Watch Later\" Playlist Videos\n- Create the App and OAuth on Your Google Cloud Account for API Access\n- Run our Golang application to sort our mess of a playlist \n- I have also included a delete.go which is a way to delete playlists, when I created them over different iterations and I wanted to test or had made mistakes. `go run delete.go` \n\nI have created my own catagories based on my topics and videos but yours will likely be different. \n\n## Extracting and Managing YouTube \"Watch Later\" Playlist Videos\n\nThis guide explains how to extract video metadata from your YouTube \"Watch Later\" playlist using Chrome DevTools. The data is saved in JSON format and can be used to manage and categorize videos more effectively.\n\n[![YouTube Video](https://img.youtube.com/vi/csLvKRO5z3E/0.jpg)](https://youtu.be/csLvKRO5z3E)\n\n---\n\n## **Prerequisites**\n1. A Google Chrome browser.\n2. Basic knowledge of JavaScript and Chrome DevTools.\n3. Access to your \"Watch Later\" playlist on YouTube.\n4. A Google Cloud account with access to create OAuth credentials.\n\n---\n\n## **Steps to Extract Video Metadata**\n\n### 1. **Open Your Watch Later Playlist**\n- Navigate to the [YouTube Watch Later playlist](https://www.youtube.com/playlist?list=WL) in Chrome.\n- Ensure you're logged into the account containing the playlist.\n\n### 2. **Open Chrome DevTools**\n- Open DevTools by pressing `Ctrl+Shift+I` (Windows/Linux) or `Cmd+Option+I` (Mac).\n- Navigate to the **Console** tab.\n\n### 3. **Scroll Through the Playlist**\n- Paste the following script into the console and press Enter:\n\n```javascript\nasync function scrollAndExtractVideosWithDebug() {\n    let prevVideoCount = 0;\n\n    // Scroll until all videos are loaded\n    while (true) {\n        window.scrollTo(0, document.documentElement.scrollHeight);\n        await new Promise(resolve =\u003e setTimeout(resolve, 2000)); // Wait for new content to load\n\n        // Count the number of loaded videos\n        let videos = document.querySelectorAll('ytd-playlist-video-renderer');\n        console.log(`Videos loaded: ${videos.length}`);\n\n        if (videos.length === prevVideoCount) break; // Exit if no new videos loaded\n        prevVideoCount = videos.length;\n    }\n\n    console.log(`Finished scrolling! Total videos detected: ${prevVideoCount}`);\n\n    // Extract video data\n    let videoElements = Array.from(document.querySelectorAll('ytd-playlist-video-renderer'));\n    let data = videoElements.map((video, index) =\u003e {\n        let title = video.querySelector('#video-title')?.textContent.trim() || 'Unknown Title';\n        let link = video.querySelector('#video-title')?.href || '#';\n        let ariaLabel = video.querySelector('h3')?.getAttribute('aria-label') || '';\n        return { index: index + 1, title, link, ariaLabel };\n    });\n\n    console.log(`Extracted ${data.length} videos.`);\n    console.log(JSON.stringify(data, null, 2));\n    return data;\n}\n\nscrollAndExtractVideosWithDebug();\n```\n\n### 4. **Save the Extracted Data**\n- Once the script completes, it will output the extracted video data as a JSON array in the console.\n- Copy the JSON data from the console and save it to a file, e.g., scrape.json.\n\n---\n\n## **Sample JSON Output**\nThe extracted data will look like this:\n\n```json\n[\n  {\n    \"index\": 1,\n    \"title\": \"MySQL Tutorial\",\n    \"link\": \"https://www.youtube.com/watch?v=yPu6qV5byu4\u0026list=WL\u0026index=1\u0026t=8s\",\n    \"ariaLabel\": \"MySQL Tutorial by Derek Banas 1,743,455 views 10 years ago 41 minutes\"\n  },\n  {\n    \"index\": 2,\n    \"title\": \"Kubernetes Crash Course\",\n    \"link\": \"https://www.youtube.com/watch?v=s_o8dwzRlu4\u0026list=WL\u0026index=2\u0026t=0s\",\n    \"ariaLabel\": \"Kubernetes Crash Course by TechWorld with Nana 400,000 views 3 years ago 25 minutes\"\n  }\n]\n```\n\n---\n\n## Create the App and OAuth on Your Google Cloud Account for API Access\n\n### 1. **Create a Project in Google Cloud Console**\n- Go to the [Google Cloud Console](https://console.cloud.google.com/).\n- Click on the project dropdown and select \"New Project\".\n- Enter a project name and click \"Create\".\n\n### 2. **Enable YouTube Data API v3**\n- In the Google Cloud Console, navigate to \"APIs \u0026 Services\" \u003e \"Library\".\n- Search for \"YouTube Data API v3\" and click on it.\n- Click \"Enable\".\n\n### 3. **Create OAuth 2.0 Credentials**\n- In the Google Cloud Console, navigate to \"APIs \u0026 Services\" \u003e \"Credentials\".\n- Click \"Create Credentials\" and select \"OAuth 2.0 Client IDs\".\n- Configure the consent screen if prompted.\n- Select \"Desktop app\" as the application type.\n- Click \"Create\" and download the credentials.json file.\n\n### 4. **Set Up OAuth 2.0 Client**\n- Place the credentials.json file in your project directory.\n\n### 5. **Run the Go Program**\nEnsure you have the following files in your workspace:\n- main.go\n- credentials.json\n- token.json (if you have previously authenticated)\n\nOpen a terminal and navigate to your workspace directory.\nRun the following command to execute the Go program:\n\n  ```sh\n  go run main.go\n  ```\n\n### 6. **Authenticate and Authorize**\n- The first time you run the program, it will prompt you to authenticate and authorize access to your YouTube account.\n- Follow the instructions to complete the authentication process.\n\n### 7. **Check the Output**\n- The program will read the scrape.json file, categorize the videos, and create new playlists on your YouTube account.\n- If successful, you will see messages indicating the creation of playlists and the addition of videos.\n\n### 8. **Handle Quota Errors**\n- If you encounter a `quotaExceeded` error, you may need to wait for your quota to reset or handle the error gracefully by implementing a retry mechanism.\n\nBy following these steps, you can effectively manage and categorize your YouTube \"Watch Later\" playlist videos.\n\n## Extras \n\nWhen you run the code in the directory you will have a new `categorized_videos.json` file which will have all of the videos listed... If you have only added the scrape.json and have not done the OAuth steps then at least you could see a level of sorting. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelcade%2Fyoutube-watch-later-mess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelcade%2Fyoutube-watch-later-mess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelcade%2Fyoutube-watch-later-mess/lists"}