1
votes

Hey guys I am downloading a generic audio only MP4 file using youtube-dl but I want to convert the mp4 file to an mp3 using ffmpeg can I do this in the ytdl post processing option ?

As I mentioned above the the file is not an youtube video it's an generic link I will also paste my code and the errors I am having

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


url = "https://aac.saavncdn.com/372/16275cb323c0a13951a08c27660f0500_320.mp4"
with youtube_dl.YoutubeDL(ydl_opts) as ydl:

    ydl.download(url)

But I am getting an error saying 'h' is not a valid URL

ERROR: 'h' is not a valid URL. Set --default-search "ytsearch" (or run  youtube-dl "ytsearch:h" ) to search YouTube
Traceback (most recent call last):
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 806, in wrapper
    return func(self, *args, **kwargs)
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 827, in __extract_info
    ie_result = ie.extract(url)
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/extractor/common.py", line 534, in extract
    ie_result = self._real_extract(url)
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/extractor/generic.py", line 2381, in _real_extract
    raise ExtractorError(
youtube_dl.utils.ExtractorError: 'h' is not a valid URL. Set --default-search "ytsearch" (or run  youtube-dl "ytsearch:h" ) to search YouTube

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 2059, in download
    res = self.extract_info(
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 799, in extract_info
    return self.__extract_info(url, ie, download, extra_info, process)
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper
    self.report_error(compat_str(e), e.format_traceback())
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 628, in report_error
    self.trouble(error_message, tb)
  File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 598, in trouble
    raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: 'h' is not a valid URL. Set --default-search "ytsearch" (or run  youtube-dl "ytsearch:h" ) to search YouTube

Thank you

1
Asking people to just do something for you is not welcome here. Try to do it yourself, and ask a question if you have a specific technical problem on the way (and have searched for other instances of that problem and not found it covered in our knowledge base).Charles Duffy
Hey there I tried to download and convert the MP4 on my own but I ran into some error that's the reason I have asked the question here, as you have mentioned above I have made a mistake by not specifying the technical problem I will edit the question and will be more specific.Anish Gowda

1 Answers

2
votes

Any time you see an error where you give it a string and the API only sees one character, you need to suspect that the API actually expects a list or tuple. That's the case here. Do:

    ydl.download((url,))