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.

88 lines
3.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. compat_str,
  8. int_or_none,
  9. parse_iso8601,
  10. )
  11. class LnkGoIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?lnk(?:go)?\.(?:alfa\.)?lt/(?:visi-video/[^/]+|video)/(?P<id>[A-Za-z0-9-]+)(?:/(?P<episode_id>\d+))?'
  13. _TESTS = [{
  14. 'url': 'http://www.lnkgo.lt/visi-video/aktualai-pratesimas/ziurek-putka-trys-klausimai',
  15. 'info_dict': {
  16. 'id': '10809',
  17. 'ext': 'mp4',
  18. 'title': "Put'ka: Trys Klausimai",
  19. 'upload_date': '20161216',
  20. 'description': 'Seniai matytas Put’ka užduoda tris klausimėlius. Pabandykime surasti atsakymus.',
  21. 'age_limit': 18,
  22. 'duration': 117,
  23. 'thumbnail': r're:^https?://.*\.jpg$',
  24. 'timestamp': 1481904000,
  25. },
  26. 'params': {
  27. 'skip_download': True, # HLS download
  28. },
  29. }, {
  30. 'url': 'http://lnkgo.alfa.lt/visi-video/aktualai-pratesimas/ziurek-nerdas-taiso-kompiuteri-2',
  31. 'info_dict': {
  32. 'id': '10467',
  33. 'ext': 'mp4',
  34. 'title': 'Nėrdas: Kompiuterio Valymas',
  35. 'upload_date': '20150113',
  36. 'description': 'md5:7352d113a242a808676ff17e69db6a69',
  37. 'age_limit': 18,
  38. 'duration': 346,
  39. 'thumbnail': r're:^https?://.*\.jpg$',
  40. 'timestamp': 1421164800,
  41. },
  42. 'params': {
  43. 'skip_download': True, # HLS download
  44. },
  45. }, {
  46. 'url': 'https://lnk.lt/video/neigalieji-tv-bokste/37413',
  47. 'only_matching': True,
  48. }]
  49. _AGE_LIMITS = {
  50. 'N-7': 7,
  51. 'N-14': 14,
  52. 'S': 18,
  53. }
  54. _M3U8_TEMPL = 'https://vod.lnk.lt/lnk_vod/lnk/lnk/%s:%s/playlist.m3u8%s'
  55. def _real_extract(self, url):
  56. display_id, video_id = re.match(self._VALID_URL, url).groups()
  57. video_info = self._download_json(
  58. 'https://lnk.lt/api/main/video-page/%s/%s/false' % (display_id, video_id or '0'),
  59. display_id)['videoConfig']['videoInfo']
  60. video_id = compat_str(video_info['id'])
  61. title = video_info['title']
  62. prefix = 'smil' if video_info.get('isQualityChangeAvailable') else 'mp4'
  63. formats = self._extract_m3u8_formats(
  64. self._M3U8_TEMPL % (prefix, video_info['videoUrl'], video_info.get('secureTokenParams') or ''),
  65. video_id, 'mp4', 'm3u8_native')
  66. self._sort_formats(formats)
  67. poster_image = video_info.get('posterImage')
  68. return {
  69. 'id': video_id,
  70. 'display_id': display_id,
  71. 'title': title,
  72. 'formats': formats,
  73. 'thumbnail': 'https://lnk.lt/all-images/' + poster_image if poster_image else None,
  74. 'duration': int_or_none(video_info.get('duration')),
  75. 'description': clean_html(video_info.get('htmlDescription')),
  76. 'age_limit': self._AGE_LIMITS.get(video_info.get('pgRating'), 0),
  77. 'timestamp': parse_iso8601(video_info.get('airDate')),
  78. 'view_count': int_or_none(video_info.get('viewsCount')),
  79. }