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.

62 lines
1.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import os.path
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. ExtractorError,
  8. compat_urllib_parse,
  9. compat_urllib_request,
  10. )
  11. class PlayedIE(InfoExtractor):
  12. IE_NAME = 'played.to'
  13. _VALID_URL = r'https?://(?:www\.)?played\.to/(?P<id>[a-zA-Z0-9_-]+)'
  14. _TEST = {
  15. 'url': 'http://played.to/j2f2sfiiukgt',
  16. 'md5': 'c2bd75a368e82980e7257bf500c00637',
  17. 'info_dict': {
  18. 'id': 'j2f2sfiiukgt',
  19. 'ext': 'flv',
  20. 'title': 'youtube-dl_test_video.mp4',
  21. },
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. orig_webpage = self._download_webpage(url, video_id)
  26. m_error = re.search(
  27. r'(?s)Reason for deletion:.*?<b class="err"[^>]*>(?P<msg>[^<]+)</b>', orig_webpage)
  28. if m_error:
  29. raise ExtractorError(m_error.group('msg'), expected=True)
  30. fields = re.findall(
  31. r'type="hidden" name="([^"]+)"\s+value="([^"]+)">', orig_webpage)
  32. data = dict(fields)
  33. self._sleep(2, video_id)
  34. post = compat_urllib_parse.urlencode(data)
  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='Downloading video page ...')
  41. title = os.path.splitext(data['fname'])[0]
  42. video_url = self._search_regex(
  43. r'file: "?(.+?)",', webpage, 'video URL')
  44. return {
  45. 'id': video_id,
  46. 'title': title,
  47. 'url': video_url,
  48. }