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

How to download the video with a resolution less than or equal to 720p and with audio. #23847

Closed
EugenSmith opened this issue Jan 26, 2020 · 1 comment
Labels

Comments

@EugenSmith
Copy link

@EugenSmith EugenSmith commented Jan 26, 2020

Hello, all!
I use embedded youtube-dl in python script for download video with a resolution less than or equal to 720p. Video successfully downloaded but without audio.
Could somebody offer some advice. How to download the video with a resolution less than or equal to 720p and with audio?

#!/usr/bin/env python

# encoding: utf-8
from __future__ import unicode_literals
import os, sys, youtube_dl

def download(url):
     ydl_options = {
         "outtmpl":           "%(id)s.%(ext)s",
         "writethumbnail": True,        
         "addmetadata": True,
         "format": "bestvideo/best[height<=720]+bestaudio/best[height<=720]",
         "continuedl": True,
         "quiet": False,
         "restrictfilenames": False,
         "ignoreerrors": True
     }
     with youtube_dl.YoutubeDL(ydl_options) as ydl:
        try:
            ydl.download([url])
        except (youtube_dl.utils.DownloadError,youtube_dl.utils.ContentTooShortError,youtube_dl.utils.ExtractorError) as e:
            print(e)      

def main():
    download(str(sys.argv[1]))    

if __name__ == "__main__":
    main()
@EugenSmith EugenSmith added the question label Jan 26, 2020
@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jan 26, 2020

Read FAQ on format selection.

@dstftw dstftw closed this Jan 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.