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.

124 lines
4.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. int_or_none,
  7. js_to_json,
  8. unified_strdate,
  9. )
  10. class LnkGoIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?lnkgo\.alfa\.lt/visi\-video/(?P<show>[^/]+)/ziurek\-(?P<display_id>[A-Za-z0-9\-]+)'
  12. _TESTS = [{
  13. 'url': 'http://lnkgo.alfa.lt/visi-video/yra-kaip-yra/ziurek-yra-kaip-yra-162',
  14. 'info_dict': {
  15. 'id': '46712',
  16. 'ext': 'mp4',
  17. 'title': 'Yra kaip yra',
  18. 'upload_date': '20150107',
  19. 'description': 'md5:d82a5e36b775b7048617f263a0e3475e',
  20. 'age_limit': 7,
  21. 'duration': 3019,
  22. 'thumbnail': 're:^https?://.*\.jpg$'
  23. },
  24. 'params': {
  25. 'skip_download': True, # HLS download
  26. },
  27. }, {
  28. 'url': 'http://lnkgo.alfa.lt/visi-video/aktualai-pratesimas/ziurek-nerdas-taiso-kompiuteri-2',
  29. 'info_dict': {
  30. 'id': '47289',
  31. 'ext': 'mp4',
  32. 'title': 'Nėrdas: Kompiuterio Valymas',
  33. 'upload_date': '20150113',
  34. 'description': 'md5:7352d113a242a808676ff17e69db6a69',
  35. 'age_limit': 18,
  36. 'duration': 346,
  37. 'thumbnail': 're:^https?://.*\.jpg$'
  38. },
  39. 'params': {
  40. 'skip_download': True, # HLS download
  41. },
  42. }]
  43. _AGE_LIMITS = {
  44. 'N-7': 7,
  45. 'N-14': 14,
  46. 'S': 18,
  47. }
  48. def _real_extract(self, url):
  49. mobj = re.match(self._VALID_URL, url)
  50. display_id = mobj.group('display_id')
  51. webpage = self._download_webpage(
  52. url, display_id, 'Downloading player webpage')
  53. video_id = self._search_regex(
  54. r'data-ep="([^"]+)"', webpage, 'video ID')
  55. title = self._og_search_title(webpage)
  56. description = self._og_search_description(webpage)
  57. thumbnail_w = int_or_none(
  58. self._og_search_property('image:width', webpage, 'thumbnail width', fatal=False))
  59. thumbnail_h = int_or_none(
  60. self._og_search_property('image:height', webpage, 'thumbnail height', fatal=False))
  61. thumbnail = {
  62. 'url': self._og_search_thumbnail(webpage),
  63. }
  64. if thumbnail_w and thumbnail_h:
  65. thumbnail.update({
  66. 'width': thumbnail_w,
  67. 'height': thumbnail_h,
  68. })
  69. upload_date = unified_strdate(self._search_regex(
  70. r'class="meta-item\sair-time">.*?<strong>([^<]+)</strong>', webpage, 'upload date', fatal=False))
  71. duration = int_or_none(self._search_regex(
  72. r'VideoDuration = "([^"]+)"', webpage, 'duration', fatal=False))
  73. pg_rating = self._search_regex(
  74. r'pgrating="([^"]+)"', webpage, 'PG rating', fatal=False, default='')
  75. age_limit = self._AGE_LIMITS.get(pg_rating.upper(), 0)
  76. sources_js = self._search_regex(
  77. r'(?s)sources:\s(\[.*?\]),', webpage, 'sources')
  78. sources = self._parse_json(
  79. sources_js, video_id, transform_source=js_to_json)
  80. formats = []
  81. for source in sources:
  82. if source.get('provider') == 'rtmp':
  83. m = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<play_path>.+)$', source['file'])
  84. if not m:
  85. continue
  86. formats.append({
  87. 'format_id': 'rtmp',
  88. 'ext': 'flv',
  89. 'url': m.group('url'),
  90. 'play_path': m.group('play_path'),
  91. 'page_url': url,
  92. })
  93. elif source.get('file').endswith('.m3u8'):
  94. formats.append({
  95. 'format_id': 'hls',
  96. 'ext': source.get('type', 'mp4'),
  97. 'url': source['file'],
  98. })
  99. self._sort_formats(formats)
  100. return {
  101. 'id': video_id,
  102. 'display_id': display_id,
  103. 'title': title,
  104. 'formats': formats,
  105. 'thumbnails': [thumbnail],
  106. 'duration': duration,
  107. 'description': description,
  108. 'age_limit': age_limit,
  109. 'upload_date': upload_date,
  110. }