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.

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