alexta69 / metube

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

Support GET requests to /add #372

Open TheSpyder opened 8 months ago

TheSpyder commented 8 months ago

How hard would it be to implement GET support for adding videos, something like /add?url=myvideo&quality=best? This would allow the bookmarklet and extension to work without the HTTPS restriction (using window.open(), which can be any URL).

I only have a passing knowledge of Python but adding doesn't seem too complex, the hard part is probably displaying something useful on success (such as redirecting to the main page). https://github.com/alexta69/metube/blob/4a3a27e71cadaea52db51e85ffdbaf0a49beeaf0/app/main.py#L110-L114

PikuZheng commented 8 months ago

just change post to get like @routes.get(config.URL_PREFIX + 'add')

TheSpyder commented 8 months ago

I thought of that, but then how would request.json() work? I'm not familiar with the framework at all.

PikuZheng commented 8 months ago

well... still you can send a request body with GET image

TheSpyder commented 8 months ago

In theory, sure, but I specifically want to use query string parameters so I can avoid the HTTPS restriction with window.open('http://my-server:8081/add?video=window.location&quality=best') (or something similar, I'd probably need to URL encode the location).

PikuZheng commented 8 months ago

sorry I misunderstood. these may help:

@routes.post(config.URL_PREFIX + 'add')
@routes.get(config.URL_PREFIX + 'add')
async def add(request):
    if request.method=="GET":
        post=request.query
    else:
        post = await request.json()
    url = post.get('url') .............not changed below

then you can use something like /add?url=http%3A%2F%2Fwww.youtube.com........&quality=best this is the minimal modification I think

TheSpyder commented 8 months ago

aha! thank you. I might submit a pull request if it works 🤔

Ilosariph commented 5 months ago

@TheSpyder did you try it? Sounds like an easy solution to download videos.

TheSpyder commented 5 months ago

no, I never got around to it before I stopped using the shortcut. I didn't use my phone much for sending videos to metube anyway.