Tuesday, October 03, 2023

Taming YouTube, Part 3: Declaring YouTube Playlist Bankruptcy

I've got my youtubeassist shell script authenticated with the Google API so I can finally get down to the business of optimizing my YouTube workflow.

First things first, I wanted to clean up the 300+ playlists I currently have in my account. To do this, I added a playlists-snapshot command to youtubeassist. This action grabs all the playlists on my account, creates a fresh local directory with today's timestamp, and writes out each playlist as its own .json file. Here this option in action:

$ youtubeassist -a playlists-snapshot -d ./snapshots
[wait for it...and done]
$ ls
$ ls 20231003.0709 | wc -l
$ ls 20231003.0709 | head

In a single command I've captured all 316 of my playlists to a local directory. I can confirm the .json files are valid by using jq.

$ cat 20231003.0709/Weekly_Discoveries_2019_02_03.json | jq -r '.items[] |  "https://youtube.com/watch?v=" + .contentDetails.videoId + "|" + .snippet.title'
https://youtube.com/watch?v=HNAM2EVXH9A|Owl City - Not All Heroes Wear Capes (Acoustic)
https://youtube.com/watch?v=I-QfPUz1es8|Imagine Dragons - Bad Liar
https://youtube.com/watch?v=jrlMaRdM4wI|L√ČON - You And I (Official Video)

To complete the snapshot procedure, I set up the local directory to be part of a git repository. Once the snapshot command finished, I did a git add, git commit and git push to ensure that the snapshot was safely stored in the cloud.

With all 316 playlists captured, I'm ready to remove the majority of them. To accomplish this, I captured a list of playlists in a .txt file. I edited this file, removing any playlist I wanted save. Finally, I deleted the rest using this one-liner:

$ youtubeassist -a playlists > all.txt
$ emacsclient all.txt      # edit all.txt, removing playlists to save
$ cat all.txt | while read line ; do \
  id=$(echo $line | cut -d: -f1); \
  name=$(echo $line | cut -d: -f2) ; \
  echo $name ; \
  youtubeassist -a playlist-delete -i $id ; \
done | tee yt.cleanup
To build
Weekly Discoveries
Weekly Discoveries - 2022-12-25
The request cannot be completed because you have exceeded your

All went well until I realized I'd maxed out on my YouTube quota for the day:

Whoops. Part way through the list, YouTube stopped honoring my requests to delete playlists. My dreams of having a pristine set of YouTube playlists are going to have to wait for another day (or two). My quota should free up tomorrow, and I can delete the rest of playlists then. When the playlists are cleaned up, I can move to the next part of my plan: creating a workflow that let's me efficiently find, watch and archive YouTube content. Stay tuned!

No comments:

Post a Comment