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.

111 lines
3.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_parse_qs,
  7. compat_urllib_parse,
  8. compat_HTTPError,
  9. )
  10. from ..utils import (
  11. ExtractorError,
  12. HEADRequest,
  13. remove_end,
  14. )
  15. class CloudyIE(InfoExtractor):
  16. _IE_DESC = 'cloudy.ec and videoraj.ch'
  17. _VALID_URL = r'''(?x)
  18. https?://(?:www\.)?(?P<host>cloudy\.ec|videoraj\.ch)/
  19. (?:v/|embed\.php\?id=)
  20. (?P<id>[A-Za-z0-9]+)
  21. '''
  22. _EMBED_URL = 'http://www.%s/embed.php?id=%s'
  23. _API_URL = 'http://www.%s/api/player.api.php?%s'
  24. _MAX_TRIES = 2
  25. _TESTS = [
  26. {
  27. 'url': 'https://www.cloudy.ec/v/af511e2527aac',
  28. 'md5': '5cb253ace826a42f35b4740539bedf07',
  29. 'info_dict': {
  30. 'id': 'af511e2527aac',
  31. 'ext': 'flv',
  32. 'title': 'Funny Cats and Animals Compilation june 2013',
  33. }
  34. },
  35. {
  36. 'url': 'http://www.videoraj.ch/v/47f399fd8bb60',
  37. 'md5': '7d0f8799d91efd4eda26587421c3c3b0',
  38. 'info_dict': {
  39. 'id': '47f399fd8bb60',
  40. 'ext': 'flv',
  41. 'title': 'Burning a New iPhone 5 with Gasoline - Will it Survive?',
  42. }
  43. }
  44. ]
  45. def _extract_video(self, video_host, video_id, file_key, error_url=None, try_num=0):
  46. if try_num > self._MAX_TRIES - 1:
  47. raise ExtractorError('Unable to extract video URL', expected=True)
  48. form = {
  49. 'file': video_id,
  50. 'key': file_key,
  51. }
  52. if error_url:
  53. form.update({
  54. 'numOfErrors': try_num,
  55. 'errorCode': '404',
  56. 'errorUrl': error_url,
  57. })
  58. data_url = self._API_URL % (video_host, compat_urllib_parse.urlencode(form))
  59. player_data = self._download_webpage(
  60. data_url, video_id, 'Downloading player data')
  61. data = compat_parse_qs(player_data)
  62. try_num += 1
  63. if 'error' in data:
  64. raise ExtractorError(
  65. '%s error: %s' % (self.IE_NAME, ' '.join(data['error_msg'])),
  66. expected=True)
  67. title = data.get('title', [None])[0]
  68. if title:
  69. title = remove_end(title, '&asdasdas').strip()
  70. video_url = data.get('url', [None])[0]
  71. if video_url:
  72. try:
  73. self._request_webpage(HEADRequest(video_url), video_id, 'Checking video URL')
  74. except ExtractorError as e:
  75. if isinstance(e.cause, compat_HTTPError) and e.cause.code in [404, 410]:
  76. self.report_warning('Invalid video URL, requesting another', video_id)
  77. return self._extract_video(video_host, video_id, file_key, video_url, try_num)
  78. return {
  79. 'id': video_id,
  80. 'url': video_url,
  81. 'title': title,
  82. }
  83. def _real_extract(self, url):
  84. mobj = re.match(self._VALID_URL, url)
  85. video_host = mobj.group('host')
  86. video_id = mobj.group('id')
  87. url = self._EMBED_URL % (video_host, video_id)
  88. webpage = self._download_webpage(url, video_id)
  89. file_key = self._search_regex(
  90. [r'key\s*:\s*"([^"]+)"', r'filekey\s*=\s*"([^"]+)"'],
  91. webpage, 'file_key')
  92. return self._extract_video(video_host, video_id, file_key)