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.

76 lines
2.6 KiB

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