Created
February 17, 2012 14:56
-
-
Save alejandrobernardis/1853912 to your computer and use it in GitHub Desktop.
Simple YouTube Video List
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Copyright (c) 2012 Young and Rubicam Digital Mexico. | |
# Licensed under the Apache License, Version 2.0 (the "License") | |
# | |
# Author: Alejandro M. Bernardis | |
# Email: alejandro.bernardis at gmail.com | |
# Created: Feb 17, 2012 08:54:18 AM | |
# | |
import gdata.youtube.service | |
import os | |
import re | |
import shutil | |
from datetime import datetime | |
#: -- | |
def PrintVideoList(vlist=None, vcount=0, vtotal=5, vi=0, user_name=None, file_name="../database.csv"): | |
if not user_name: | |
raise TypeError('PrintVideoList() required the user_name define.') | |
if vlist: | |
with open(file_name, "a") as f: | |
for entry in vlist.entry: | |
vi += 1 | |
vid = re.sub(r"http:\/\/gdata.youtube.com\/feeds\/api\/videos\/", "", entry.id.text) | |
line = "%s,%s,%s\n" % (vi, vid, entry.media.title.text) | |
f.write(line) | |
print vi, user_name, vid, entry.media.title.text | |
f.close() | |
else: | |
if os.path.exists(file_name): | |
shutil.move(file_name, | |
"../backup_%s.csv" % datetime.strftime(datetime.now(), '%Y%m%d%H%M%S%f')) | |
if vcount < (vtotal+1): | |
i = (1 if vcount == 0 else (vcount*25)+1) | |
uri = "http://gdata.youtube.com/feeds/api/users/%s/uploads?start-index=%s&max-results=25" % (user_name, i) | |
vcount += 1 | |
PrintVideoList(ytsrv.GetYouTubeVideoFeed(uri=uri), vcount, vtotal, vi, user_name, file_name) | |
else: | |
print 'PrintVideoList (%s): %s videos' % (user_name, vi) | |
#: -- | |
if __name__ == '__main__': | |
PrintVideoList(user_name="my_username") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment