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.

69 lines
2.0 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. )
  8. from ..utils import ExtractorError
  9. class PrimeShareTVIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?primeshare\.tv/download/(?P<id>[\da-zA-Z]+)'
  11. _TEST = {
  12. 'url': 'http://primeshare.tv/download/238790B611',
  13. 'md5': 'b92d9bf5461137c36228009f31533fbc',
  14. 'info_dict': {
  15. 'id': '238790B611',
  16. 'ext': 'mp4',
  17. 'title': 'Public Domain - 1960s Commercial - Crest Toothpaste-YKsuFona',
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. webpage = self._download_webpage(url, video_id)
  23. if '>File not exist<' in webpage:
  24. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  25. fields = dict(re.findall(r'''(?x)<input\s+
  26. type="hidden"\s+
  27. name="([^"]+)"\s+
  28. (?:id="[^"]+"\s+)?
  29. value="([^"]*)"
  30. ''', webpage))
  31. headers = {
  32. 'Referer': url,
  33. 'Content-Type': 'application/x-www-form-urlencoded',
  34. }
  35. wait_time = int(self._search_regex(
  36. r'var\s+cWaitTime\s*=\s*(\d+)',
  37. webpage, 'wait time', default=7)) + 1
  38. self._sleep(wait_time, video_id)
  39. req = compat_urllib_request.Request(
  40. url, compat_urllib_parse.urlencode(fields), headers)
  41. video_page = self._download_webpage(
  42. req, video_id, 'Downloading video page')
  43. video_url = self._search_regex(
  44. r"url\s*:\s*'([^']+\.primeshare\.tv(?::443)?/file/[^']+)'",
  45. video_page, 'video url')
  46. title = self._html_search_regex(
  47. r'<h1>Watch\s*(?:&nbsp;)?\s*\((.+?)(?:\s*\[\.\.\.\])?\)\s*(?:&nbsp;)?\s*<strong>',
  48. video_page, 'title')
  49. return {
  50. 'id': video_id,
  51. 'url': video_url,
  52. 'title': title,
  53. 'ext': 'mp4',
  54. }