JuanBindez / pytubefix

Python3 library for downloading YouTube Videos.
https://pytubefix.readthedocs.io
MIT License
722 stars 100 forks source link

Playlist length bug #247

Closed shandralor closed 1 month ago

shandralor commented 1 month ago

:exclamation: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE :exclamation:

lack of information will lead to closure of the issue


Describe the bug When downloading a playlist that is longer than 100 items I receive an Error: HTTP Error 400: Bad Request


code that was used that resulted in the bug

import os
from pytubefix import YouTube, Playlist
from pytubefix.cli import on_progress
import time
import random

def download_video(video_url, output_directory):
    retry = 0
    max_retries = 3

    while retry < max_retries:
        try:
            yt = YouTube(video_url, client='WEB_CREATOR', on_progress_callback=on_progress)
            ys = yt.streams.get_audio_only()
            print(f'Downloading video: {yt.title}')
            ys.download(output_path=output_directory, mp3=True)
            return

        except Exception as e:
            print(f'An error occurred: {e}')

            # Wait for a random interval between 1-5 seconds before retrying
            time.sleep(random.uniform(1, 5))

            retry += 1

def main():
    url = input('Enter the URL of the YouTube video or playlist: ')
    playlist_passed = 'playlist' in url

    output_dir = os.path.join(os.getcwd(), 'Downloads') 

    if not os.path.exists(output_dir):  
        os.makedirs(output_dir)
    try:
        if playlist_passed:

            print('Downloading playlist')
            pl = Playlist(url, client='WEB_CREATOR')

            for video_url in pl.video_urls:
               print(video_url)

        else:
            download_video(url, output_dir)
    except Exception as e:
        print(f'An error occurred: {e}')

    print()
    print('Download complete.')

if __name__ == '__main__':
    main()

Expected behavior I would like to be able to use playlists longer than 100 videos


Screenshots If applicable, add screenshots to help explain your problem.


Desktop (please complete the following information):


Additional context Add any other context about the problem here.

jhanley-com commented 1 month ago

What is the Playlist URL?

shandralor commented 1 month ago

https://www.youtube.com/playlist?list=PLAB6jimK6CqdXxbqqSyNHTBUWvEiE8qvV

I tested with removing a song from the playlist and it did download one additional song before throwing the error, again stopping at 100 songs

felipeucelli commented 1 month ago

The fix is available in this PR #249

JuanBindez commented 1 month ago

try: pytubefix==7.1rc1

shandralor commented 1 month ago

You fixed it with the version above! Thx for this!