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.

146 lines
5.5 KiB

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