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.

64 lines
1.8 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. 'skip': 'Removed for copyright infringement.', # oh wow
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. orig_webpage = self._download_webpage(url, video_id)
  29. m_error = re.search(
  30. r'(?s)Reason for deletion:.*?<b class="err"[^>]*>(?P<msg>[^<]+)</b>', orig_webpage)
  31. if m_error:
  32. raise ExtractorError(m_error.group('msg'), expected=True)
  33. fields = re.findall(
  34. r'type="hidden" name="([^"]+)"\s+value="([^"]+)">', orig_webpage)
  35. data = dict(fields)
  36. self._sleep(2, video_id)
  37. post = compat_urllib_parse.urlencode(data)
  38. headers = {
  39. b'Content-Type': b'application/x-www-form-urlencoded',
  40. }
  41. req = compat_urllib_request.Request(url, post, headers)
  42. webpage = self._download_webpage(
  43. req, video_id, note='Downloading video page ...')
  44. title = os.path.splitext(data['fname'])[0]
  45. video_url = self._search_regex(
  46. r'file: "?(.+?)",', webpage, 'video URL')
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'url': video_url,
  51. }