[bleacherreport] fix style issues and simplify

This commit is contained in:
remitamine 2015-12-21 11:12:58 +01:00
parent 63b728f06f
commit c7fa5fa42c
4 changed files with 30 additions and 52 deletions

View file

@ -9,23 +9,21 @@ from ..utils import (
class AMPIE(InfoExtractor): class AMPIE(InfoExtractor):
def _get_media_node(self, item, name, default=None):
media_name = 'media-%s' % name
media_group = item.get('media-group') or item
return media_group.get(media_name) or item.get(media_name) or item.get(name, default)
# parse Akamai Adaptive Media Player feed # parse Akamai Adaptive Media Player feed
def _extract_feed_info(self, url): def _extract_feed_info(self, url):
item = self._download_json( item = self._download_json(
url, None, url, None, 'Downloading Akamai AMP feed',
'Downloading Akamai AMP feed', 'Unable to download Akamai AMP feed')['channel']['item']
'Unable to download Akamai AMP feed'
)['channel']['item']
video_id = item['guid'] video_id = item['guid']
def get_media_node(name, default=None):
media_name = 'media-%s' % name
media_group = item.get('media-group') or item
return media_group.get(media_name) or item.get(media_name) or item.get(name, default)
thumbnails = [] thumbnails = []
media_thumbnail = self._get_media_node(item, 'thumbnail') media_thumbnail = get_media_node('thumbnail')
if media_thumbnail: if media_thumbnail:
if isinstance(media_thumbnail, dict): if isinstance(media_thumbnail, dict):
media_thumbnail = [media_thumbnail] media_thumbnail = [media_thumbnail]
@ -38,7 +36,7 @@ class AMPIE(InfoExtractor):
}) })
subtitles = {} subtitles = {}
media_subtitle = self._get_media_node(item, 'subTitle') media_subtitle = get_media_node('subTitle')
if media_subtitle: if media_subtitle:
if isinstance(media_subtitle, dict): if isinstance(media_subtitle, dict):
media_subtitle = [media_subtitle] media_subtitle = [media_subtitle]
@ -48,26 +46,28 @@ class AMPIE(InfoExtractor):
subtitles[lang] = [{'url': subtitle['href']}] subtitles[lang] = [{'url': subtitle['href']}]
formats = [] formats = []
media_content = self._get_media_node(item, 'content') media_content = get_media_node('content')
if isinstance(media_content, dict): if isinstance(media_content, dict):
media_content = [media_content] media_content = [media_content]
for media_data in media_content: for media_data in media_content:
media = media_data['@attributes'] media = media_data['@attributes']
media_type = media['type'] media_type = media['type']
if media_type == 'video/f4m': if media_type == 'video/f4m':
f4m_formats = self._extract_f4m_formats(media['url'] + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124', video_id, f4m_id='hds', fatal=False) f4m_formats = self._extract_f4m_formats(
media['url'] + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124',
video_id, f4m_id='hds', fatal=False)
if f4m_formats: if f4m_formats:
formats.extend(f4m_formats) formats.extend(f4m_formats)
elif media_type == 'application/x-mpegURL': elif media_type == 'application/x-mpegURL':
m3u8_formats = self._extract_m3u8_formats(media['url'], video_id, m3u8_id='hls', fatal=False) m3u8_formats = self._extract_m3u8_formats(
media['url'], video_id, 'mp4', m3u8_id='hls', fatal=False)
if m3u8_formats: if m3u8_formats:
formats.extend(m3u8_formats) formats.extend(m3u8_formats)
else: else:
formats.append({ formats.append({
'format_id': media_data['media-category']['@attributes']['label'], 'format_id': media_data['media-category']['@attributes']['label'],
'url': media['url'], 'url': media['url'],
'preference': 1, 'tbr': int_or_none(media.get('bitrate')),
'vbr': int_or_none(media.get('bitrate')),
'filesize': int_or_none(media.get('fileSize')), 'filesize': int_or_none(media.get('fileSize')),
}) })
@ -75,8 +75,8 @@ class AMPIE(InfoExtractor):
return { return {
'id': video_id, 'id': video_id,
'title': self._get_media_node(item, 'title'), 'title': get_media_node('title'),
'description': self._get_media_node(item, 'description'), 'description': get_media_node('description'),
'thumbnails': thumbnails, 'thumbnails': thumbnails,
'timestamp': parse_iso8601(item.get('pubDate'), ' '), 'timestamp': parse_iso8601(item.get('pubDate'), ' '),
'duration': int_or_none(media_content[0].get('@attributes', {}).get('duration')), 'duration': int_or_none(media_content[0].get('@attributes', {}).get('duration')),

View file

@ -26,7 +26,7 @@ class BleacherReportIE(InfoExtractor):
'uploader': 'Team Stream Now ', 'uploader': 'Team Stream Now ',
}, },
'add_ie': ['Ooyala'], 'add_ie': ['Ooyala'],
},{ }, {
'url': 'http://bleacherreport.com/articles/2586817-aussie-golfers-get-fright-of-their-lives-after-being-chased-by-angry-kangaroo', 'url': 'http://bleacherreport.com/articles/2586817-aussie-golfers-get-fright-of-their-lives-after-being-chased-by-angry-kangaroo',
'md5': 'af5f90dc9c7ba1c19d0a3eac806bbf50', 'md5': 'af5f90dc9c7ba1c19d0a3eac806bbf50',
'info_dict': { 'info_dict': {
@ -35,25 +35,11 @@ class BleacherReportIE(InfoExtractor):
'title': 'Aussie Golfers Get Fright of Their Lives After Being Chased by Angry Kangaroo', 'title': 'Aussie Golfers Get Fright of Their Lives After Being Chased by Angry Kangaroo',
'timestamp': 1446839961, 'timestamp': 1446839961,
'uploader': 'Sean Fay', 'uploader': 'Sean Fay',
'description': 'md5:e95afafa43619816552723878b3b0a84', 'description': 'md5:825e94e0f3521df52fa83b2ed198fa20',
'uploader_id': 6466954, 'uploader_id': 6466954,
'upload_date': '20151011', 'upload_date': '20151011',
}, },
'add_ie': ['Youtube'], 'add_ie': ['Youtube'],
},{
'url': 'http://bleacherreport.com/articles/2496438-fsu-stat-projections-is-jalen-ramsey-best-defensive-player-in-college-football',
'md5': 'a3ffc3dc73afdbc2010f02d98f990f20',
'info_dict': {
'id': '2496438',
'ext': 'mp4',
'title': 'FSU Stat Projections: Is Jalen Ramsey Best Defensive Player in College Football?',
'upload_date': '20150615',
'uploader': 'Team Stream Now ',
'timestamp': 1434380212,
'description': 'CFB, ACC, Florida State',
'uploader_id': 3992341,
},
'add_ie': ['Vine'],
}] }]
def _real_extract(self, url): def _real_extract(self, url):
@ -115,7 +101,6 @@ class BleacherReportCMSIE(AMPIE):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
info = self._extract_feed_info('http://cms.bleacherreport.com/media/items/%s/akamai.json' % video_id) info = self._extract_feed_info('http://cms.bleacherreport.com/media/items/%s/akamai.json' % video_id)
info['id'] = video_id info['id'] = video_id
return info return info

View file

@ -13,9 +13,6 @@ from ..compat import (
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
clean_html, clean_html,
determine_ext,
int_or_none,
parse_iso8601,
) )
@ -91,7 +88,8 @@ class DramaFeverIE(DramaFeverBaseIE):
video_id = self._match_id(url).replace('/', '.') video_id = self._match_id(url).replace('/', '.')
try: try:
info = self._extract_feed_info('http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id) info = self._extract_feed_info(
'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id)
except ExtractorError as e: except ExtractorError as e:
if isinstance(e.cause, compat_HTTPError): if isinstance(e.cause, compat_HTTPError):
raise ExtractorError( raise ExtractorError(

View file

@ -3,10 +3,6 @@ from __future__ import unicode_literals
import re import re
from .amp import AMPIE from .amp import AMPIE
from ..utils import (
parse_iso8601,
int_or_none,
)
class FoxNewsIE(AMPIE): class FoxNewsIE(AMPIE):
@ -22,8 +18,8 @@ class FoxNewsIE(AMPIE):
'title': 'Frozen in Time', 'title': 'Frozen in Time',
'description': '16-year-old girl is size of toddler', 'description': '16-year-old girl is size of toddler',
'duration': 265, 'duration': 265,
#'timestamp': 1304411491, # 'timestamp': 1304411491,
#'upload_date': '20110503', # 'upload_date': '20110503',
'thumbnail': 're:^https?://.*\.jpg$', 'thumbnail': 're:^https?://.*\.jpg$',
}, },
}, },
@ -36,8 +32,8 @@ class FoxNewsIE(AMPIE):
'title': "Rep. Luis Gutierrez on if Obama's immigration plan is legal", 'title': "Rep. Luis Gutierrez on if Obama's immigration plan is legal",
'description': "Congressman discusses president's plan", 'description': "Congressman discusses president's plan",
'duration': 292, 'duration': 292,
#'timestamp': 1417662047, # 'timestamp': 1417662047,
#'upload_date': '20141204', # 'upload_date': '20141204',
'thumbnail': 're:^https?://.*\.jpg$', 'thumbnail': 're:^https?://.*\.jpg$',
}, },
}, },
@ -52,10 +48,9 @@ class FoxNewsIE(AMPIE):
] ]
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) host, video_id = re.match(self._VALID_URL, url).groups()
video_id = mobj.group('id')
host = mobj.group('host')
info = self._extract_feed_info('http://%s/v/feed/video/%s.js?template=fox' % (host, video_id)) info = self._extract_feed_info(
'http://%s/v/feed/video/%s.js?template=fox' % (host, video_id))
info['id'] = video_id info['id'] = video_id
return info return info