mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-11-04 00:25:15 +00:00 
			
		
		
		
	[roosterteeth] Improve (Closes #9864)
This commit is contained in:
		@@ -1,9 +1,14 @@
 | 
				
			|||||||
# coding: utf-8
 | 
					# coding: utf-8
 | 
				
			||||||
from __future__ import unicode_literals
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .common import InfoExtractor
 | 
					from .common import InfoExtractor
 | 
				
			||||||
from ..utils import (
 | 
					from ..utils import (
 | 
				
			||||||
    ExtractorError,
 | 
					    ExtractorError,
 | 
				
			||||||
 | 
					    int_or_none,
 | 
				
			||||||
 | 
					    strip_or_none,
 | 
				
			||||||
 | 
					    unescapeHTML,
 | 
				
			||||||
    urlencode_postdata,
 | 
					    urlencode_postdata,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -14,19 +19,17 @@ class RoosterTeethIE(InfoExtractor):
 | 
				
			|||||||
    _NETRC_MACHINE = 'roosterteeth'
 | 
					    _NETRC_MACHINE = 'roosterteeth'
 | 
				
			||||||
    _TESTS = [{
 | 
					    _TESTS = [{
 | 
				
			||||||
        'url': 'http://roosterteeth.com/episode/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
 | 
					        'url': 'http://roosterteeth.com/episode/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
 | 
				
			||||||
 | 
					        'md5': 'e2bd7764732d785ef797700a2489f212',
 | 
				
			||||||
        'info_dict': {
 | 
					        'info_dict': {
 | 
				
			||||||
            'id': '26576',
 | 
					            'id': '26576',
 | 
				
			||||||
 | 
					            'display_id': 'million-dollars-but-season-2-million-dollars-but-the-game-announcement',
 | 
				
			||||||
            'ext': 'mp4',
 | 
					            'ext': 'mp4',
 | 
				
			||||||
            'title': 'Million Dollars, But... The Game Announcement',
 | 
					            'title': 'Million Dollars, But...: Million Dollars, But... The Game Announcement',
 | 
				
			||||||
 | 
					            'description': 'md5:0cc3b21986d54ed815f5faeccd9a9ca5',
 | 
				
			||||||
            'thumbnail': 're:^https?://.*\.png$',
 | 
					            'thumbnail': 're:^https?://.*\.png$',
 | 
				
			||||||
            'description': 'Introducing Million Dollars, But... The Game! Available for pre-order now at www.MDBGame.com ',
 | 
					 | 
				
			||||||
            'creator': 'Rooster Teeth',
 | 
					 | 
				
			||||||
            'series': 'Million Dollars, But...',
 | 
					            'series': 'Million Dollars, But...',
 | 
				
			||||||
            'episode': 'Million Dollars, But... The Game Announcement',
 | 
					            'episode': 'Million Dollars, But... The Game Announcement',
 | 
				
			||||||
            'episode_id': '26576',
 | 
					            'comment_count': int,
 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        'params': {
 | 
					 | 
				
			||||||
            'skip_download': True,  # m3u8 downloads
 | 
					 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    }, {
 | 
					    }, {
 | 
				
			||||||
        'url': 'http://achievementhunter.roosterteeth.com/episode/off-topic-the-achievement-hunter-podcast-2016-i-didn-t-think-it-would-pass-31',
 | 
					        'url': 'http://achievementhunter.roosterteeth.com/episode/off-topic-the-achievement-hunter-podcast-2016-i-didn-t-think-it-would-pass-31',
 | 
				
			||||||
@@ -40,73 +43,106 @@ class RoosterTeethIE(InfoExtractor):
 | 
				
			|||||||
    }, {
 | 
					    }, {
 | 
				
			||||||
        'url': 'http://theknow.roosterteeth.com/episode/the-know-game-news-season-1-boring-steam-sales-are-better',
 | 
					        'url': 'http://theknow.roosterteeth.com/episode/the-know-game-news-season-1-boring-steam-sales-are-better',
 | 
				
			||||||
        'only_matching': True,
 | 
					        'only_matching': True,
 | 
				
			||||||
 | 
					    }, {
 | 
				
			||||||
 | 
					        # 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,
 | 
				
			||||||
    }]
 | 
					    }]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _login(self):
 | 
					    def _login(self):
 | 
				
			||||||
        (username, password) = self._get_login_info()
 | 
					        (username, password) = self._get_login_info()
 | 
				
			||||||
        if username is None or password is None:
 | 
					        if username is None:
 | 
				
			||||||
            return False
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # token is required to authenticate request
 | 
					        login_page = self._download_webpage(
 | 
				
			||||||
        login_page = self._download_webpage(self._LOGIN_URL, None, 'Getting login token', 'Unable to get login token')
 | 
					            self._LOGIN_URL, None,
 | 
				
			||||||
 | 
					            note='Downloading login page',
 | 
				
			||||||
 | 
					            errnote='Unable to download login page')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        login_form = self._hidden_inputs(login_page)
 | 
					        login_form = self._hidden_inputs(login_page)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        login_form.update({
 | 
					        login_form.update({
 | 
				
			||||||
            'username': username,
 | 
					            'username': username,
 | 
				
			||||||
            'password': password,
 | 
					            'password': password,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        login_payload = urlencode_postdata(login_form)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # required for proper responses
 | 
					 | 
				
			||||||
        login_headers = {
 | 
					 | 
				
			||||||
            'Referer': self._LOGIN_URL,
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        login_request = self._download_webpage(
 | 
					        login_request = self._download_webpage(
 | 
				
			||||||
            self._LOGIN_URL, None,
 | 
					            self._LOGIN_URL, None,
 | 
				
			||||||
            note='Logging in as %s' % username,
 | 
					            note='Logging in as %s' % username,
 | 
				
			||||||
            data=login_payload,
 | 
					            data=urlencode_postdata(login_form),
 | 
				
			||||||
            headers=login_headers)
 | 
					            headers={
 | 
				
			||||||
 | 
					                'Referer': self._LOGIN_URL,
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if 'Authentication failed' in login_request:
 | 
					        if not any(re.search(p, login_request) for p in (
 | 
				
			||||||
            raise ExtractorError(
 | 
					                r'href=["\']https?://(?:www\.)?roosterteeth\.com/logout"',
 | 
				
			||||||
                'Login failed (invalid username/password)', expected=True)
 | 
					                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')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _real_initialize(self):
 | 
					    def _real_initialize(self):
 | 
				
			||||||
        self._login()
 | 
					        self._login()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _real_extract(self, url):
 | 
					    def _real_extract(self, url):
 | 
				
			||||||
        match_id = self._match_id(url)
 | 
					        display_id = self._match_id(url)
 | 
				
			||||||
        webpage = self._download_webpage(url, match_id)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        episode_id = self._html_search_regex(r"commentControls\('#comment-([0-9]+)'\)", webpage, 'episode id', match_id, False)
 | 
					        webpage = self._download_webpage(url, display_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.report_extraction(episode_id)
 | 
					        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')))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        title = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'episode title', self._og_search_title(webpage), False)
 | 
					        title = strip_or_none(self._og_search_title(
 | 
				
			||||||
        thumbnail = self._og_search_thumbnail(webpage)
 | 
					            webpage, default=None)) or episode
 | 
				
			||||||
        description = self._og_search_description(webpage)
 | 
					 | 
				
			||||||
        creator = self._html_search_regex(r'<h3>Latest (.+) Gear</h3>', webpage, 'site', 'Rooster Teeth', False)
 | 
					 | 
				
			||||||
        series = self._html_search_regex(r'<h2>More ([^<]+)</h2>', webpage, 'series', fatal=False)
 | 
					 | 
				
			||||||
        episode = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'episode title', fatal=False)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if '<div class="non-sponsor">' in webpage:
 | 
					        m3u8_url = self._search_regex(
 | 
				
			||||||
            self.raise_login_required('%s is only available for FIRST members' % title)
 | 
					            r'file\s*:\s*(["\'])(?P<url>http.+?\.m3u8.*?)\1',
 | 
				
			||||||
 | 
					            webpage, 'm3u8 url', default=None, group='url')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if '<div class="golive-gate">' in webpage:
 | 
					        if not m3u8_url:
 | 
				
			||||||
            self.raise_login_required('%s is not available yet' % title)
 | 
					            if re.search(r'<div[^>]+class=["\']non-sponsor', webpage):
 | 
				
			||||||
 | 
					                self.raise_login_required(
 | 
				
			||||||
 | 
					                    '%s is only available for FIRST members' % display_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        formats = self._extract_m3u8_formats(self._html_search_regex(r"file: '(.+?)m3u8'", webpage, 'm3u8 url') + 'm3u8', episode_id, ext='mp4')
 | 
					            if re.search(r'<div[^>]+class=["\']golive-gate', webpage):
 | 
				
			||||||
 | 
					                self.raise_login_required('%s is not available yet' % display_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            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')
 | 
				
			||||||
        self._sort_formats(formats)
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            'id': episode_id,
 | 
					            'id': video_id,
 | 
				
			||||||
 | 
					            'display_id': display_id,
 | 
				
			||||||
            'title': title,
 | 
					            'title': title,
 | 
				
			||||||
            'formats': formats,
 | 
					 | 
				
			||||||
            'thumbnail': thumbnail,
 | 
					 | 
				
			||||||
            'description': description,
 | 
					            'description': description,
 | 
				
			||||||
            'creator': creator,
 | 
					            'thumbnail': thumbnail,
 | 
				
			||||||
            'series': series,
 | 
					            'series': series,
 | 
				
			||||||
            'episode': episode,
 | 
					            'episode': episode,
 | 
				
			||||||
            'episode_id': episode_id,
 | 
					            'comment_count': comment_count,
 | 
				
			||||||
 | 
					            'formats': formats,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user