pytube / pytube

A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.
https://pytube.io
The Unlicense
10.58k stars 2.34k forks source link

[BUG] HTTP Error 410: Gone #1946

Open AlcapOTP opened 4 days ago

AlcapOTP commented 4 days ago

Hello. I'm using the latest version of pytube. I'm trying to convert youtube videos stored in a bookmark folder, into '.wav' but for every link i get 'HTTP Error 410: Gone' I did some digging and i found out that this error can be caused by removed or inaccessible video. However i manually checked the links and everything is ok.

Here is the script that's using pytube.

import os
import json
import win32com.client
from pytube import YouTube
from pydub import AudioSegment

def get_chrome_bookmarks():
    shell = win32com.client.Dispatch("WScript.Shell")
    path = os.path.join(os.getenv('LOCALAPPDATA'), r'Google\Chrome\User Data\Default\Bookmarks')

    with open(path, 'r', encoding='utf-8') as file:
        data = json.load(file)

    return data

def find_bookmark_folder(bookmarks, folder_name):
    for item in bookmarks['roots']['bookmark_bar']['children']:
        if item['type'] == 'folder' and item['name'] == folder_name:
            return item
    return None

def process_links(links):
    for link in links:
        url = link['url']
        if '&list' in url:
            url = url.split('&list')[0]

        try:
            yt = YouTube(url)
            stream = yt.streams.filter(only_audio=True).first()
            if stream is None:
                print(f"No audio stream available for {url}")
                continue

            output_file = stream.download()
            base, ext = os.path.splitext(output_file)
            audio_file = base + '.wav'

            audio = AudioSegment.from_file(output_file)
            audio.export(audio_file, format='wav')

            os.remove(output_file)

            print(f"Downloaded and converted: {url} to {audio_file}")

        except Exception as e:
            print(f"Failed to process {url}: {e}")

def main():
    bookmarks = get_chrome_bookmarks()
    folder_name = 'tragoudia'  # Replace with your bookmark folder name
    folder = find_bookmark_folder(bookmarks, folder_name)

    if folder is None:
        print(f"Folder {folder_name} not found")
        return

    process_links(folder['children'])

if __name__ == "__main__":
    main()
github-actions[bot] commented 4 days ago

Thank you for contributing to PyTube. Please remember to reference Contributing.md