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

ffmpeg.py looks for ffmpeg_location #31448

Closed
6 tasks done
codevalid opened this issue Jan 2, 2023 · 5 comments
Closed
6 tasks done

ffmpeg.py looks for ffmpeg_location #31448

codevalid opened this issue Jan 2, 2023 · 5 comments

Comments

@codevalid
Copy link

codevalid commented Jan 2, 2023

Checklist

  • I'm reporting a broken site support issue
  • I've verified that I'm running youtube-dl version 2021.12.17
  • I've checked that all provided URLs are alive and playable in a browser
  • I've checked that all URLs and arguments with special characters are properly quoted or escaped
  • I've searched the bugtracker for similar bug reports including closed ones
  • I've read bugs section in FAQ

Verbose log

Traceback (most recent call last):
  File ".\PycharmProjects\pythonProject\Hello.py", line 42, in <module>
    meta = ydl.extract_info(
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 808, in extract_info
    return self.__extract_info(url, ie, download, extra_info, process)
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 815, in wrapper
    return func(self, *args, **kwargs)
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 847, in __extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 881, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 1692, in process_video_result
    self.process_info(new_info)
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 1976, in process_info
    success = dl(filename, info_dict)
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 1915, in dl
    return fd.download(name, info)
  File ".\anaconda3\lib\site-packages\youtube_dl\downloader\common.py", line 366, in download
    return self.real_download(filename, info_dict)
  File ".\anaconda3\lib\site-packages\youtube_dl\downloader\external.py", line 35, in real_download
    retval = self._call_downloader(tmpfilename, info_dict)
  File ".\anaconda3\lib\site-packages\youtube_dl\downloader\external.py", line 227, in _call_downloader
    self.report_error('m3u8 download detected but ffmpeg or avconv could not be found. Please install one.')
  File ".\anaconda3\lib\site-packages\youtube_dl\downloader\common.py", line 165, in report_error
    self.ydl.report_error(*args, **kargs)
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 628, in report_error
    self.trouble(error_message, tb)
  File ".\anaconda3\lib\site-packages\youtube_dl\YoutubeDL.py", line 598, in trouble
    raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: m3u8 download detected but ffmpeg or avconv could not be found. Please install one.

Description

While running from command line, the location of ffmppeg can be passed using option --ffmpeg-location
However, while trying to use this in Python, using this option produces the above error, even though it's passed as below
'ffmpeg-location' : '.\Downloads\ffmpeg\bin\ffmpeg.exe',
I was trying to go through various modules where this value is being picked up, and found it in ffmpeg.py

location = self._downloader.params.get('ffmpeg_location')

now once i change the option to use this,

'ffmpeg_location' : '.\Downloads\ffmpeg\bin\ffmpeg.exe',
everything works fine. Can we either fix the code or update the documentation to use underscore, instead of hypen?

@afterdelight

This comment was marked as off-topic.

@codevalid

This comment was marked as off-topic.

@rautamiekka

This comment was marked as off-topic.

@dirkf
Copy link
Contributor

dirkf commented Jan 3, 2023

The parameter names in the code aren't the same as the command-line options. Look at options.py (ca. l.853) for the mapping.

@dirkf dirkf added the question label Jan 11, 2023
@dirkf
Copy link
Contributor

dirkf commented Jan 12, 2023

This well hacky code achieves the same for yt-dl as the much slicker code posted for yt-dlp, ie it shows what API parameters correspond to a given set of command-line options and so answers OP's question:

import youtube_dl
from types import MethodType
from youtube_dl.utils import DateRange

def cli_to_api(*opts):
    YDL = youtube_dl.YoutubeDL

    class ParseYTDLResult(Exception):
        def __init__(self, result):
            super(ParseYTDLResult, self).__init__('result')
            self.opts = result

    def ytdl_init(ydl, ydl_opts):
        super(YDL, ydl).__init__(ydl_opts)
        raise ParseYTDLResult(ydl_opts)

    YDL.__init__ = MethodType(ytdl_init, YDL)

    def parsed_options(argv):
        try:
            youtube_dl._real_main(list(argv))
        except ParseYTDLResult as result:
            return result.opts

    # should be set in utils
    def DR__ne__(d, other):
        try:
            if isinstance(d, DateRange):
                return d.start != other.start or d.end != other.end
        except Exception:
            pass
        return d != other 

    default = parsed_options([])
    diff = dict((k, v) for k, v in parsed_options(opts).items() if DR__ne__(default[k], v))
    if 'postprocessors' in diff:
        diff['postprocessors'] = [pp for pp in diff['postprocessors'] if pp not in default['postprocessors']]
    return diff

Eg:

>>> cli_to_api('--ffmpeg-location', '.\\Downloads\\ffmpeg\\bin\\ffmpeg.exe')
{'ffmpeg_location': '.\\Downloads\\ffmpeg\\bin\\ffmpeg.exe'}
>>> cli_to_api('-x', '--audio-format', 'mp3')
{'format': 'bestaudio/best', 'postprocessors': [{'preferredcodec': 'mp3', 'nopostoverwrites': False, 'key': 'FFmpegExtractAudio', 'preferredquality': '5'}]}
>>> 

@dirkf dirkf closed this as completed Jan 12, 2023
@dirkf dirkf changed the title ffmpeg.py looks for 'ffmpeg_location ffmpeg.py looks for ffmpeg_location Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants