snotr.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. parse_duration,
  7. parse_filesize,
  8. str_to_int,
  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': 'mp4',
  17. 'title': 'Drone flying through fireworks!',
  18. 'duration': 248,
  19. 'filesize_approx': 40700000,
  20. 'description': 'A drone flying through Fourth of July Fireworks',
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. },
  23. 'expected_warnings': ['description'],
  24. }, {
  25. 'url': 'http://www.snotr.com/video/530/David_Letteman_-_George_W_Bush_Top_10',
  26. 'info_dict': {
  27. 'id': '530',
  28. 'ext': 'mp4',
  29. 'title': 'David Letteman - George W. Bush Top 10',
  30. 'duration': 126,
  31. 'filesize_approx': 8500000,
  32. 'description': 'The top 10 George W. Bush moments, brought to you by David Letterman!',
  33. 'thumbnail': 're:^https?://.*\.jpg$',
  34. }
  35. }]
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. video_id = mobj.group('id')
  39. webpage = self._download_webpage(url, video_id)
  40. title = self._og_search_title(webpage)
  41. description = self._og_search_description(webpage)
  42. info_dict = self._parse_html5_media_entries(url, webpage, video_id)[0]
  43. view_count = str_to_int(self._html_search_regex(
  44. r'<p[^>]*>\s*<strong[^>]*>Views:</strong>\s*<span[^>]*>([\d,\.]+)',
  45. webpage, 'view count', fatal=False))
  46. duration = parse_duration(self._html_search_regex(
  47. r'<p[^>]*>\s*<strong[^>]*>Length:</strong>\s*<span[^>]*>([\d:]+)',
  48. webpage, 'duration', fatal=False))
  49. filesize_approx = parse_filesize(self._html_search_regex(
  50. r'<p[^>]*>\s*<strong[^>]*>Filesize:</strong>\s*<span[^>]*>([^<]+)',
  51. webpage, 'filesize', fatal=False))
  52. info_dict.update({
  53. 'id': video_id,
  54. 'description': description,
  55. 'title': title,
  56. 'view_count': view_count,
  57. 'duration': duration,
  58. 'filesize_approx': filesize_approx,
  59. })
  60. return info_dict