search

Home  >  Q&A  >  body text

YT-DLP return format (m3u8)

I have a website running on Node.js, with Express on the backend, which in turn calls a .py script to download user requested audio using yt-dlp. When I run the site on localhost, everything runs fine and I get a .mp4 downloadable URL that I can feed directly into the JavaScript audio.

However, when I deploy the website on Heroku, the same .py script gives me a .m3u8 url which is an audio playlist and requires extra steps like hls can be played using JavaScript.

My question is why does this happen.

My Heroku build package contains nodejs and python. Am I missing some yt-dlp format option FFmpegExtractAudio here or below?

My .py script is

ydl_opts = {
'format': 'bestaudio/best',
'quiet': True,
'postprocessors': [{
    'key': 'FFmpegExtractAudio',
    'preferredcodec': 'mp3',
    'preferredquality': '192',
}],}

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
    info = ydl.extract_info("ytsearch:%s" %
                            requestedAudio, download=False)['entries'][0]
    # code follows...
except yt_dlp.utils.DownloadError or yt_dlp.utils.ExtractorError:
    # code follows...

P粉920835423P粉920835423271 days ago521

reply all(1)I'll reply

  • P粉459440991

    P粉4594409912024-03-30 00:14:27

    Edit: For those who have similar issues, I was able to solve the problem by changing the yt-dlp options. Specifically, I added the format and extractor_args flags. Note: The code above runs on localhost, the code below runs on the Heroku deployed webapp as well as localhost. Happy coding!

    ydl_opts = {
    'format': '(bestaudio/best)[protocol~="^https?$"]',
    'quiet': True,
    'noplaylist': True,
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
    'extractor_args': {'youtube':{'player_client': ['android', 'web']}},

    reply
    0
  • Cancelreply