Created
March 22, 2014 03:26
-
-
Save hagino3000/9700646 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
import argparse | |
import json | |
import urllib | |
parser = argparse.ArgumentParser(description="Fetch Youtube movie info by movie id", | |
formatter_class=argparse.RawDescriptionHelpFormatter, | |
epilog='Ex: python fetch_ytmovie.py rMHdqOyp6tc' | |
) | |
parser.add_argument('movie_id', metavar='id', type=str, nargs='?', help='Movie ID string') | |
args = parser.parse_args() | |
def main(): | |
if args.movie_id is None: | |
parser.print_help() | |
return | |
url = 'http://gdata.youtube.com/feeds/api/videos/%s?alt=json' % args.movie_id | |
print("Start fetch %s" % url) | |
f = urllib.urlopen(url) | |
ret = f.read() | |
data = json.loads(ret) | |
output(data) | |
def output(data): | |
print('======= Title ==========') | |
print(data['entry']['title']['$t']) | |
print('======= Description ==========') | |
print(data['entry']['media$group']['media$description']['$t']) | |
print('======= thumbnails ==========') | |
for t in data['entry']['media$group']['media$thumbnail']: | |
print('%s*%s %s' % (t['width'], t['height'], t['url'])) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment