fivetv.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. )
  7. class FiveTVIE(InfoExtractor):
  8. _VALID_URL = r'http://(?:www\.)?5-tv\.ru/[^/]*/(?P<id>\d+)'
  9. _TESTS = [
  10. {
  11. 'url': 'http://5-tv.ru/news/96814/',
  12. 'md5': 'bbff554ad415ecf5416a2f48c22d9283',
  13. 'info_dict': {
  14. 'id': '96814',
  15. 'ext': 'mp4',
  16. 'title': 'Россияне выбрали имя для общенациональной платежной системы',
  17. 'description': 'md5:a8aa13e2b7ad36789e9f77a74b6de660',
  18. 'thumbnail': 're:^https?://.*\.jpg$',
  19. 'width': 480,
  20. 'height': 360,
  21. 'duration': 180,
  22. },
  23. },
  24. {
  25. 'url': 'http://5-tv.ru/video/1021729/',
  26. 'md5': '299c8b72960efc9990acd2c784dc2296',
  27. 'info_dict': {
  28. 'id': '1021729',
  29. 'ext': 'mp4',
  30. 'title': '3D принтер',
  31. 'description': 'md5:d76c736d29ef7ec5c0cf7d7c65ffcb41',
  32. 'thumbnail': 're:^https?://.*\.jpg$',
  33. 'width': 480,
  34. 'height': 360,
  35. 'duration': 180,
  36. },
  37. },
  38. ]
  39. def _real_extract(self, url):
  40. video_id = self._match_id(url)
  41. webpage = self._download_webpage(url, video_id)
  42. video_link = self._search_regex(
  43. r'(<a.*?class="videoplayer">)', webpage, 'video link')
  44. url = self._search_regex(r'href="([^"]+)"', video_link, 'video url')
  45. width = int_or_none(self._search_regex(
  46. r'width:(\d+)px', video_link, 'width', default=None, fatal=False))
  47. height = int_or_none(self._search_regex(
  48. r'height:(\d+)px', video_link, 'height', default=None, fatal=False))
  49. duration = int_or_none(self._og_search_property(
  50. 'video:duration', webpage, 'duration'))
  51. return {
  52. 'id': video_id,
  53. 'url': url,
  54. 'width': width,
  55. 'height': height,
  56. 'title': self._og_search_title(webpage),
  57. 'description': self._og_search_description(webpage),
  58. 'thumbnail': self._og_search_thumbnail(webpage),
  59. 'duration': duration,
  60. }