javascripthls.jsyt-dlp

YT-DLP Return Format (m3u8)


I have a website that runs on node.js and express on the back end that in turn calls .py script to download a user-requested audio using yt-dlp. When I run the website on the localhost, everything runs perfectly, and I get a .mp4 downloadable url that can be fed right into the JavaScript audio.

However, when I deploy my website on Heroku, the same .py script gives me a .m3u8 url which is an audio playlist, and it requires extra steps such as hls to be played with JavaScript.

My question is why this happens.

My Heroku buildpack contains nodejs and python. Am I missing FFmpegExtractAudio here or some yt-dlp formatting options 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...

Solution

  • EDIT: For those that have similar issue, I was able to fix the problem by changing the yt-dlp options. Specifically, I added format and extractor_args flags. Note: the above code worked on localhost, the below code worked on Heroku deployed webapp as well as the 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']}},