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.

108 lines
3.3 KiB

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