PageRenderTime 68ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/tubestrip.py

https://github.com/arkem/hottest100
Python | 40 lines | 36 code | 3 blank | 1 comment | 2 complexity | c7fbefeab11380e6759b7bf62970ef7f MD5 | raw file
  1. #!/usr/bin/env python
  2. import urllib2
  3. import re
  4. import os
  5. import sys
  6. def strip_video(video_id):
  7. if video_id.find("youtube.com") != -1:
  8. url = video_id
  9. video_id = re.search("v=(\w*)", url).group(1)
  10. else:
  11. url = "http://youtube.com/watch?v=%s" % (video_id)
  12. title = video_id
  13. t_value = re.compile(""".*swfArgs.*
  14. "t":\s*
  15. "([^"]*)"
  16. """,re.VERBOSE|re.I)
  17. print url
  18. print video_id
  19. result = urllib2.urlopen(url).read()
  20. for line in result.split('\n'):
  21. m = re.match(t_value, line)
  22. if m:
  23. url = "%s/get_video.php?l=165&video_id=%s&t=%s&fmt=18" \
  24. % ("http://youtube.com", video_id, m.group(1))
  25. print url
  26. try:
  27. title = re.search("<title>(.*)</title>", result, re.M).group(1)
  28. except AttributeError:
  29. pass
  30. print 'Output: "%s.mp3"' % title
  31. os.system('mplayer -hardframedrop -vo null -cache 8096 -ao pcm:file="%s.pcm" "%s"' % (title, url))
  32. os.system('lame "%s.pcm" "%s.mp3"' % (title, title))
  33. os.system('rm "%s.pcm"' % title) # Dangerous
  34. for s in sys.argv[1:]:
  35. strip_video(s)