snotr.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. str_to_int,
  7. parse_iso8601,
  8. )
  9. class SnotrIE(InfoExtractor):
  10. _VALID_URL = r'http?://(?:www\.)?snotr\.com/video/(?P<id>\d+)/([\w]+)'
  11. _TESTS =[ {
  12. 'url': 'http://www.snotr.com/video/13708/Drone_flying_through_fireworks',
  13. 'info_dict': {
  14. 'id': '13708',
  15. 'ext': 'flv',
  16. 'title': 'Drone flying through fireworks!',
  17. 'duration': 247,
  18. 'filesize':12320768
  19. }
  20. },
  21. {
  22. 'url': 'http://www.snotr.com/video/530/David_Letteman_-_George_W_Bush_Top_10',
  23. 'info_dict': {
  24. 'id': '530',
  25. 'ext': 'flv',
  26. 'title': 'David Letteman - George W. Bush Top 10',
  27. 'duration': 126,
  28. 'filesize': 1048576
  29. }
  30. }]
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('id')
  34. # TODO more code goes here, for example ...
  35. webpage = self._download_webpage(url, video_id)
  36. title = self._og_search_title(webpage)
  37. description = self._og_search_description(webpage)
  38. video_url = "http://cdn.videos.snotr.com/%s.flv" % video_id
  39. view_count = str_to_int(self._html_search_regex(r'<p>\n<strong>Views:</strong>\n([\d,\.]+)</p>',webpage,'view count'))
  40. duration = self._html_search_regex(r'<p>\n<strong>Length:</strong>\n(.*?)</p>',webpage,'duration')
  41. duration = str_to_int(duration[:1])*60 + str_to_int(duration[2:4])
  42. file_size = self._html_search_regex(r'<p>\n<strong>Filesize:</strong>\n(.*?)</p>',webpage,'filesize')
  43. file_size = str_to_int(re.match(r'\d+',file_size).group())*131072
  44. return {
  45. 'id': video_id,
  46. 'title': title,
  47. 'url':video_url,
  48. 'view_count':view_count,
  49. 'duration':duration,
  50. 'filesize':file_size
  51. }