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.

77 lines
2.7 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. compat_HTTPError,
  5. compat_str,
  6. compat_urllib_parse,
  7. compat_urllib_parse_urlparse,
  8. ExtractorError,
  9. )
  10. class AddAnimeIE(InfoExtractor):
  11. _VALID_URL = r'^http://(?:\w+\.)?add-anime\.net/watch_video.php\?(?:.*?)v=(?P<video_id>[\w_]+)(?:.*)'
  12. IE_NAME = u'AddAnime'
  13. _TEST = {
  14. u'url': u'http://www.add-anime.net/watch_video.php?v=24MR3YO5SAS9',
  15. u'file': u'24MR3YO5SAS9.mp4',
  16. u'md5': u'72954ea10bc979ab5e2eb288b21425a0',
  17. u'info_dict': {
  18. u"description": u"One Piece 606",
  19. u"title": u"One Piece 606"
  20. }
  21. }
  22. def _real_extract(self, url):
  23. try:
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('video_id')
  26. webpage = self._download_webpage(url, video_id)
  27. except ExtractorError as ee:
  28. if not isinstance(ee.cause, compat_HTTPError):
  29. raise
  30. redir_webpage = ee.cause.read().decode('utf-8')
  31. action = self._search_regex(
  32. r'<form id="challenge-form" action="([^"]+)"',
  33. redir_webpage, u'Redirect form')
  34. vc = self._search_regex(
  35. r'<input type="hidden" name="jschl_vc" value="([^"]+)"/>',
  36. redir_webpage, u'redirect vc value')
  37. av = re.search(
  38. r'a\.value = ([0-9]+)[+]([0-9]+)[*]([0-9]+);',
  39. redir_webpage)
  40. if av is None:
  41. raise ExtractorError(u'Cannot find redirect math task')
  42. av_res = int(av.group(1)) + int(av.group(2)) * int(av.group(3))
  43. parsed_url = compat_urllib_parse_urlparse(url)
  44. av_val = av_res + len(parsed_url.netloc)
  45. confirm_url = (
  46. parsed_url.scheme + u'://' + parsed_url.netloc +
  47. action + '?' +
  48. compat_urllib_parse.urlencode({
  49. 'jschl_vc': vc, 'jschl_answer': compat_str(av_val)}))
  50. self._download_webpage(
  51. confirm_url, video_id,
  52. note=u'Confirming after redirect')
  53. webpage = self._download_webpage(url, video_id)
  54. video_url = self._search_regex(r"var (?:hq|normal)_video_file = '(.*?)';",
  55. webpage, u'video file URL')
  56. video_extension = video_url[-3:] # mp4 or flv ?
  57. video_title = self._og_search_title(webpage)
  58. video_description = self._og_search_description(webpage)
  59. return {
  60. '_type': 'video',
  61. 'id': video_id,
  62. 'url': video_url,
  63. 'ext': video_extension,
  64. 'title': video_title,
  65. 'description': video_description
  66. }