alexta69 / metube

Self-hosted YouTube downloader (web UI for youtube-dl / yt-dlp)
GNU Affero General Public License v3.0
3.97k stars 264 forks source link

how to start download task only on python side . without any web request or any javascript code. #341

Closed xkungxfu closed 6 months ago

xkungxfu commented 7 months ago

because I want to download videos programmatically.I don't nead a node js website.

I write some code to try, but failed.


class YoutubeWrapper:
    def __init__(self):
        config = Config()
        notifier = Notifier()

        self.dqueue = DownloadQueue(config, notifier)
        asyncio.run(self.initialize())

    async def initialize(self):
        await self.dqueue.initialize()

    async def addxxx(self):
        url = "https://www.youtube.com/watch?v=UyduZMDY_xA"
        #url = "https://www.youtube.com/@Soothingsound3107"
        quality = "best"
        format = ""
        folder = ""
        custom_name_prefix = ""
        status = await self.dqueue.add(url, quality, format, folder, custom_name_prefix)

if __name__ == '__main__':
    yw = YoutubeWrapper()
    asyncio.run(yw.addxxx())

so, my question is how to modify my code. to start download task only on python side .

It seems that the code "await self.event.wait()" break the function "__download". I am not sure, and have no idea. Please give some suggestions ,thanks!

PikuZheng commented 7 months ago

why not just use yt-dlp command like

import os
os.system("yt-dlp https://youtu.be/xxxxxxx")
xkungxfu commented 7 months ago

I don't know how to execute the command in async and multiple threads.

PikuZheng commented 7 months ago

maybe subprocess.Popen("yt-dlp https://youtu.be/xxxxxxx") is better? it can be run multiple times without waiting for it to complete, and does not require async

xkungxfu commented 7 months ago

thank you. I will try it as your advice.

alexta69 commented 6 months ago

The point of MeTube is the UI, so use cases that don't involve the UI aren't part of this. Closing