Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Bandai Channel (https://www.b-ch.com) #21404

Closed
5 tasks done
gmarty opened this issue Jun 15, 2019 · 2 comments
Closed
5 tasks done

Support Bandai Channel (https://www.b-ch.com) #21404

gmarty opened this issue Jun 15, 2019 · 2 comments
Labels
site-support-request Add extractor(s) for a new domain

Comments

@gmarty
Copy link

gmarty commented Jun 15, 2019

Checklist

  • I'm reporting a new site support request
  • I've verified that I'm running youtube-dl version 2019.06.08
  • I've checked that all provided URLs are alive and playable in a browser
  • I've checked that none of provided URLs violate any copyrights
  • I've searched the bugtracker for similar site support requests including closed ones

Example URLs

Description

This service is limited to users located in Japan. So you need to circumvent the geolocation safeguard to play the videos.
Otherwise, the HSL manifest files return HTTP error 403 (e.g. https://bchvod-f.akamaihd.net/i/bchvod/live/smils/JP/ttl/CR005/5250/S_5250_001.smil/master.m3u8).

You don't need to be logged in to watch these videos.

Some of the video offered by this service are also available on Gyao!, which is supported by youtube-dl. However, many videos aren't, such as:

@gmarty gmarty added the site-support-request Add extractor(s) for a new domain label Jun 15, 2019
@SeveredFish
Copy link

The readme says you're allowed to 'bump' an issue, so I'd like to mention I'd like b-ch support too

@SeveredFish
Copy link

I've been thinking about this for a two or three days now, there is some key HTML in the source code, this should be the same as the embed code mentioned in brightcove.py extract urls function, (Bandai Channel uses BC for a player/geoblocking)
<video-js id="bcplayer" class="vjs-fluid video-js vjs-controls-enabled vjs-workinghover vjs-v7 vjs-layout-large bc-player-default_default bc-player-default_default-index-0 vjs-mouse vjs-dock vjs-plugins-ready vjs-player-info vjs-errors vjs-quality-menu vjs-has-started vjs-user-active vjs-playing vjs-waiting" preload="metadata" crossorigin="" data-player="default" data-embed="default" data-auth="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTQzMzc4MDAsInN1YiI6IjYwMzhkNzA4ZWIzMTUifQ.Z151sVPrHWwXPJwK_qBwiJONxMEqDMQVukpnu-nkrko " data-info="5250/1" data-mode="ST" tabindex="-1" role="region" aria-label="Video Player" style="outline: currentcolor none medium;" data-video-id="6137630962001" lang="ja"><video tabindex="-1" data-mode="ST" data-info="5250/1" data-auth="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTQzMzc4MDAsInN1YiI6IjYwMzhkNzA4ZWIzMTUifQ.Z151sVPrHWwXPJwK_qBwiJONxMEqDMQVukpnu-nkrko " data-embed="default" data-player="default" crossorigin="" preload="metadata" class="vjs-tech" id="bcplayer_html5_api" aria-labelledby="vjs-dock-title-1" aria-describedby="vjs-dock-description-2" poster="https://cf-images.ap-northeast-1.prod.boltdns.net/v1/static/5797077852001/edc2f883-ce7e-4acc-9664-579c1e004248/57db10b0-a4bc-46c3-9325-0fcc81f404f4/1440x1080/match/image.jpg" src="blob:https://www.b-ch.com/427a1356-d440-4ccc-9ba2-34620446dcff"></video>

Anyway, I worked on a super cargo cult extracter attempt, it uses some source code from brightcove.py, it is of course broken... I hope this inspires someone who knows a bit more about how youtube-dl works and how to rip videos. Either way I'll probably try messing about with some code more though, since the issue hasn't got much momentum :/

# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor
from .common import SearchInfoExtractor
from .brightcove import BrightcoveNewIE

from ..utils import (
    smuggle_url,
    unsmuggle_url,
)

class BchExtractorIE(BrightcoveNewIE):
    _VALID_URL = r'https?://(?:www\.)?b-ch\.com/titles/[0-9]+/[0-9]+'
    _TEST = {
        'url': 'https://www.b-ch.com/titles/5250/001',
        'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)',
        'info_dict': {
            'id': '5250/001',
            'ext': 'mp4',
            'title': '超者ライディーン 第1話(23分)',
            'thumbnail': 'https://cf-images.ap-northeast-1.prod.boltdns.net/v1/static/5797077852001/edc2f883-ce7e-4acc-9664-579c1e004248/57db10b0-a4bc-46c3-9325-0fcc81f404f4/1440x1080/match/image.jpg',
        }
    }
    _TEST = {}

    def _real_extract(self, url):
        url, smuggled_data = unsmuggle_url(url, {'referrer': url})
        self._initialize_geo_bypass({
            'countries': smuggled_data.get('geo_countries'),
            'ip_blocks': smuggled_data.get('geo_ip_blocks'),
        })
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        
        #sourced https://github.com/ytdl-org/youtube-dl/commit/8d14fa13f6be4da656fec62ffbdc1754485fbc03
        headers = {
            'Accept': 'application/json;pk=%s' % policy_key,
        }
        referrer = smuggled_data.get('referrer')
        if referrer:
            headers.update({
                'Referer': referrer,
                'Origin': re.search(r'https?://[^/]+', referrer).group(0),
            })
        
        try:
            json_data = self._download_json(api_url, video_id, headers=headers)
        except ExtractorError as e:
            if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
                json_data = self._parse_json(e.cause.read().decode(), video_id)[0]
            
        brightcove_url = BrightCoveIE._extract_url(webpage)
        if brightcove_url:
            return self.url_result(brightcove_url, ie=BrightCoveIE.ie_key())

        title = self._html_search_regex(r'<h2 class="bch-c-heading-2__ttl">(.+?)</h2>', webpage, 'title')

        thumbnail = self._html_search_regex(r'aria-labelledby="vjs-dock-title-1" aria-describedby="vjs-dock-description-2" poster=(.+?)"', webpage, 'thumbnail')

        return {
            'id': video_id,
            'title': title,
            'description': self._og_search_description(webpage),
            'uploader': self._search_regex(r'<div[^>]+id="uploader"[^>]*>([^<]+)<', webpage, 'uploader', fatal=False),
            'thumbnail': thumbnail,
            # TODO more properties (see youtube_dl/extractor/common.py)
        }     

Here is the console output

USERNAME@LAPTOP-O8UPSKBT MINGW64 ~/Desktop/Youtube-dl-extractor-test (master)
$ python test/test_download.py TestDownload.test_BchExtractor --verbose
test_BchExtractor (__main__.TestDownload): ... [brightcove:new] 4463358922001: Downloading JSON metadata
ERROR: Access to this resource is forbidden by access policy.
Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 632, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 2275, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\brightcove.py", line 644, in _real_extract
    json_data = self._download_json(api_url, video_id, headers=headers)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 893, in _download_json
    res = self._download_json_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 872, in _download_json_handle
    res = self._download_webpage_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\adobepass.py", line 1336, in _download_webpage_handle
    return super(AdobePassIE, self)._download_webpage_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 665, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query, expected_status=expected_status)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 650, in _request_webpage
    raise ExtractorError(errmsg, sys.exc_info()[2], cause=err)
youtube_dl.utils.ExtractorError: Unable to download JSON metadata: HTTP Error 403: Forbidden (caused by <HTTPError 403: 'Forbidden'>); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 632, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 2275, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\brightcove.py", line 644, in _real_extract
    json_data = self._download_json(api_url, video_id, headers=headers)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 893, in _download_json
    res = self._download_json_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 872, in _download_json_handle
    res = self._download_webpage_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\adobepass.py", line 1336, in _download_webpage_handle
    return super(AdobePassIE, self)._download_webpage_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 665, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query, expected_status=expected_status)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 650, in _request_webpage
    raise ExtractorError(errmsg, sys.exc_info()[2], cause=err)
youtube_dl.utils.ExtractorError: Unable to download JSON metadata: HTTP Error 403: Forbidden (caused by <HTTPError 403: 'Forbidden'>); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 806, in wrapper
    return func(self, *args, **kwargs)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 827, in __extract_info
    ie_result = ie.extract(url)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 532, in extract
    ie_result = self._real_extract(url)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\brightcove.py", line 656, in _real_extract
    raise ExtractorError(message, expected=True)
youtube_dl.utils.ExtractorError: Access to this resource is forbidden by access policy.

ERROR

======================================================================
ERROR: test_BchExtractor (__main__.TestDownload):
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 632, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 2275, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\brightcove.py", line 644, in _real_extract
    json_data = self._download_json(api_url, video_id, headers=headers)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 893, in _download_json
    res = self._download_json_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 872, in _download_json_handle
    res = self._download_webpage_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\adobepass.py", line 1336, in _download_webpage_handle
    return super(AdobePassIE, self)._download_webpage_handle(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 665, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query, expected_status=expected_status)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 650, in _request_webpage
    raise ExtractorError(errmsg, sys.exc_info()[2], cause=err)
youtube_dl.utils.ExtractorError: Unable to download JSON metadata: HTTP Error 403: Forbidden (caused by <HTTPError 403: 'Forbidden'>); please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 806, in wrapper
    return func(self, *args, **kwargs)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 827, in __extract_info
    ie_result = ie.extract(url)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\common.py", line 532, in extract
    ie_result = self._real_extract(url)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\extractor\brightcove.py", line 656, in _real_extract
    raise ExtractorError(message, expected=True)
youtube_dl.utils.ExtractorError: Access to this resource is forbidden by access policy.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\test\test_download.py", line 157, in test_template
    res_dict = ydl.extract_info(
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 799, in extract_info
    return self.__extract_info(url, ie, download, extra_info, process)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 815, in wrapper
    self.report_error(compat_str(e), e.format_traceback())
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 628, in report_error
    self.trouble(error_message, tb)
  File "C:\Users\USERNAME\Desktop\Youtube-dl-extractor-test\youtube_dl\YoutubeDL.py", line 598, in trouble
    raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: Access to this resource is forbidden by access policy.

----------------------------------------------------------------------
Ran 1 test in 0.772s

FAILED (errors=1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
site-support-request Add extractor(s) for a new domain
Projects
None yet
Development

No branches or pull requests

2 participants