๐ How To List All Videos in a YouTube Channel (For Obsidian)
Prerequisites:
- Python
- yt-dlp
- YouTube Channel ID, Found here: https://www.youtube.com/account_advanced
Code:
import subprocess
import json
import re
playlist_url = "https://www.youtube.com/playlist?list=UUpdrY4TWv2GhlCNjiATkugg"
result = subprocess.run(
ย ย ["yt-dlp", "--flat-playlist", "-J", playlist_url],
ย ย capture_output=True,
ย ย text=True
)
data = json.loads(result.stdout)
def escape_markdown(text):
ย ย # Escape characters that could break markdown or Obsidian links
ย ย return re.sub(r'([\[\]#*`_])', r'\\\1', text)
for entry in data.get("entries", []):
ย ย raw_title = entry.get("title", "Untitled")
ย ย clean_title = escape_markdown(raw_title)
ย ย video_id = entry.get("id", "")
ย ย url = f"https://www.youtube.com/watch?v={video_id}"
ย ย # Format: [[Title]] - [Video](URL)
ย ย print(f"[[{clean_title}]] ([Video]({url}))")
Disclaimer
The above was Vibe Coded, it may not be the most efficient way of doing this.
Caveats
- The links don't play nice with Obsidian's formatting, so some safety things are included