youtube-dl test video "'/\ä↭𝕐

By: Philipp Hagemeister

50   2   9732

Uploaded on 10/02/2012

test chars: "'/\ä↭𝕐
test URL: https://github.com/rg3/youtube-dl/issues/1892

This is a test video for youtube-dl.

For more information, contact phihag@phihag.de .

Comments (17):

By anonymous    2017-09-20

My crystal ball tells me that your URL contains ampersands, like https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9. In a shell, the ampersand makes the program run in the background (asynchronously).

Escape ampersands in URLs, by putting the whole URL in quotes:

youtube-dl 'https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9'

On Windows cmd, use double quotes instead:

youtube-dl "https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9"

Alternatively, escsape all problematic characters. Consult your shell handbook on which characters have special meanings and how to escape them. Oftentimes, a backslash will work:

 youtube-dl https://www.youtube.com/watch?v=BaW_jenozKc\&t=1s\&end=9

Original Thread

By anonymous    2017-09-20

Starting with youtube-dl 2017.03.16 - or right now if you check out the git repository - you can simply pass in --extract-audio --audio-format flac, as in:

youtube-dl -x --audio-format flac  https://www.youtube.com/watch?v=BaW_jenozKc

(-x is short for --extract-audio.)

Original Thread

By anonymous    2017-09-20

youtube-dl already contains this functionality - just specify that you want mp3:

youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=BaW_jenozKc

Replace https://www.youtube.com/watch?v=BaW_jenozKc with your actual URL.

Original Thread

By anonymous    2017-09-23

Ok, I know that to get Mp3 files from Youtube-DL in a python program you use

from __future__ import unicode_literals
import youtube_dl


ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
    'key': 'FFmpegExtractAudio',
    'preferredcodec': 'mp3',
    'preferredquality': '192',
    }], 
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

I have gotten that to work no problem. My problem is that i cannot get the -a or --batch file FILE to work with this I tried to set a Filesystem but that was just randomly guessing, and the information in the ReadMe is lacking for embedding.

Is there anyway to download youtube videos from a txt file using a Python program, or a resource online that explains embedding

Original Thread

By anonymous    2017-10-15

There is no need to write a configuration file; you can set the output template from python as well:

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    'outtmpl': '/var/www/html/media/audio/%(title)s.%(ext)s',
    'extractaudio': True,
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '320',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

Original Thread

By anonymous    2017-12-11

I'm using youtube-dl on python 3.6.1 on my Mac, and I have followed the proper steps, which is this code:

from __future__ import unicode_literals
import youtube_dl
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

But it is giving me this error:

Traceback (most recent call last):
  File "/Users/Hussein/Downloads/youtube_dl.py", line 2, in <module>
    import youtube_dl
  File "/Users/Hussein/Downloads/youtube_dl.py", line 5, in <module>
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
AttributeError: module 'youtube_dl' has no attribute 'YoutubeDL'

Original Thread

By anonymous    2017-12-18

Here's the code:

from __future__ import unicode_literals
import youtube_dl


ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

I pretty much copied this from download only audio from youtube video using youtube-dl in python script. The error that is coming up is:

AttributeError: module 'youtube_dl' has no attribute 'YoutubeDL'

I did lots of research but is seems youtube_dl is a pretty uncommon module. Essentially, it can get a ton of data off of youtube. The code I had was supposed to successfully grab audio from a youtube link of my desire. However, that same error always comes up. I ran it on python 2.7.13 and 3.6.3 - the same outcome on both. It seemed to have worked for otthers, and there was another thread about this here Can someone tell me what is causing the error so I can move onward with this project?

Original Thread

By anonymous    2018-02-12

The full list of options is documented in YoutubeDL.py. If you only want to replicate command-line options, you can also have a look in __init__.py.

To replicate --embed-thumbnail and --add-metadata, use the following:

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    'writethumbnail': True,
    'postprocessors': [{
        'key': 'FFmpegMetadata'
    }, {
        'key': 'EmbedThumbnail',
        'already_have_thumbnail': True,  # overwrite any thumbnails already present
    }],
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

Original Thread

By anonymous    2018-03-18

YoutubeDL.py does list all parameters to youtube-dl. embed-thumbnail and embedthumbnail don't work because they are not valid options for a YoutubeDL, and hence not listed in the list of options. However, these options cover "just" the download.

Many effects are implemented by postprocessors, i.e. code that runs after the download has been completed. Postprocessors can be composited in new ways, but if you just want to replicate an existing command-line invocation, have a look at the main function to find out how command-line options map to postprocessors and YoutubeDL API options. For instance, to write thumbnails into video files, you can use

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    'format': 'bestvideo[height<=480]+bestaudio[ext=m4a]/best',
    'updatetime': False,
    'writethumbnail': True,
    'postprocessors': [{
        'key': 'EmbedThumbnail',
        'already_have_thumbnail': False,
    }],
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

Original Thread

By anonymous    2018-03-18

Only a very small minority of the websites supported by youtube-dl actually serve audio-only files. But some do, including most videos on YouTube. For these, you can request the filetype bestaudio and extract the information instead of downloading:

from __future__ import unicode_literals 
import youtube_dl

ydl_opts = {
    'format': 'bestaudio',
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    info = ydl.extract_info(
        'https://www.youtube.com/watch?v=BaW_jenozKc', download=False)
    print(info['formats'][0]['url'])

Note that this will get you the correct URL. However, there is no guarantee that this URL will work, if you change anything of:

  • The IP address using the URL (in other words, if you transfer this URL to another machine and try to download from there, it won't work).
  • The HTTP headers (User-Agent and such). Can be found in the http_headers key of the format dictionary.
  • The cookies (can be found in ydl.cookiejar).

Which of these constrains have to be met depends on the video, and is subject to sudden change. For instance, it looks like at the moment the URL is enough for many YouTube videos, but YouTube has definitely blocked other IPv4 addresses and even all different IP addresses for some videos, or only music and other highly monetized videos, over time.

Also note that the file you'll get may be in a strange format. For instance, YouTube used to send invalid m4a files which could not be read by most players. You'll often get opus, which may not be supported everywhere. If you just want the audio file, it's better to let youtube-dl download and convert it, as described in the documentation and other answers.

Original Thread

By anonymous    2018-05-01

I am attempting to download the highest quality audio and video of a particular YouTube video from within a Python script.

My code is pretty straight forward:

import youtube_dl
ydl_opts = {
    'format': 'bestvideo[width>=1920]/bestvideo+bestaudio/best',
    'outtmpl': 'test.mp4',
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

The format line was taken from this question.

The problem I'm encountering is that the downloaded result has no audio component. The video component works as expected. The console output doesn't seem to indicate that audio is downloaded either.

C:\Dev>py youtube_test.py
[youtube] BaW_jenozKc: Downloading webpage
[youtube] BaW_jenozKc: Downloading video info webpage
[youtube] BaW_jenozKc: Extracting video information
[download] Destination: test.mp4
[download] 100% of 2.11MiB in 00:00

Why am I not getting the audio component over the test video and how can I solve that?

I am running on Windows 10. I have ffmpeg installed and in my path.

C:\Dev>ffmpeg -version
ffmpeg version N-90721-g783df2eb59 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil      56. 13.100 / 56. 13.100
libavcodec     58. 17.100 / 58. 17.100
libavformat    58. 11.101 / 58. 11.101
libavdevice    58.  2.100 / 58.  2.100
libavfilter     7. 15.100 /  7. 15.100
libswscale      5.  0.102 /  5.  0.102
libswresample   3.  0.101 /  3.  0.101
libpostproc    55.  0.100 / 55.  0.100

Original Thread

By anonymous    2018-05-01

The format and output template in your code are wrong. Let's start with the format: Your specification bestvideo[width>=1920]/bestvideo+bestaudio/best says:

  1. If present and with width >= 1920, pick the best video format.
  2. Otherwise, pick the best video format, and the best audio format, and combine them.
  3. Otherwise, pick the best file with audio and video included.

Simply remove the first term and pass in bestvideo+bestaudio/best.

Note that the resulting file may not be mp4, so you should also use %(ext)s in the output template. In summary, use this:

import youtube_dl
ydl_opts = {
    'format': 'bestvideo+bestaudio/best',
    'outtmpl': 'test.%(ext)s',
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])

Original Thread

By anonymous    2018-05-14

Use a Pool:

import multiprocessing.dummy
import subprocess

arr = [
    {'vpath': 'example/%(title)s.%(ext)s', 'url': 'https://www.youtube.com/watch?v=BaW_jenozKc'},
    {'vpath': 'example/%(title)s.%(ext)s', 'url': 'http://vimeo.com/56015672'},
    {'vpath': '%(playlist_title)s/%(title)s-%(id)s.%(ext)s',
     'url': 'https://www.youtube.com/playlist?list=PLLe-WjSmNEm-UnVV8e4qI9xQyI0906hNp'},
]

email = 'my-email@example.com'
password = '123456'

def download(v):
    subprocess.check_call([
        'echo', 'youtube-dl',
        '-u', email, '-p', password,
        '-o', v['vpath'], '--', v['url']])


p = multiprocessing.dummy.Pool(concurrent)
p.map(download, arr)

multiprocessing.dummy.Pool is a lightweight thread-based version of a Pool, which is more suitable here because the work tasks are just starting subprocesses.

Note that instead of os.system, subprocess.check_call, which prevents the command injection vulnerability in your previous code.

Also note that youtube-dl output templates are really powerful. In most cases, you don't actually need to define and manage file names yourself.

Original Thread

By anonymous    2018-05-21

Your code has several errors:

  • your indentation is not good, in python it is very important.
  • You are trying to use undefined variables.
  • The task of downloading is blocking so your program will probably freeze, the solution is to execute it from another thread, and to send the information you must use signals, in this case we create the progressChanged and finished signals that will inform the progress and the end of the download, respectively.

from __future__ import unicode_literals

import sys
import os
import threading

import youtube_dl

from youtube_dl import postprocessor

from PyQt5.QtCore import QDir, QObject, pyqtSignal, Qt
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox, QFileDialog

from downloader_ui import Ui_Dialog

class YoutubeWorker(QObject):
    progressChanged = pyqtSignal(int)
    finished = pyqtSignal()

    def doWork(self, url, path):
        def my_hook(d):
            if d['status'] == 'finished':
                self.finished.emit()
            elif d['status'] == 'downloading' :
                progresol = d['_percent_str']
                progreso = progresol.replace("%","")
                self.progressChanged.emit(float(progreso))
        ydl_opts = {
                'format': 'best',
                'outtmpl': os.path.join(path, 'video/%(title)s.%(ext)s'),
                'noplayList': False,
                'postprocessor': [{'key':'FFmegExtractAudio',
                                'preferredcodec': 'mp3',
                                'preferredquality': '256',}],
                'progress_hooks':[my_hook],
            }
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([url])

class helloworld(QDialog, Ui_Dialog):
    def __init__(self):
        QDialog.__init__(self)
        self.setupUi(self)
        self.url.setText("https://www.youtube.com/watch?v=BaW_jenozKc")
        self.save_location.setText(os.getcwd())
        self.download.clicked.connect(self.presionar)
        self.Browse.clicked.connect(self.seleccionar_directorio)

    def seleccionar_directorio(self):
        directorio = QFileDialog.getExistingDirectory(self, "Seleccionar Carpeta", 
            os.getcwd(), 
            QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)
        if directorio:
            self.save_location.setText(directorio)

    def presionar(self):
        self.worker = YoutubeWorker()
        self.worker.progressChanged.connect(self.progress.setValue, Qt.QueuedConnection)
        self.worker.finished.connect(lambda: QMessageBox.about(self,"inicio", "descarga completa"))
        th = threading.Thread(target= self.worker.doWork, args = (self.url.text(), self.save_location.text()))
        th.daemon = True
        th.start()

if __name__== "__main__":
    app = QApplication(sys.argv)
    aplicacion = helloworld()
    aplicacion.show()
    sys.exit(app.exec_())

Original Thread

Submit Your Video

If you have some great dev videos to share, please fill out this form.