primesharetv.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_filesize,
  7. unified_strdate,
  8. urlencode_postdata,
  9. )
  10. from ..compat import (
  11. compat_urllib_request,
  12. )
  13. class PrimesharetvIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?primeshare\.tv/download/(?P<id>.*)(?:.*)'
  15. _TESTS = [
  16. {
  17. 'url': 'http://primeshare.tv/download/238790B611',
  18. 'md5': 'bb41f9f6c0dd434c729f04ce5b677192',
  19. 'info_dict': {
  20. 'id': '238790B611',
  21. 'ext': 'mp4',
  22. "title": "Public Domain - 1960s Commercial - Crest Toothpaste-YKsuFona [...]",
  23. "duration": 10,
  24. },
  25. }
  26. ]
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. webpage = self._download_webpage(url, video_id)
  30. self._sleep(9, video_id)
  31. hashtoken = self._search_regex(r' name="hash" value="(.*?)" ', webpage, 'hash token')
  32. data = urlencode_postdata({
  33. 'hash': hashtoken,
  34. })
  35. headers = {
  36. 'Referer': url,
  37. 'Content-Type': 'application/x-www-form-urlencoded',
  38. }
  39. video_page_request = compat_urllib_request.Request(url, data, headers=headers)
  40. video_page = self._download_webpage(video_page_request, None, False, '')
  41. video_url = self._html_search_regex(
  42. r'url: \'(http://[a-z0-9]+\.primeshare\.tv:443/file/get/[^\']+)\',', video_page, 'video url')
  43. title = self._html_search_regex(
  44. r'<h1>Watch&nbsp;[^\(]+\(([^/)]+)\)&nbsp;', video_page, 'title')
  45. return {
  46. 'id': video_id,
  47. 'url': video_url,
  48. 'title': title,
  49. 'ext': 'mp4',
  50. }