these files are indeed quite hardcore to parse by hand. Try something like this:
Code:
#!/usr/bin/env python
import sys
import urllib2
import xml.etree.ElementTree as ET
# param1 = user, param2 = result count
url = 'https://gdata.youtube.com/feeds/api/users/{0}/uploads?max-results={1}'.format( sys.argv[1], sys.argv[2] )
req = urllib2.Request( url )
f = urllib2.urlopen( req )
xmlroot = ET.fromstring( f.read() )
for entry in ( x for x in xmlroot if x.tag.endswith( '}entry' ) ): # entry tags are about clips
for elem in entry:
tag = elem.tag.split('}')[-1]
if tag=='link' and elem.get('rel')=='self':
print 'video_id: '+elem.get('href').split('/')[-1]
elif tag=='title':
print 'title: '+elem.text
elif tag=='statistics':
print 'view count: '+elem.get('viewCount' )
print
in action:
Code:
$ ./yt.py IGNEntertainment 3
title: IGN News - Activision Has No Debt, $4.6 Billion in Cash
video_id: GwbnUwQ_A50
view count: 10525
title: Injustice: Gods Among Us - Lobo Combos 1
video_id: 1k8N8bVYVD4
view count: 9741
title: GTA V Screenshots, Stars Wars/Battlefield/FIFA Updates, & Avengers 2 Woes - IGN Daily Fix 05.08.13
video_id: j_iSJ1KSrbU
view count: 21480
i used this to parse the xml
http://docs.python.org/2/library/xml...ementtree.html
Bookmarks