Skip to content

Instantly share code, notes, and snippets.

@bplunkert
Last active November 13, 2024 11:56
Show Gist options
  • Save bplunkert/190eaf17dc073432b49dd565d55636e3 to your computer and use it in GitHub Desktop.
Save bplunkert/190eaf17dc073432b49dd565d55636e3 to your computer and use it in GitHub Desktop.
Youtube Channel Scraper
#!/usr/bin/env python3
# Downloads every video from a Youtube channel in highest quality
# Example:
# export CHANNEL_URL="https://www.youtube.com/@psicoactivopodcast/videos"
# docker run -v ./downloads:/downloads -e CHANNEL_URL="${CHANNEL_URL}" youtube-downloader
import yt_dlp
import os
# Define the download function
def download_youtube_channel(channel_url, download_path='/downloads'):
# Ensure the download path exists
os.makedirs(download_path, exist_ok=True)
# yt-dlp options for the highest quality video
ydl_opts = {
'format': 'bestvideo+bestaudio/best', # Download best video and audio, or best available
'merge_output_format': 'mp4', # Merge video and audio to mp4
'outtmpl': os.path.join(download_path, '%(title)s.%(ext)s'), # Output file naming
'ignoreerrors': True, # Ignore errors and continue downloading other videos
'playlistend': None, # Download all videos
}
# Start the download process
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
ydl.download([channel_url])
print("Download completed successfully.")
except Exception as e:
print(f"An error occurred: {e}")
# Channel URL to download from
channel_url = os.getenv('CHANNEL_URL', 'https://www.youtube.com/c/YOUR_CHANNEL_NAME/videos')
# Download videos
download_youtube_channel(channel_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment