streamcloud.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. sanitized_Request,
  8. urlencode_postdata,
  9. )
  10. class StreamcloudIE(InfoExtractor):
  11. IE_NAME = 'streamcloud.eu'
  12. _VALID_URL = r'https?://streamcloud\.eu/(?P<id>[a-zA-Z0-9_-]+)(?:/(?P<fname>[^#?]*)\.html)?'
  13. _TESTS = [{
  14. 'url': 'http://streamcloud.eu/skp9j99s4bpz/youtube-dl_test_video_____________-BaW_jenozKc.mp4.html',
  15. 'md5': '6bea4c7fa5daaacc2a946b7146286686',
  16. 'info_dict': {
  17. 'id': 'skp9j99s4bpz',
  18. 'ext': 'mp4',
  19. 'title': 'youtube-dl test video \'/\\ ä ↭',
  20. },
  21. 'skip': 'Only available from the EU'
  22. }, {
  23. 'url': 'http://streamcloud.eu/ua8cmfh1nbe6/NSHIP-148--KUC-NG--H264-.mp4.html',
  24. 'only_matching': True,
  25. }]
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. url = 'http://streamcloud.eu/%s' % video_id
  29. orig_webpage = self._download_webpage(url, video_id)
  30. if '>File Not Found<' in orig_webpage:
  31. raise ExtractorError(
  32. 'Video %s does not exist' % video_id, expected=True)
  33. fields = re.findall(r'''(?x)<input\s+
  34. type="(?:hidden|submit)"\s+
  35. name="([^"]+)"\s+
  36. (?:id="[^"]+"\s+)?
  37. value="([^"]*)"
  38. ''', orig_webpage)
  39. post = urlencode_postdata(fields)
  40. self._sleep(12, video_id)
  41. headers = {
  42. b'Content-Type': b'application/x-www-form-urlencoded',
  43. }
  44. req = sanitized_Request(url, post, headers)
  45. webpage = self._download_webpage(
  46. req, video_id, note='Downloading video page ...')
  47. title = self._html_search_regex(
  48. r'<h1[^>]*>([^<]+)<', webpage, 'title')
  49. video_url = self._search_regex(
  50. r'file:\s*"([^"]+)"', webpage, 'video URL')
  51. thumbnail = self._search_regex(
  52. r'image:\s*"([^"]+)"', webpage, 'thumbnail URL', fatal=False)
  53. return {
  54. 'id': video_id,
  55. 'title': title,
  56. 'url': video_url,
  57. 'thumbnail': thumbnail,
  58. }