cloudy.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. )
  11. class CloudyIE(InfoExtractor):
  12. _IE_DESC = 'cloudy.ec and videoraj.ch'
  13. _VALID_URL = r'''(?x)
  14. https?://(?:www\.)?(?P<host>cloudy\.ec|videoraj\.ch)/
  15. (?:v/|embed\.php\?id=)
  16. (?P<id>[A-Za-z0-9]+)
  17. '''
  18. _EMBED_URL = 'http://www.%s/embed.php?id=%s'
  19. _API_URL = 'http://www.%s/api/player.api.php?%s'
  20. _TESTS = [
  21. {
  22. 'url': 'https://www.cloudy.ec/v/af511e2527aac',
  23. 'md5': '5cb253ace826a42f35b4740539bedf07',
  24. 'info_dict': {
  25. 'id': 'af511e2527aac',
  26. 'ext': 'flv',
  27. 'title': 'Funny Cats and Animals Compilation june 2013',
  28. }
  29. },
  30. {
  31. 'url': 'http://www.videoraj.ch/v/47f399fd8bb60',
  32. 'md5': '7d0f8799d91efd4eda26587421c3c3b0',
  33. 'info_dict': {
  34. 'id': '47f399fd8bb60',
  35. 'ext': 'flv',
  36. 'title': 'Burning a New iPhone 5 with Gasoline - Will it Survive?',
  37. }
  38. }
  39. ]
  40. def _real_extract(self, url):
  41. mobj = re.match(self._VALID_URL, url)
  42. video_host = mobj.group('host')
  43. video_id = mobj.group('id')
  44. url = self._EMBED_URL % (video_host, video_id)
  45. webpage = self._download_webpage(url, video_id)
  46. file_key = self._search_regex(
  47. r'filekey\s*=\s*"([^"]+)"', webpage, 'file_key')
  48. data_url = self._API_URL % (video_host, compat_urllib_parse.urlencode({
  49. 'file': video_id,
  50. 'key': file_key,
  51. }))
  52. player_data = self._download_webpage(
  53. data_url, video_id, 'Downloading player data')
  54. data = compat_parse_qs(player_data)
  55. if 'error' in data:
  56. raise ExtractorError(
  57. '%s error: %s' % (self.IE_NAME, ' '.join(data['error_msg'])),
  58. expected=True)
  59. title = data.get('title', [None])[0]
  60. if title:
  61. title = remove_end(title, '&asdasdas').strip()
  62. formats = []
  63. video_url = data.get('url', [None])[0]
  64. if video_url:
  65. formats.append({
  66. 'format_id': 'sd',
  67. 'url': video_url,
  68. })
  69. return {
  70. 'id': video_id,
  71. 'title': title,
  72. 'formats': formats,
  73. }