Thursday, 15 July 2010

python - Getting length of YouTube video (without downloading the video itself) -


I need to know the simplest way to grab the length of YouTube video that is given to the URL of the video according to the program .

Is the YouTube API the Best Way? It looks something complex and I've never used it before, so I'm likely to take a bit to adjust, but I really want a quick solution. I take a look through the source of a video page, which is expected to be listed in it, but apparently this (although it lists the suggested video times in a very good list which would be easy to parse ) If this is the best method, then is anyone snippet?

Ideally I can do it in Python, and I need it to finally

  00: 00: 00   < P> But I'm completely open for any solution I could have anyway.  

I appreciate any insights.

All you have to do is get the seconds from XML given by YouTube API 2.0 The attribute is in the yt: duration element. You end with only a second resolution (not yet a millisecond). Here's an example: xml.dom.minidom import from urlib2 import urlopen from parseString to vid in datetime import timedelta ('wJ4hPaNyHnY', 'dJ38nHlVE78', 'huXaL8qj2Vs'): Https://gdata.youtube. Com / feeds / api / videos / {0}? V = 2'.format (vid) s = urlopen (url) .read () d = parseString (s) e = d.getElementsByTagName ('Yt: duration') [ 0] A = eeditimes ['sec'] v = int (au) t = timeldata (second = v) print (t)

and output is:

  0:00:59 0:02:24 0:04:49    

No comments:

Post a Comment