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.

66 lines
2.1 KiB

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