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.

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