Skip to content

Instantly share code, notes, and snippets.

@AndiH
Created May 18, 2014 11:28
Show Gist options
  • Select an option

  • Save AndiH/6966d0f32a70c75c330f to your computer and use it in GitHub Desktop.

Select an option

Save AndiH/6966d0f32a70c75c330f to your computer and use it in GitHub Desktop.
Retrieve (max.) resolution of YouTube Video
import urllib2, argparse
from bs4 import BeautifulSoup
def getWidthAndHeight(videoURL):
video = urllib2.urlopen(videoURL)
videoSoup = BeautifulSoup(video)
width = height = 0
for element in videoSoup.find_all('meta'):
if (element.get('property') == 'og:video:width'):
width = int(element.get('content'))
if (element.get('property') == 'og:video:height'):
height = int(element.get('content'))
return (width, height)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Retrieve max resolution of youtube video")
parser.add_argument('-url', type=str, help="Youtube Video URL")
args = parser.parse_args()
(width, height) = getWidthAndHeight(args.url)
print(str(width) + "x" + str(height) + " (" + str(round(float(width)/float(height),4)) + " ratio)" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment