Skip to content

migrate to yt-dlp from pytube / hacktoberfest#2524

Open
Pobitro-B wants to merge 3 commits intospotDL:devfrom
Pobitro-B:migrate-to-yt_dlp
Open

migrate to yt-dlp from pytube / hacktoberfest#2524
Pobitro-B wants to merge 3 commits intospotDL:devfrom
Pobitro-B:migrate-to-yt_dlp

Conversation

@Pobitro-B
Copy link

@Pobitro-B Pobitro-B commented Oct 6, 2025

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

  • Replaced pytube.Search and PyTube usages with yt_dlp.YoutubeDL for search and metadata extraction.
  • Updated initialization and search logic to match yt-dlp’s workflow (ytsearch5: query).
  • Removed deprecated innertube references.
  • Ensured returned Result objects preserve the same fields and data types as before.
  • Minor log-level adjustments in logging.py to silence yt-dlp internal messages.

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:

  • Restores YouTube search functionality.
  • Reduces dependency maintenance.
  • Improves resilience against API updates.

How Has This Been Tested?

Environment:

  • Windows 11
  • Python 3.13
  • yt-dlp 2025.08.27
  • SpotDL (editable install from main branch)

Tests performed:

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the CONTRIBUTING document
  • I have added tests to cover my changes
  • All new and existing tests passed

@Pobitro-B Pobitro-B changed the title migrate to yt-dlp from pytube migrate to yt-dlp from pytube / hacktoberfest Oct 6, 2025
@Pobitro-B
Copy link
Author

Increased the number of results fetched from 5 to 10 for test_youtube.py
Please review and share if any further changes are needed.

@Silverarmor Silverarmor changed the base branch from master to dev October 8, 2025 10:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Search and PyTube with yt_dlp.YoutubeDL for search and metadata extraction
  • Removed deprecated innertube client version workaround
  • Updated logging configuration to use yt_dlp instead of pytube

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}"
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
search_query = f"ytsearch10:{search_term}"
search_query = f"ytsearch5:{search_term}"

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +55
try:
info = ydl.extract_info(search_query, download=False)
except Exception:
return []
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate away from pytube

3 participants