streamcloud.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urllib_parse_urlencode
  6. from ..utils import sanitized_Request
  7. class StreamcloudIE(InfoExtractor):
  8. IE_NAME = 'streamcloud.eu'
  9. _VALID_URL = r'https?://streamcloud\.eu/(?P<id>[a-zA-Z0-9_-]+)(?:/(?P<fname>[^#?]*)\.html)?'
  10. _TEST = {
  11. 'url': 'http://streamcloud.eu/skp9j99s4bpz/youtube-dl_test_video_____________-BaW_jenozKc.mp4.html',
  12. 'md5': '6bea4c7fa5daaacc2a946b7146286686',
  13. 'info_dict': {
  14. 'id': 'skp9j99s4bpz',
  15. 'ext': 'mp4',
  16. 'title': 'youtube-dl test video \'/\\ ä ↭',
  17. },
  18. 'skip': 'Only available from the EU'
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. url = 'http://streamcloud.eu/%s' % video_id
  23. orig_webpage = self._download_webpage(url, video_id)
  24. fields = re.findall(r'''(?x)<input\s+
  25. type="(?:hidden|submit)"\s+
  26. name="([^"]+)"\s+
  27. (?:id="[^"]+"\s+)?
  28. value="([^"]*)"
  29. ''', orig_webpage)
  30. post = compat_urllib_parse_urlencode(fields)
  31. self._sleep(12, video_id)
  32. headers = {
  33. b'Content-Type': b'application/x-www-form-urlencoded',
  34. }
  35. req = sanitized_Request(url, post, headers)
  36. webpage = self._download_webpage(
  37. req, video_id, note='Downloading video page ...')
  38. title = self._html_search_regex(
  39. r'<h1[^>]*>([^<]+)<', webpage, 'title')
  40. video_url = self._search_regex(
  41. r'file:\s*"([^"]+)"', webpage, 'video URL')
  42. thumbnail = self._search_regex(
  43. r'image:\s*"([^"]+)"', webpage, 'thumbnail URL', fatal=False)
  44. return {
  45. 'id': video_id,
  46. 'title': title,
  47. 'url': video_url,
  48. 'thumbnail': thumbnail,
  49. }