kivy / kivy

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS
https://kivy.org
MIT License
17k stars 3.04k forks source link

pytube to download YouTube video works on notebook but fails on kivy app #8663

Closed zillurbmb51 closed 1 month ago

zillurbmb51 commented 1 month ago

Hi,

I was trying to create an app to download videos from youtube using pytube library. It works in notebook but does not work on the kivy app. My operating system is MacOS Sonoma 14.4.1 and kivy version 2.3.0

Here is my code and error log:


class YouTubeDownloader(App):
    def build(self):
        self.layout = BoxLayout(orientation='vertical', spacing=10, padding=10)

        # Blue Box
        blue_box = BoxLayout(orientation='vertical', spacing=10, padding=10, size_hint=(1, 0.25))
        blue_box.add_widget(Label(text='Download YouTube video here!', size_hint=(1, None), height=50))
        self.layout.add_widget(blue_box)

        # White Box
        white_box = BoxLayout(orientation='vertical', spacing=10, padding=10, size_hint=(1, 0.25))
        self.url_input = TextInput(hint_text='Enter YouTube video URL', multiline=False)
        white_box.add_widget(self.url_input)
        download_button = Button(text='Download', size_hint=(1, None), height=50)
        download_button.bind(on_press=self.download_video)
        white_box.add_widget(download_button)
        self.layout.add_widget(white_box)

        # Red Box
        self.red_box = BoxLayout(orientation='vertical', spacing=10, padding=10, size_hint=(1, 0.25))
        self.progress_label = Label(text='', size_hint=(1, None), height=50)
        self.download_path_label = Label(text='', size_hint=(1, None), height=50)
        self.red_box.add_widget(self.progress_label)
        self.red_box.add_widget(self.download_path_label)
        self.layout.add_widget(self.red_box)

        return self.layout

    def download_video(self, instance):
        url = self.url_input.text
        if url:
            try:
                yt = YouTube(url)
                video = yt.streams.get_highest_resolution()
                self.progress_label.text = "Downloading..."
                video.download(os.path.expanduser('~'), on_progress_callback=self.show_progress)
                self.progress_label.text = "Download completed successfully!"
                self.download_path_label.text = f"Downloaded video path: {video.download(os.path.expanduser('~'))}"
            except Exception as e:
                self.progress_label.text = "An error occurred during download."
                print("An error occurred:", e)
        else:
            self.progress_label.text = "Please enter a valid YouTube URL."

    def show_progress(self, stream, chunk, bytes_remaining):
        total_size = stream.filesize
        bytes_downloaded = total_size - bytes_remaining
        progress = int((bytes_downloaded / total_size) * 100)
        self.progress_label.text = f"Downloading... {progress}%"

if __name__ == '__main__':
    YouTubeDownloader().run()

Error:

[INFO   ] [Logger      ] Record log in /Users/zillurrahman/.kivy/logs/kivy_24-03-30_17.txt
[INFO   ] [Kivy        ] v2.3.0
[INFO   ] [Kivy        ] Installed at "/opt/homebrew/lib/python3.11/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.11.8 (main, Feb  6 2024, 21:21:21) [Clang 15.0.0 (clang-1500.1.0.2.5)]
[INFO   ] [Python      ] Interpreter at "/opt/homebrew/opt/python@3.11/bin/python3.11"
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 195 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_imageio, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'2.1 Metal - 88'>
[INFO   ] [GL          ] OpenGL vendor <b'Apple'>
[INFO   ] [GL          ] OpenGL renderer <b'Apple M2 Pro'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 1
[INFO   ] [GL          ] Shading version <b'1.20'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Base        ] Start application main loop
[INFO   ] [Clipboard   ] Provider: sdl2(['clipboard_nspaste'] ignored)
[DEBUG  ] [matched regex search] (?:v=|\/)([0-9A-Za-z_-]{11}).*
[DEBUG  ] applying descrambler
[DEBUG  ] finding initial function name
[DEBUG  ] [Pattern failed] ytplayer\.config\s*=\s*
[DEBUG  ] Could not parse object.
[DEBUG  ] [finished regex search, matched] (/s/player/[\w\d]+/[\w\d_/.]+/base\.js)
[DEBUG  ] finding initial function name
[DEBUG  ] [finished regex search, matched] (?P<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)
[DEBUG  ] getting transform plan
[DEBUG  ] [matched regex search] pNa=function\(\w\){[a-z=\.\(\"\)]*;(.*);(?:.+)}
[DEBUG  ] getting transform object
[DEBUG  ] Finding throttling function name
[DEBUG  ] [finished regex search, matched] a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)
[DEBUG  ] Finding throttling function name
[DEBUG  ] [finished regex search, matched] a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
[DEBUG  ] signature found, skip decipher
An error occurred: Stream.download() got an unexpected keyword argument 'on_progress_callback'
github-actions[bot] commented 1 month ago

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.

If you're having trouble installing Kivy, make sure to check out the installation docs for Windows, Linux and macOS.

Let us know if this comment was made in error, and we'll be happy to reopen the issue.