migrate to yt-dlp from pytube / hacktoberfest#2524
migrate to yt-dlp from pytube / hacktoberfest#2524Pobitro-B wants to merge 3 commits intospotDL:devfrom
Conversation
|
Increased the number of results fetched from 5 to 10 for test_youtube.py |
There was a problem hiding this comment.
Pull Request Overview
This PR migrates the YouTube audio provider from the unmaintained pytube library to yt-dlp, addressing reliability issues causing HTTP 400 errors. The change restores YouTube search functionality and improves resilience against API updates.
Key changes:
- Replaced
pytube.SearchandPyTubewithyt_dlp.YoutubeDLfor search and metadata extraction - Removed deprecated
innertubeclient version workaround - Updated logging configuration to use
yt_dlpinstead ofpytube
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| spotdl/utils/logging.py | Updated logger name from "pytube" to "yt_dlp" |
| spotdl/providers/audio/youtube.py | Complete migration from pytube to yt-dlp API, replacing search implementation and metadata extraction |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| search_results: Optional[List[PyTube]] = Search(search_term).results | ||
| with YoutubeDL(self.ydl_opts) as ydl: | ||
| # Search for videos — ytsearch5 limits to top 5 results | ||
| search_query = f"ytsearch10:{search_term}" |
There was a problem hiding this comment.
The search query is hardcoded to return 10 results ('ytsearch10'), but the comment on line 50 mentions 'top 5 results'. This inconsistency could cause confusion. Either update the comment to match the implementation or use 'ytsearch5' if 5 results is the intended behavior.
| search_query = f"ytsearch10:{search_term}" | |
| search_query = f"ytsearch5:{search_term}" |
| try: | ||
| info = ydl.extract_info(search_query, download=False) | ||
| except Exception: | ||
| return [] |
There was a problem hiding this comment.
The bare except Exception clause silently swallows all exceptions, making debugging difficult. Consider catching specific yt-dlp exceptions (e.g., DownloadError, ExtractorError) or at minimum logging the error before returning an empty list to aid troubleshooting.
Title: Migrating to yt-dlp
Shifted YouTube audio provider from pytube to yt-dlp for improved reliability, maintenance, and feature support.
Description: Modified youtube.py and logging.py, changed all uses of pytube to a similar yt-dlp implementation
Related Issue: migrate away from pytube #2417
Fixes #2417 — pytube dependency is no longer maintained and currently causes YouTube downloads/search to fail due to repeated HTTP 400 errors.
Motivation and Context
Pytube is outdated and unreliable, breaking frequently due to YouTube-side changes.
yt-dlp offers a stable and feature-rich alternative, ensuring consistent functionality for SpotDL’s YouTube-based downloads and searches.
This migration:
How Has This Been Tested?
Environment:
Tests performed:
Types of Changes
Checklist