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.

97 lines
2.8 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_HTTPError,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. HEADRequest,
  12. remove_end,
  13. )
  14. class CloudyIE(InfoExtractor):
  15. _IE_DESC = 'cloudy.ec'
  16. _VALID_URL = r'''(?x)
  17. https?://(?:www\.)?cloudy\.ec/
  18. (?:v/|embed\.php\?id=)
  19. (?P<id>[A-Za-z0-9]+)
  20. '''
  21. _EMBED_URL = 'http://www.cloudy.ec/embed.php?id=%s'
  22. _API_URL = 'http://www.cloudy.ec/api/player.api.php'
  23. _MAX_TRIES = 2
  24. _TEST = {
  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. def _extract_video(self, video_id, file_key, error_url=None, try_num=0):
  34. if try_num > self._MAX_TRIES - 1:
  35. raise ExtractorError('Unable to extract video URL', expected=True)
  36. form = {
  37. 'file': video_id,
  38. 'key': file_key,
  39. }
  40. if error_url:
  41. form.update({
  42. 'numOfErrors': try_num,
  43. 'errorCode': '404',
  44. 'errorUrl': error_url,
  45. })
  46. player_data = self._download_webpage(
  47. self._API_URL, video_id, 'Downloading player data', query=form)
  48. data = compat_parse_qs(player_data)
  49. try_num += 1
  50. if 'error' in data:
  51. raise ExtractorError(
  52. '%s error: %s' % (self.IE_NAME, ' '.join(data['error_msg'])),
  53. expected=True)
  54. title = data.get('title', [None])[0]
  55. if title:
  56. title = remove_end(title, '&asdasdas').strip()
  57. video_url = data.get('url', [None])[0]
  58. if video_url:
  59. try:
  60. self._request_webpage(HEADRequest(video_url), video_id, 'Checking video URL')
  61. except ExtractorError as e:
  62. if isinstance(e.cause, compat_HTTPError) and e.cause.code in [404, 410]:
  63. self.report_warning('Invalid video URL, requesting another', video_id)
  64. return self._extract_video(video_id, file_key, video_url, try_num)
  65. return {
  66. 'id': video_id,
  67. 'url': video_url,
  68. 'title': title,
  69. }
  70. def _real_extract(self, url):
  71. mobj = re.match(self._VALID_URL, url)
  72. video_id = mobj.group('id')
  73. url = self._EMBED_URL % video_id
  74. webpage = self._download_webpage(url, video_id)
  75. file_key = self._search_regex(
  76. [r'key\s*:\s*"([^"]+)"', r'filekey\s*=\s*"([^"]+)"'],
  77. webpage, 'file_key')
  78. return self._extract_video(video_id, file_key)