played.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import time
  5. import os.path
  6. from .common import InfoExtractor
  7. from ..utils import (
  8. compat_urllib_parse,
  9. compat_urllib_request,
  10. )
  11. class PlayedIE(InfoExtractor):
  12. IE_NAME = 'played.to'
  13. _VALID_URL = r'https?://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. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. orig_webpage = self._download_webpage(url, video_id)
  27. fields = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)">', orig_webpage)
  28. data = dict(fields)
  29. self.to_screen('%s: Waiting for timeout' % video_id)
  30. time.sleep(2)
  31. post = compat_urllib_parse.urlencode(data)
  32. headers = {
  33. b'Content-Type': b'application/x-www-form-urlencoded',
  34. }
  35. req = compat_urllib_request.Request(url, post, headers)
  36. webpage = self._download_webpage(
  37. req, video_id, note='Downloading video page ...')
  38. title = os.path.splitext(data['fname'])[0]
  39. video_url = self._search_regex(
  40. r'file: "?(.+?)",', webpage, 'video URL')
  41. return {
  42. 'id': video_id,
  43. 'title': title,
  44. 'url': video_url,
  45. }