I would like to access the result of the following shell command,
youtube-dl -g "www.youtube.com/..."
to print its output direct url
to a file, from within a python program. This is what I have tried:
import youtube-dl fromurl="www.youtube.com/..." geturl=youtube-dl.magiclyextracturlfromurl(fromurl)
Is that possible? I tried to understand the mechanism in the source but got lost: youtube_dl/__init__.py
, youtube_dl/youtube_DL.py
, info_extractors
...
You can use 'format', 'continue', 'outtmpl' in ydl_opts As example; ydl_opts= { 'format: '22', 'continue': True; 'outtmpl': '%(uploader)s - %(title)s. %(ext)s' 'progress_hooks': [my_hook], } def my_hook(d): if d['status'] == 'downloading': print('Downloading video! ') if d['status'] == 'finished': print('Downloaded!
About youtube-dl youtube-dl is a command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter (2.6, 2.7, or 3.2+), and it is not platform-specific.
The simplest way to use YouTube-dl is to give it the URL of a youtube video. Go to a video on YouTube that you want to download. Select the text of the URL in the address bar, and copy it to your clipboard by pressing Ctrl + C . If the URL has a "&" in it (a playlist, for example), only copy the URL up to the & symbol.
Downloading videos from YouTube is in breach of YouTube's Terms of Service, and the company could sue you. YouTube has shown no desire to penalize users for downloading videos. Downloading copyrighted videos without permission is a criminal act.
It's not difficult and actually documented:
import youtube_dl ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s.%(ext)s'}) with ydl: result = ydl.extract_info( 'http://www.youtube.com/watch?v=BaW_jenozKc', download=False # We just want to extract the info ) if 'entries' in result: # Can be a playlist or a list of videos video = result['entries'][0] else: # Just a video video = result print(video) video_url = video['url'] print(video_url)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With