fivetv.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from .common import InfoExtractor
  2. from ..utils import int_or_none
  3. class FiveTVIE(InfoExtractor):
  4. _VALID_URL = r'''(?x)
  5. https?://
  6. (?:www\.)?5-tv\.ru/
  7. (?:
  8. (?:[^/]+/)+(?P<id>\d+)|
  9. (?P<path>[^/?#]+)(?:[/?#])?
  10. )
  11. '''
  12. _TESTS = [{
  13. 'url': 'http://5-tv.ru/news/96814/',
  14. 'md5': 'bbff554ad415ecf5416a2f48c22d9283',
  15. 'info_dict': {
  16. 'id': '96814',
  17. 'ext': 'mp4',
  18. 'title': 'Россияне выбрали имя для общенациональной платежной системы',
  19. 'description': 'md5:a8aa13e2b7ad36789e9f77a74b6de660',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'duration': 180,
  22. },
  23. }, {
  24. 'url': 'http://5-tv.ru/video/1021729/',
  25. 'info_dict': {
  26. 'id': '1021729',
  27. 'ext': 'mp4',
  28. 'title': '3D принтер',
  29. 'description': 'md5:d76c736d29ef7ec5c0cf7d7c65ffcb41',
  30. 'thumbnail': r're:^https?://.*\.jpg$',
  31. 'duration': 180,
  32. },
  33. }, {
  34. # redirect to https://www.5-tv.ru/projects/1000095/izvestia-glavnoe/
  35. 'url': 'http://www.5-tv.ru/glavnoe/#itemDetails',
  36. 'info_dict': {
  37. 'id': 'glavnoe',
  38. 'ext': 'mp4',
  39. 'title': r're:^Итоги недели с \d+ по \d+ \w+ \d{4} года$',
  40. 'thumbnail': r're:^https?://.*\.jpg$',
  41. },
  42. 'skip': 'redirect to «Известия. Главное» project page',
  43. }, {
  44. 'url': 'http://www.5-tv.ru/glavnoe/broadcasts/508645/',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://5-tv.ru/films/1507502/',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'http://5-tv.ru/programs/broadcast/508713/',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'http://5-tv.ru/angel/',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'http://www.5-tv.ru/schedule/?iframe=true&width=900&height=450',
  57. 'only_matching': True,
  58. }]
  59. def _real_extract(self, url):
  60. mobj = self._match_valid_url(url)
  61. video_id = mobj.group('id') or mobj.group('path')
  62. webpage = self._download_webpage(url, video_id)
  63. video_url = self._search_regex(
  64. [r'<div[^>]+?class="(?:flow)?player[^>]+?data-href="([^"]+)"',
  65. r'<a[^>]+?href="([^"]+)"[^>]+?class="videoplayer"'],
  66. webpage, 'video url')
  67. title = self._generic_title('', webpage)
  68. duration = int_or_none(self._og_search_property(
  69. 'video:duration', webpage, 'duration', default=None))
  70. return {
  71. 'id': video_id,
  72. 'url': video_url,
  73. 'title': title,
  74. 'description': self._og_search_description(webpage, default=None),
  75. 'thumbnail': self._og_search_thumbnail(webpage, default=None),
  76. 'duration': duration,
  77. }