1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-12-04 22:27:55 +01:00
youtube-dl/youtube_dl/extractor/roosterteeth.py

149 lines
5.5 KiB
Python
Raw Normal View History

2016-06-22 09:58:42 +02:00
# coding: utf-8
from __future__ import unicode_literals
2016-07-09 20:28:28 +02:00
import re
2016-06-22 09:58:42 +02:00
from .common import InfoExtractor
from ..utils import (
ExtractorError,
2016-07-09 20:28:28 +02:00
int_or_none,
strip_or_none,
unescapeHTML,
2016-06-22 09:58:42 +02:00
urlencode_postdata,
)
class RoosterTeethIE(InfoExtractor):
_VALID_URL = r'https?://(?:.+?\.)?roosterteeth\.com/episode/(?P<id>[^/?#&]+)'
_LOGIN_URL = 'https://roosterteeth.com/login'
_NETRC_MACHINE = 'roosterteeth'
_TESTS = [{
'url': 'http://roosterteeth.com/episode/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
2016-07-09 20:28:28 +02:00
'md5': 'e2bd7764732d785ef797700a2489f212',
2016-06-22 09:58:42 +02:00
'info_dict': {
'id': '26576',
2016-07-09 20:28:28 +02:00
'display_id': 'million-dollars-but-season-2-million-dollars-but-the-game-announcement',
2016-06-22 09:58:42 +02:00
'ext': 'mp4',
2016-07-09 20:28:28 +02:00
'title': 'Million Dollars, But...: Million Dollars, But... The Game Announcement',
'description': 'md5:0cc3b21986d54ed815f5faeccd9a9ca5',
'thumbnail': r're:^https?://.*\.png$',
2016-06-22 09:58:42 +02:00
'series': 'Million Dollars, But...',
'episode': 'Million Dollars, But... The Game Announcement',
2016-07-09 20:28:28 +02:00
'comment_count': int,
2016-06-22 09:58:42 +02:00
},
}, {
'url': 'http://achievementhunter.roosterteeth.com/episode/off-topic-the-achievement-hunter-podcast-2016-i-didn-t-think-it-would-pass-31',
'only_matching': True,
}, {
'url': 'http://funhaus.roosterteeth.com/episode/funhaus-shorts-2016-austin-sucks-funhaus-shorts',
'only_matching': True,
}, {
'url': 'http://screwattack.roosterteeth.com/episode/death-battle-season-3-mewtwo-vs-shadow',
'only_matching': True,
}, {
'url': 'http://theknow.roosterteeth.com/episode/the-know-game-news-season-1-boring-steam-sales-are-better',
'only_matching': True,
2016-07-09 20:28:28 +02:00
}, {
# only available for FIRST members
'url': 'http://roosterteeth.com/episode/rt-docs-the-world-s-greatest-head-massage-the-world-s-greatest-head-massage-an-asmr-journey-part-one',
'only_matching': True,
2016-06-22 09:58:42 +02:00
}]
def _login(self):
username, password = self._get_login_info()
2016-07-09 20:28:28 +02:00
if username is None:
return
2016-06-22 09:58:42 +02:00
2016-07-09 20:28:28 +02:00
login_page = self._download_webpage(
self._LOGIN_URL, None,
note='Downloading login page',
errnote='Unable to download login page')
2016-06-22 09:58:42 +02:00
login_form = self._hidden_inputs(login_page)
2016-07-09 20:28:28 +02:00
2016-06-22 09:58:42 +02:00
login_form.update({
'username': username,
'password': password,
})
login_request = self._download_webpage(
self._LOGIN_URL, None,
note='Logging in',
2016-07-09 20:28:28 +02:00
data=urlencode_postdata(login_form),
headers={
'Referer': self._LOGIN_URL,
})
if not any(re.search(p, login_request) for p in (
r'href=["\']https?://(?:www\.)?roosterteeth\.com/logout"',
r'>Sign Out<')):
error = self._html_search_regex(
r'(?s)<div[^>]+class=(["\']).*?\balert-danger\b.*?\1[^>]*>(?:\s*<button[^>]*>.*?</button>)?(?P<error>.+?)</div>',
login_request, 'alert', default=None, group='error')
if error:
raise ExtractorError('Unable to login: %s' % error, expected=True)
raise ExtractorError('Unable to log in')
2016-06-22 09:58:42 +02:00
def _real_initialize(self):
self._login()
def _real_extract(self, url):
2016-07-09 20:28:28 +02:00
display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id)
2016-06-22 09:58:42 +02:00
2016-07-09 20:28:28 +02:00
episode = strip_or_none(unescapeHTML(self._search_regex(
(r'videoTitle\s*=\s*(["\'])(?P<title>(?:(?!\1).)+)\1',
r'<title>(?P<title>[^<]+)</title>'), webpage, 'title',
default=None, group='title')))
2016-06-22 09:58:42 +02:00
2016-07-09 20:28:28 +02:00
title = strip_or_none(self._og_search_title(
webpage, default=None)) or episode
2016-06-22 09:58:42 +02:00
2016-07-09 20:28:28 +02:00
m3u8_url = self._search_regex(
r'file\s*:\s*(["\'])(?P<url>http.+?\.m3u8.*?)\1',
webpage, 'm3u8 url', default=None, group='url')
2016-06-22 09:58:42 +02:00
2016-07-09 20:28:28 +02:00
if not m3u8_url:
if re.search(r'<div[^>]+class=["\']non-sponsor', webpage):
self.raise_login_required(
'%s is only available for FIRST members' % display_id)
2016-06-22 09:58:42 +02:00
2016-07-09 20:28:28 +02:00
if re.search(r'<div[^>]+class=["\']golive-gate', webpage):
self.raise_login_required('%s is not available yet' % display_id)
2016-06-22 09:58:42 +02:00
2016-07-09 20:28:28 +02:00
raise ExtractorError('Unable to extract m3u8 URL')
formats = self._extract_m3u8_formats(
m3u8_url, display_id, ext='mp4',
entry_protocol='m3u8_native', m3u8_id='hls')
2016-06-22 09:58:42 +02:00
self._sort_formats(formats)
2016-07-09 20:28:28 +02:00
description = strip_or_none(self._og_search_description(webpage))
thumbnail = self._proto_relative_url(self._og_search_thumbnail(webpage))
series = self._search_regex(
(r'<h2>More ([^<]+)</h2>', r'<a[^>]+>See All ([^<]+) Videos<'),
webpage, 'series', fatal=False)
comment_count = int_or_none(self._search_regex(
r'>Comments \((\d+)\)<', webpage,
'comment count', fatal=False))
video_id = self._search_regex(
(r'containerId\s*=\s*["\']episode-(\d+)\1',
r'<div[^<]+id=["\']episode-(\d+)'), webpage,
'video id', default=display_id)
2016-06-22 09:58:42 +02:00
return {
2016-07-09 20:28:28 +02:00
'id': video_id,
'display_id': display_id,
2016-06-22 09:58:42 +02:00
'title': title,
'description': description,
2016-07-09 20:28:28 +02:00
'thumbnail': thumbnail,
2016-06-22 09:58:42 +02:00
'series': series,
'episode': episode,
2016-07-09 20:28:28 +02:00
'comment_count': comment_count,
'formats': formats,
2016-06-22 09:58:42 +02:00
}