添加Yogaglo作为支持的youtube-dl站点

时间:2017-12-05 13:02:54

标签: python youtube-dl

我想为youtube-dl添加Yogaglo支持。

我已按照Github的指导。

并起草了以下内容:

# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor


class YogagloIE(InfoExtractor):
 _SIGNIN_URL = 'https://www.yogaglo.com/login'
 _PASSWORD_URL = 'https://www.yogaglo.com/login/password'
 _USER_URL = 'https://www.yogaglo.com/login/user'
 _ACCOUNT_CREDENTIALS_HINT = 'Use --username and --password options to provide yogaglo.com account credentials.'
_NETRC_MACHINE = 'yogaglo'


def _real_initialize(self):
    self._login()

_VALID_URL = r'https?://(?:www\.)?yogaglo\.com/class/(?P<id>[0-9]+)'
_TEST = {
    'url': 'https://www.yogaglo.com/class/7206',
    'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)',
    'info_dict': {
        'id': '7206',
        'ext': 'mp4',
        'title': 'Have a Great Day!'
        # TODO more properties, either as:
        # * A value
        # * MD5 checksum; start the string with md5:
        # * A regular expression; start the string with re:
        # * Any Python type (for example int or float)
    }
}

def _real_extract(self, url):
    video_id = self._match_id(url)
    webpage = self._download_webpage(url, video_id)
    title = self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title')

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

我已将yogagloIE添加到提取器列表中,当我运行它时,我收到一个错误,即URL不受支持。这实际上是初稿,建议任何关于锄头改进并使其发挥作用的指导。

1 个答案:

答案 0 :(得分:0)

在Python中,缩进很重要,因此请确保正确缩进您的课程。

之后,您必须定义_login方法或将_real_initialize留空。

随着实施,将调用提取器(当然它还没有功能):

$ youtube-dl test:yogaglo
[TestURL] Test URL: https://www.yogaglo.com/class/7206
[Yogaglo] 7206: Downloading webpage
ERROR: Unable to extract title; 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.

您可以使用以下命令拉出此工作状态(可能事先git stash所有内容,并将旧的yogaglo.py文件重命名为其他内容):

git pull https://github.com/phihag/youtube-dl.git yogaglo