snotr.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. float_or_none,
  7. str_to_int,
  8. parse_duration,
  9. )
  10. class SnotrIE(InfoExtractor):
  11. _VALID_URL = r'http?://(?:www\.)?snotr\.com/video/(?P<id>\d+)/([\w]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.snotr.com/video/13708/Drone_flying_through_fireworks',
  14. 'info_dict': {
  15. 'id': '13708',
  16. 'ext': 'flv',
  17. 'title': 'Drone flying through fireworks!',
  18. 'duration': 247,
  19. 'filesize_approx': 98566144,
  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_approx': 8912896,
  29. }
  30. }]
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('id')
  34. webpage = self._download_webpage(url, video_id)
  35. title = self._og_search_title(webpage)
  36. description = self._og_search_description(webpage)
  37. video_url = "http://cdn.videos.snotr.com/%s.flv" % video_id
  38. view_count = str_to_int(self._html_search_regex(
  39. r'<p>\n<strong>Views:</strong>\n([\d,\.]+)</p>',
  40. webpage, 'view count', fatal=False))
  41. duration = parse_duration(self._html_search_regex(
  42. r'<p>\n<strong>Length:</strong>\n\s*([0-9:]+).*?</p>',
  43. webpage, 'duration', fatal=False))
  44. filesize_approx = float_or_none(self._html_search_regex(
  45. r'<p>\n<strong>Filesize:</strong>\n\s*([0-9.]+)\s*megabyte</p>',
  46. webpage, 'filesize', fatal=False), invscale=1024 * 1024)
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'url': video_url,
  51. 'view_count': view_count,
  52. 'duration': duration,
  53. 'filesize_approx': filesize_approx,
  54. }