]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bleacherreport.py
Remove upstream's autoupdate mechanism
[youtubedl] / youtube_dl / extractor / bleacherreport.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .amp import AMPIE
6 from ..utils import (
7 ExtractorError,
8 int_or_none,
9 parse_iso8601,
10 )
11
12
13 class BleacherReportIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?bleacherreport\.com/articles/(?P<id>\d+)'
15 _TESTS = [{
16 'url': 'http://bleacherreport.com/articles/2496438-fsu-stat-projections-is-jalen-ramsey-best-defensive-player-in-college-football',
17 'md5': 'a3ffc3dc73afdbc2010f02d98f990f20',
18 'info_dict': {
19 'id': '2496438',
20 'ext': 'mp4',
21 'title': 'FSU Stat Projections: Is Jalen Ramsey Best Defensive Player in College Football?',
22 'uploader_id': 3992341,
23 'description': 'CFB, ACC, Florida State',
24 'timestamp': 1434380212,
25 'upload_date': '20150615',
26 'uploader': 'Team Stream Now ',
27 },
28 'add_ie': ['Ooyala'],
29 }, {
30 'url': 'http://bleacherreport.com/articles/2586817-aussie-golfers-get-fright-of-their-lives-after-being-chased-by-angry-kangaroo',
31 'md5': '6a5cd403418c7b01719248ca97fb0692',
32 'info_dict': {
33 'id': '2586817',
34 'ext': 'webm',
35 'title': 'Aussie Golfers Get Fright of Their Lives After Being Chased by Angry Kangaroo',
36 'timestamp': 1446839961,
37 'uploader': 'Sean Fay',
38 'description': 'md5:b1601e2314c4d8eec23b6eafe086a757',
39 'uploader_id': 6466954,
40 'upload_date': '20151011',
41 },
42 'add_ie': ['Youtube'],
43 }]
44
45 def _real_extract(self, url):
46 article_id = self._match_id(url)
47
48 article_data = self._download_json('http://api.bleacherreport.com/api/v1/articles/%s' % article_id, article_id)['article']
49
50 thumbnails = []
51 primary_photo = article_data.get('primaryPhoto')
52 if primary_photo:
53 thumbnails = [{
54 'url': primary_photo['url'],
55 'width': primary_photo.get('width'),
56 'height': primary_photo.get('height'),
57 }]
58
59 info = {
60 '_type': 'url_transparent',
61 'id': article_id,
62 'title': article_data['title'],
63 'uploader': article_data.get('author', {}).get('name'),
64 'uploader_id': article_data.get('authorId'),
65 'timestamp': parse_iso8601(article_data.get('createdAt')),
66 'thumbnails': thumbnails,
67 'comment_count': int_or_none(article_data.get('commentsCount')),
68 'view_count': int_or_none(article_data.get('hitCount')),
69 }
70
71 video = article_data.get('video')
72 if video:
73 video_type = video['type']
74 if video_type == 'cms.bleacherreport.com':
75 info['url'] = 'http://bleacherreport.com/video_embed?id=%s' % video['id']
76 elif video_type == 'ooyala.com':
77 info['url'] = 'ooyala:%s' % video['id']
78 elif video_type == 'youtube.com':
79 info['url'] = video['id']
80 elif video_type == 'vine.co':
81 info['url'] = 'https://vine.co/v/%s' % video['id']
82 else:
83 info['url'] = video_type + video['id']
84 return info
85 else:
86 raise ExtractorError('no video in the article', expected=True)
87
88
89 class BleacherReportCMSIE(AMPIE):
90 _VALID_URL = r'https?://(?:www\.)?bleacherreport\.com/video_embed\?id=(?P<id>[0-9a-f-]{36})'
91 _TESTS = [{
92 'url': 'http://bleacherreport.com/video_embed?id=8fd44c2f-3dc5-4821-9118-2c825a98c0e1',
93 'md5': '2e4b0a997f9228ffa31fada5c53d1ed1',
94 'info_dict': {
95 'id': '8fd44c2f-3dc5-4821-9118-2c825a98c0e1',
96 'ext': 'flv',
97 'title': 'Cena vs. Rollins Would Expose the Heavyweight Division',
98 'description': 'md5:984afb4ade2f9c0db35f3267ed88b36e',
99 },
100 }]
101
102 def _real_extract(self, url):
103 video_id = self._match_id(url)
104 info = self._extract_feed_info('http://cms.bleacherreport.com/media/items/%s/akamai.json' % video_id)
105 info['id'] = video_id
106 return info