You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.2 KiB

  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. 'description': 'A drone flying through Fourth of July Fireworks',
  21. }
  22. }, {
  23. 'url': 'http://www.snotr.com/video/530/David_Letteman_-_George_W_Bush_Top_10',
  24. 'info_dict': {
  25. 'id': '530',
  26. 'ext': 'flv',
  27. 'title': 'David Letteman - George W. Bush Top 10',
  28. 'duration': 126,
  29. 'filesize_approx': 8912896,
  30. 'description': 'The top 10 George W. Bush moments, brought to you by David Letterman!',
  31. }
  32. }]
  33. def _real_extract(self, url):
  34. mobj = re.match(self._VALID_URL, url)
  35. video_id = mobj.group('id')
  36. webpage = self._download_webpage(url, video_id)
  37. title = self._og_search_title(webpage)
  38. description = self._og_search_description(webpage)
  39. video_url = "http://cdn.videos.snotr.com/%s.flv" % video_id
  40. view_count = str_to_int(self._html_search_regex(
  41. r'<p>\n<strong>Views:</strong>\n([\d,\.]+)</p>',
  42. webpage, 'view count', fatal=False))
  43. duration = parse_duration(self._html_search_regex(
  44. r'<p>\n<strong>Length:</strong>\n\s*([0-9:]+).*?</p>',
  45. webpage, 'duration', fatal=False))
  46. filesize_approx = float_or_none(self._html_search_regex(
  47. r'<p>\n<strong>Filesize:</strong>\n\s*([0-9.]+)\s*megabyte</p>',
  48. webpage, 'filesize', fatal=False), invscale=1024 * 1024)
  49. return {
  50. 'id': video_id,
  51. 'description': description,
  52. 'title': title,
  53. 'url': video_url,
  54. 'view_count': view_count,
  55. 'duration': duration,
  56. 'filesize_approx': filesize_approx,
  57. }