-
Notifications
You must be signed in to change notification settings - Fork 0
/
getInfo.py
62 lines (52 loc) · 2.11 KB
/
getInfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
import os
import random
import re
import shlex
import subprocess
import xml.dom.minidom
from vidKeys import *
def getVinfo(vid):
(author, title, width, height, desc, views, upDate, srcURL, encURL) = ('', '', '0', '0', '', '0', '0', '', '')
fileName = '/tmp/vids/viddler-' + vid
os.system('wget --timeout=30 --tries=3 -q -O ' + fileName + ' "http://api.viddler.com/rest/v1/?method=viddler.videos.getDetails&api_key=' + apiKey + '&video_id=' + vid + '&include_comments=0"')
try:
xmlDoc = xml.dom.minidom.parse(fileName)
curNode = xmlDoc.documentElement.firstChild # should now be inside <video>
while curNode:
if curNode.tagName == 'code': # this is <error><code> -- aaa, abandon ship
return ('', '', '0', '0', '', '0', '0', '', '')
elif curNode.tagName == 'author':
author = curNode.firstChild.data
elif curNode.tagName == 'id':
id = curNode.firstChild.data
elif curNode.tagName == 'title':
if curNode.firstChild != None: # odd ones are blank. viddler bug
title = curNode.firstChild.data
elif curNode.tagName == 'width':
width = curNode.firstChild.data
elif curNode.tagName == 'height':
height = curNode.firstChild.data
elif curNode.tagName == 'description':
# This is optional, unlike everything else
if curNode.firstChild == None:
desc = ''
else:
desc = curNode.firstChild.data
elif curNode.tagName == 'view_count':
views = curNode.firstChild.data
elif curNode.tagName == 'upload_time':
upDate = curNode.firstChild.data
elif curNode.tagName == 'files':
fNode = curNode.firstChild
while fNode:
if fNode.tagName == 'source':
srcURL = fNode.firstChild.data
elif fNode.tagName == 'flv':
encURL = fNode.firstChild.data
fNode = fNode.nextSibling
curNode = curNode.nextSibling
except:
return (author, title, width, height, desc, views, upDate, srcURL, encURL)
os.remove(fileName)
return (author, title, width, height, desc, views, upDate, srcURL, encURL)