lnkgo.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 = self._og_search_thumbnail(webpage)
  58. thumbnail_w = int_or_none(
  59. self._og_search_property('image:width', webpage, 'thumbnail width', fatal=False))
  60. thumbnail_h = int_or_none(
  61. self._og_search_property('image:height', webpage, 'thumbnail height', fatal=False))
  62. thumbnails = [{
  63. 'url': thumbnail,
  64. 'width': thumbnail_w,
  65. 'height': thumbnail_h,
  66. }]
  67. upload_date = unified_strdate(self._search_regex(
  68. r'class="meta-item\sair-time">.*?<strong>([^<]+)</strong>', webpage, 'upload date', fatal=False))
  69. duration = int_or_none(self._search_regex(
  70. r'VideoDuration = "([^"]+)"', webpage, 'duration', fatal=False))
  71. pg_rating = self._search_regex(
  72. r'pgrating="([^"]+)"', webpage, 'PG rating', fatal=False, default='')
  73. age_limit = self._AGE_LIMITS.get(pg_rating, 0)
  74. sources_js = self._search_regex(
  75. r'(?s)sources:\s(\[.*?\]),', webpage, 'sources')
  76. sources = self._parse_json(
  77. sources_js, video_id, transform_source=js_to_json)
  78. formats = []
  79. for source in sources:
  80. if source.get('provider') == 'rtmp':
  81. m = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<play_path>.+)$', source['file'])
  82. if not m:
  83. continue
  84. formats.append({
  85. 'format_id': 'rtmp',
  86. 'ext': 'flv',
  87. 'url': m.group('url'),
  88. 'play_path': m.group('play_path'),
  89. 'page_url': url,
  90. })
  91. elif source.get('file').endswith('.m3u8'):
  92. formats.append({
  93. 'format_id': 'hls',
  94. 'ext': source.get('type', 'mp4'),
  95. 'url': source['file'],
  96. })
  97. self._sort_formats(formats)
  98. return {
  99. 'id': video_id,
  100. 'display_id': display_id,
  101. 'title': title,
  102. 'formats': formats,
  103. 'thumbnails': thumbnails,
  104. 'duration': duration,
  105. 'description': description,
  106. 'age_limit': age_limit,
  107. 'upload_date': upload_date,
  108. }