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.

94 lines
3.2 KiB

10 years ago
9 years ago
9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. parse_duration,
  9. remove_end,
  10. )
  11. class LRTIE(InfoExtractor):
  12. IE_NAME = 'lrt.lt'
  13. _VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/irasas/(?P<id>[0-9]+)'
  14. _TESTS = [{
  15. # m3u8 download
  16. 'url': 'http://www.lrt.lt/mediateka/irasas/54391/',
  17. 'md5': 'fe44cf7e4ab3198055f2c598fc175cb0',
  18. 'info_dict': {
  19. 'id': '54391',
  20. 'ext': 'mp4',
  21. 'title': 'Septynios Kauno dienos',
  22. 'description': 'md5:24d84534c7dc76581e59f5689462411a',
  23. 'duration': 1783,
  24. 'view_count': int,
  25. 'like_count': int,
  26. },
  27. }, {
  28. # direct mp3 download
  29. 'url': 'http://www.lrt.lt/mediateka/irasas/1013074524/',
  30. 'md5': '389da8ca3cad0f51d12bed0c844f6a0a',
  31. 'info_dict': {
  32. 'id': '1013074524',
  33. 'ext': 'mp3',
  34. 'title': 'Kita tema 2016-09-05 15:05',
  35. 'description': 'md5:1b295a8fc7219ed0d543fc228c931fb5',
  36. 'duration': 3008,
  37. 'view_count': int,
  38. 'like_count': int,
  39. },
  40. }]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(url, video_id)
  44. title = remove_end(self._og_search_title(webpage), ' - LRT')
  45. formats = []
  46. for _, file_url in re.findall(
  47. r'file\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage):
  48. ext = determine_ext(file_url)
  49. if ext not in ('m3u8', 'mp3'):
  50. continue
  51. # mp3 served as m3u8 produces stuttered media file
  52. if ext == 'm3u8' and '.mp3' in file_url:
  53. continue
  54. if ext == 'm3u8':
  55. formats.extend(self._extract_m3u8_formats(
  56. file_url, video_id, 'mp4', entry_protocol='m3u8_native',
  57. fatal=False))
  58. elif ext == 'mp3':
  59. formats.append({
  60. 'url': file_url,
  61. 'vcodec': 'none',
  62. })
  63. self._sort_formats(formats)
  64. thumbnail = self._og_search_thumbnail(webpage)
  65. description = self._og_search_description(webpage)
  66. duration = parse_duration(self._search_regex(
  67. r'var\s+record_len\s*=\s*(["\'])(?P<duration>[0-9]+:[0-9]+:[0-9]+)\1',
  68. webpage, 'duration', default=None, group='duration'))
  69. view_count = int_or_none(self._html_search_regex(
  70. r'<div[^>]+class=(["\']).*?record-desc-seen.*?\1[^>]*>(?P<count>.+?)</div>',
  71. webpage, 'view count', fatal=False, group='count'))
  72. like_count = int_or_none(self._search_regex(
  73. r'<span[^>]+id=(["\'])flikesCount.*?\1>(?P<count>\d+)<',
  74. webpage, 'like count', fatal=False, group='count'))
  75. return {
  76. 'id': video_id,
  77. 'title': title,
  78. 'formats': formats,
  79. 'thumbnail': thumbnail,
  80. 'description': description,
  81. 'duration': duration,
  82. 'view_count': view_count,
  83. 'like_count': like_count,
  84. }