I'm new to python and I'm writing a python script to use youtube-dl to extract only download link, exactly like link given by the console (youtube-dl --get-url url). I don't want to download the media, I just need the download-link from my script.
12 Answers
>>> from youtube_dl import YoutubeDL # $ pip install youtube-dl >>> url = ' >>> ydl = YoutubeDL() >>> r = ydl.extract_info(url, download=False) [youtube] pvAsqPbz9Ro: Downloading webpage [youtube] pvAsqPbz9Ro: Downloading video info webpage [youtube] pvAsqPbz9Ro: Extracting video information [youtube] pvAsqPbz9Ro: Downloading DASH manifest [youtube] pvAsqPbz9Ro: Downloading DASH manifest >>> r['url'] u' If there are several media formats then to get media url for the last format:
with youtube_dl.YoutubeDL(dict(forceurl=True)) as ydl: r = ydl.extract_info(url, download=False) media_url = r['formats'][-1]['url'] 0from youtube_dl import YoutubeDL ydl = YoutubeDL() url = ' r = ydl.extract_info(url, download=False) # if any link will do urls = [format['url'] for format in r['formats']] # if you want links with video and audio urls = [f['url'] for f in r['formats'] if f['acodec'] != 'none' and f['vcodec'] != 'none']