Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the manifest_url of a video, similar to yt-dlp? #414

Open
SuperMechaDeathChrist opened this issue Jan 13, 2025 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@SuperMechaDeathChrist
Copy link

SuperMechaDeathChrist commented Jan 13, 2025

Is your feature request related to a problem? Please describe.
I want to play adaptive streams of youtube videos, that contain both audio and video.

Describe the solution you'd like
Using yt-dlp (a fork based on youtube-dl) i can achieve this by parsing the json with the following code:

import subprocess
import json

u="https://www.youtube.com/watch?v=aqz-KE-bpKQ"

yt_dlp='yt-dlp.exe'

out=subprocess.check_output([yt_dlp, u, '--dump-json'], shell=True, text=True)
out=json.loads(out.strip())
for fi in reversed(out['formats']):
    ext=fi['ext']
    prot=fi['protocol']
    has_drm=fi.get('has_drm')
    manifest_url=fi.get('manifest_url',None)
    res=fi.get('resolution','')
    fps=fi.get('fps',None)
    if manifest_url and prot=='m3u8_native' and ext=='mp4':
        surl=manifest_url

And the stream url surl looks like this:

https://manifest.googlevideo.com/api/manifest/hls_variant/expire/1736819473/ei/sW6FZ4OCN4az2_gPvde6sAI/ip/148.214.94.244/id/6aacfe284f9ba4a4/source/youtube/requiressl/yes/xpc/EgVo2aDSNQ%3D%3D/playback_host/rr1---sn-uvu5a2a5t-bqad.googlevideo.com/met/1736797873%2C/mh/aP/mm/31%2C29/mn/sn-uvu5a2a5t-bqad%2Csn-9gv7zn7e/ms/au%2Crdu/mv/m/mvi/1/pl/24/rms/au%2Cau/tx/51380154/txs/51380152%2C51380153%2C51380154%2C51380155/hfr/1/demuxed/1/tts_caps/1/maudio/1/initcwndbps/2160000/bui/AY2Et-Ph2i0I3cM1e8WXQdBnGhRNJp2zc0H68aNsRV7P5KWkXJ98OeHX5KvNhYvWL6RPPdUlv6bdY21H/spc/9kzgDfPDUUMeCIbHTz0Ap9jdtTnRnDXXVmw0icI60nybhBJTuHSARlU/vprv/1/go/1/rqh/5/mt/1736797518/fvip/3/nvgoi/1/short_key/1/ncsapi/1/keepalive/yes/fexp/51326932%2C51335594%2C51353498%2C51371294/dover/13/itag/0/playlist_type/DVR/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Cxpc%2Ctx%2Ctxs%2Chfr%2Cdemuxed%2Ctts_caps%2Cmaudio%2Cbui%2Cspc%2Cvprv%2Cgo%2Crqh%2Citag%2Cplaylist_type/sig/AJfQdSswRgIhANAafFh_eeYaUUFcx7N3r-XhnbjYFjy9zyf6U1KwO8vFAiEA1n090WkYdH47tYK9pBWECZQMv9GZekbztwuKlfW2zhA%3D/lsparams/playback_host%2Cmet%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Crms%2Cinitcwndbps/lsig/AGluJ3MwRQIgXxaG784fhjfMQBKkOYS4G7ft5Z_kX-Sme9MqmDJjThUCIQC7h2CZbZQS6ENiw_G3JzledDprwVZUtKTfsQZMC1hyOw%3D%3D/file/index.m3u8?MimeType=video%2Fmp4&ISAdaptive=1

This stream url can be played with vlc, or in kodi with the inputstream.adaptive plugin. It plays as high resolution video with audio, and it appears to be a .m3u8 file.

Describe alternatives you've considered
The stream url I obtain with this method appears to have several parts of an adaptive stream url that I obtain with pytubefix, so i tried reconstructing it but it didn't work. There where some parts that i couldn't find, like hfr, tts_caps, maudio, go, nvgoi, short_key, ncsapi, dover, playlist_type. Also, some parts appear to have a different, format, like the id.

I believe the manifest_url can be obtained or constructed from the watch_html or one of the raw html responses for a Youtube object.

Additional context
I am making a youtube kodi addon, and implementing pytubefix to get adaptive stream urls that include audio would be a game changer in my opinion, because pytubefix is way faster than my current implementation.

@SuperMechaDeathChrist SuperMechaDeathChrist added the enhancement New feature or request label Jan 13, 2025
@JuanBindez JuanBindez moved this from waiting to enhancement in Improving Pytubefix Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: enhancement
Development

No branches or pull requests

1 participant