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.

91 lines
2.9 KiB

  1. import re
  2. from ..utils import (
  3. unified_strdate,
  4. )
  5. from .subtitles import SubtitlesInfoExtractor
  6. class VikiIE(SubtitlesInfoExtractor):
  7. IE_NAME = u'viki'
  8. _VALID_URL = r'^https?://(?:www\.)?viki\.com/videos/(?P<id>[0-9]+v)'
  9. _TEST = {
  10. u'url': u'http://www.viki.com/videos/1023585v-heirs-episode-14',
  11. u'file': u'1023585v.mp4',
  12. u'md5': u'a21454021c2646f5433514177e2caa5f',
  13. u'info_dict': {
  14. u'title': u'Heirs Episode 14',
  15. u'uploader': u'SBS',
  16. u'description': u'md5:c4b17b9626dd4b143dcc4d855ba3474e',
  17. u'upload_date': u'20131121',
  18. u'age_limit': 13,
  19. }
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. video_id = mobj.group(1)
  24. webpage = self._download_webpage(url, video_id)
  25. title = self._og_search_title(webpage)
  26. description = self._og_search_description(webpage)
  27. thumbnail = self._og_search_thumbnail(webpage)
  28. uploader = self._html_search_regex(
  29. r'<strong>Broadcast Network: </strong>\s*([^<]*)<', webpage,
  30. u'uploader')
  31. if uploader is not None:
  32. uploader = uploader.strip()
  33. rating_str = self._html_search_regex(
  34. r'<strong>Rating: </strong>\s*([^<]*)<', webpage,
  35. u'rating information', default='').strip()
  36. RATINGS = {
  37. 'G': 0,
  38. 'PG': 10,
  39. 'PG-13': 13,
  40. 'R': 16,
  41. 'NC': 18,
  42. }
  43. age_limit = RATINGS.get(rating_str)
  44. info_url = 'http://www.viki.com/player5_fragment/%s?action=show&controller=videos' % video_id
  45. info_webpage = self._download_webpage(info_url, video_id)
  46. video_url = self._html_search_regex(
  47. r'<source[^>]+src="([^"]+)"', info_webpage, u'video URL')
  48. upload_date_str = self._html_search_regex(
  49. r'"created_at":"([^"]+)"', info_webpage, u'upload date')
  50. upload_date = (
  51. unified_strdate(upload_date_str)
  52. if upload_date_str is not None
  53. else None
  54. )
  55. # subtitles
  56. video_subtitles = self.extract_subtitles(video_id, info_webpage)
  57. if self._downloader.params.get('listsubtitles', False):
  58. self._list_available_subtitles(video_id, info_webpage)
  59. return
  60. return {
  61. 'id': video_id,
  62. 'title': title,
  63. 'url': video_url,
  64. 'description': description,
  65. 'thumbnail': thumbnail,
  66. 'age_limit': age_limit,
  67. 'uploader': uploader,
  68. 'subtitles': video_subtitles,
  69. 'upload_date': upload_date,
  70. }
  71. def _get_available_subtitles(self, video_id, info_webpage):
  72. res = {}
  73. for sturl in re.findall(r'<track src="([^"]+)"/>'):
  74. m = re.search(r'/(?P<lang>[a-z]+)\.vtt', sturl)
  75. if not m:
  76. continue
  77. res[m.group('lang')] = sturl
  78. return res