Created
May 18, 2014 11:28
-
-
Save AndiH/6966d0f32a70c75c330f to your computer and use it in GitHub Desktop.
Retrieve (max.) resolution of YouTube Video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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