screenwavemedia.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. unified_strdate,
  8. js_to_json,
  9. )
  10. class ScreenwaveMediaIE(InfoExtractor):
  11. _VALID_URL = r'http://player\d?\.screenwavemedia\.com/(?:play/)?[a-zA-Z]+\.php\?[^"]*\bid=(?P<id>.+)'
  12. _TESTS = [{
  13. 'url': 'http://player.screenwavemedia.com/play/play.php?playerdiv=videoarea&companiondiv=squareAd&id=Cinemassacre-19911',
  14. 'only_matching': True,
  15. }]
  16. def _real_extract(self, url):
  17. video_id = self._match_id(url)
  18. playerdata = self._download_webpage(
  19. 'http://player.screenwavemedia.com/player.php?id=%s' % video_id,
  20. video_id, 'Downloading player webpage')
  21. vidtitle = self._search_regex(
  22. r'\'vidtitle\'\s*:\s*"([^"]+)"', playerdata, 'vidtitle').replace('\\/', '/')
  23. playerconfig = self._download_webpage(
  24. 'http://player.screenwavemedia.com/player.js',
  25. video_id, 'Downloading playerconfig webpage')
  26. videoserver = self._search_regex(r'SWMServer\s*=\s*"([\d\.]+)"', playerdata, 'videoserver')
  27. sources = self._parse_json(
  28. js_to_json(
  29. re.sub(
  30. r'(?s)/\*.*?\*/', '',
  31. self._search_regex(
  32. r"sources\s*:\s*(\[[^\]]+?\])", playerconfig,
  33. 'sources',
  34. ).replace(
  35. "' + thisObj.options.videoserver + '",
  36. videoserver
  37. ).replace(
  38. "' + playerVidId + '",
  39. video_id
  40. )
  41. )
  42. ),
  43. video_id, fatal=False
  44. )
  45. # Fallback to hardcoded sources if JS changes again
  46. if not sources:
  47. self.report_warning('Falling back to a hardcoded list of streams')
  48. sources = [{
  49. 'file': 'http://%s/vod/%s_%s.mp4' % (videoserver, video_id, format_id),
  50. 'type': 'mp4',
  51. 'label': format_label,
  52. } for format_id, format_label in (
  53. ('low', '144p Low'), ('med', '160p Med'), ('high', '360p High'), ('hd1', '720p HD1'))]
  54. sources.append({
  55. 'file': 'http://%s/vod/smil:%s.smil/playlist.m3u8' % (videoserver, video_id),
  56. 'type': 'hls',
  57. })
  58. formats = []
  59. for source in sources:
  60. if source['type'] == 'hls':
  61. formats.extend(self._extract_m3u8_formats(source['file'], video_id))
  62. else:
  63. file_ = source.get('file')
  64. if not file_:
  65. continue
  66. format_label = source.get('label')
  67. format_id = self._search_regex(
  68. r'_(.+?)\.[^.]+$', file_, 'format id', default=None)
  69. height = int_or_none(self._search_regex(
  70. r'^(\d+)[pP]', format_label, 'height', default=None))
  71. formats.append({
  72. 'url': source['file'],
  73. 'format_id': format_id,
  74. 'format': format_label,
  75. 'ext': source.get('type'),
  76. 'height': height,
  77. })
  78. self._sort_formats(formats)
  79. return {
  80. 'id': video_id,
  81. 'title': vidtitle,
  82. 'formats': formats,
  83. }
  84. class TeamFourIE(InfoExtractor):
  85. _VALID_URL = r'https?://(?:www\.)?teamfourstar\.com/video/(?P<id>[a-z0-9\-]+)/?'
  86. _TEST = {
  87. 'url': 'http://teamfourstar.com/video/a-moment-with-tfs-episode-4/',
  88. 'info_dict': {
  89. 'id': 'TeamFourStar-5292a02f20bfa',
  90. 'ext': 'mp4',
  91. 'upload_date': '20130401',
  92. 'description': 'Check out this and more on our website: http://teamfourstar.com\nTFS Store: http://sharkrobot.com/team-four-star\nFollow on Twitter: http://twitter.com/teamfourstar\nLike on FB: http://facebook.com/teamfourstar',
  93. 'title': 'A Moment With TFS Episode 4',
  94. }
  95. }
  96. def _real_extract(self, url):
  97. display_id = self._match_id(url)
  98. webpage = self._download_webpage(url, display_id)
  99. playerdata_url = self._search_regex(
  100. r'src="(http://player\d?\.screenwavemedia\.com/(?:play/)?[a-zA-Z]+\.php\?[^"]*\bid=.+?)"',
  101. webpage, 'player data URL')
  102. video_title = self._html_search_regex(
  103. r'<div class="heroheadingtitle">(?P<title>.+?)</div>',
  104. webpage, 'title')
  105. video_date = unified_strdate(self._html_search_regex(
  106. r'<div class="heroheadingdate">(?P<date>.+?)</div>',
  107. webpage, 'date', fatal=False))
  108. video_description = self._html_search_regex(
  109. r'(?s)<div class="postcontent">(?P<description>.+?)</div>',
  110. webpage, 'description', fatal=False)
  111. video_thumbnail = self._og_search_thumbnail(webpage)
  112. return {
  113. '_type': 'url_transparent',
  114. 'display_id': display_id,
  115. 'title': video_title,
  116. 'description': video_description,
  117. 'upload_date': video_date,
  118. 'thumbnail': video_thumbnail,
  119. 'url': playerdata_url,
  120. }