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.

66 lines
2.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. merge_dicts,
  7. urljoin,
  8. )
  9. class WakanimIE(InfoExtractor):
  10. _VALID_URL = r'https://(?:www\.)?wakanim\.tv/[^/]+/v2/catalogue/episode/(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'https://www.wakanim.tv/de/v2/catalogue/episode/2997/the-asterisk-war-omu-staffel-1-episode-02-omu',
  13. 'info_dict': {
  14. 'id': '2997',
  15. 'ext': 'mp4',
  16. 'title': 'Episode 02',
  17. 'description': 'md5:2927701ea2f7e901de8bfa8d39b2852d',
  18. 'series': 'The Asterisk War (OmU.)',
  19. 'season_number': 1,
  20. 'episode': 'Episode 02',
  21. 'episode_number': 2,
  22. },
  23. 'params': {
  24. 'format': 'bestvideo',
  25. 'skip_download': True,
  26. },
  27. }, {
  28. # DRM Protected
  29. 'url': 'https://www.wakanim.tv/de/v2/catalogue/episode/7843/sword-art-online-alicization-omu-arc-2-folge-15-omu',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(url, video_id)
  35. m3u8_url = urljoin(url, self._search_regex(
  36. r'file\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, 'm3u8 url',
  37. group='url'))
  38. # https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-content-protection-overview#streaming-urls
  39. encryption = self._search_regex(
  40. r'encryption%3D(c(?:enc|bc(?:s-aapl)?))',
  41. m3u8_url, 'encryption', default=None)
  42. if encryption and encryption in ('cenc', 'cbcs-aapl'):
  43. raise ExtractorError('This video is DRM protected.', expected=True)
  44. formats = self._extract_m3u8_formats(
  45. m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
  46. m3u8_id='hls')
  47. info = self._search_json_ld(webpage, video_id, default={})
  48. title = self._search_regex(
  49. (r'<h1[^>]+\bclass=["\']episode_h1[^>]+\btitle=(["\'])(?P<title>(?:(?!\1).)+)\1',
  50. r'<span[^>]+\bclass=["\']episode_title["\'][^>]*>(?P<title>[^<]+)'),
  51. webpage, 'title', default=None, group='title')
  52. return merge_dicts(info, {
  53. 'id': video_id,
  54. 'title': title,
  55. 'formats': formats,
  56. })