1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-18 08:16:10 +00:00

fix: refactor two extractors into one

This commit is contained in:
wangchangren 2022-06-18 08:56:44 +08:00
parent 9ff181a1ab
commit 0afddd0b9a
2 changed files with 30 additions and 46 deletions

View file

@ -975,10 +975,7 @@ from .presstv import PressTVIE
from .prosiebensat1 import ProSiebenSat1IE from .prosiebensat1 import ProSiebenSat1IE
from .puls4 import Puls4IE from .puls4 import Puls4IE
from .pyvideo import PyvideoIE from .pyvideo import PyvideoIE
from .qingting import ( from .qingting import QingTingIE
QingTingMobileIE,
QingTingDeskTopIE,
)
from .qqmusic import ( from .qqmusic import (
QQMusicIE, QQMusicIE,
QQMusicSingerIE, QQMusicSingerIE,

View file

@ -1,46 +1,17 @@
# 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 youtube_dl import utils from youtube_dl import utils
class QingTingMobileIE(InfoExtractor):
IE_NAME = 'QingTing'
_VALID_URL = r'(?:https?://)?(?:www\.)?m\.(?:qingting\.fm|qtfm\.cn)/vchannels/\d+/programs/(?P<id>\d+)'
_TEST = {
'url': 'https://m.qingting.fm/vchannels/378005/programs/22257411/',
'md5': '47e6a94f4e621ed832c316fd1888fb3c',
'info_dict': {
'id': '22257411',
'ext': 'mp3',
'title': '用了十年才修改,谁在乎教科书?-睡前消息-蜻蜓FM听头条',
}
}
def _real_extract(self, url): class QingTingIE(InfoExtractor):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
title = self._html_search_regex(r'(?s)<title\b[^>]*>(.*)</title>', webpage, 'title', default=None) or self._og_search_title(webpage)
url = self._search_regex(
r'''("|')audioUrl\1\s*:\s*("|')(?P<url>(?:(?!\2).)*)\2''',
webpage, 'audio URL', group="url")
test_url = utils.url_or_none(url)
if not test_url:
raise utils.ExtractorError('Invalid audio URL %s' % (url,))
url = test_url
return {
'id': video_id,
'title': title,
'ext': 'mp3',
'url': url,
}
class QingTingDeskTopIE(InfoExtractor):
IE_NAME = 'QingTing' IE_NAME = 'QingTing'
_VALID_URL = r'(?:https?://)?(?:www\.)?(?:qingting\.fm|qtfm\.cn)/channels/\d+/programs/(?P<id>\d+)' _VALID_URL = r'''(?x)
(?:https?://)?(?:www\.)?
(?P<m>m\.)?(?:qingting\.fm|qtfm\.cn)/(?(m)v|)
channels/\d+/programs/(?P<id>\d+)'''
_TEST = { _TEST = {
'url': 'https://www.qingting.fm/channels/378005/programs/22257411/', 'url': 'https://www.qingting.fm/channels/378005/programs/22257411/',
'md5': '47e6a94f4e621ed832c316fd1888fb3c', 'md5': '47e6a94f4e621ed832c316fd1888fb3c',
@ -56,11 +27,27 @@ class QingTingDeskTopIE(InfoExtractor):
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
title = self._html_search_regex(r'(?s)<title\b[^>]*>(.*)</title>', webpage, 'title', title = self._html_search_regex(r'(?s)<title\b[^>]*>(.*)</title>', webpage, 'title',
default=None) or self._og_search_title(webpage) default=None) or self._og_search_title(webpage)
url = self._search_regex( urlType = self._search_regex(
r'''("|')alternate\1\s*:\s*("|')(?P<url>(?:(?!\2).)*)\2''', self._VALID_URL,
webpage, 'alternate URL', group="url") url, 'audio URL', group="m")
test_url = utils.url_or_none(url) if urlType == 'm.':
if not test_url: url = self._search_regex(
raise utils.ExtractorError('Invalid audio URL %s' % (url,)) r'''("|')audioUrl\1\s*:\s*("|')(?P<url>(?:(?!\2).)*)\2''',
url = test_url webpage, 'audio URL', group="url")
return self.url_result(url=url, video_id=video_id, video_title=title) test_url = utils.url_or_none(url)
if not test_url:
raise utils.ExtractorError('Invalid audio URL %s' % (url,))
return {
'id': video_id,
'title': title,
'ext': 'mp3',
'url': test_url,
}
else:
url = self._search_regex(
r'''("|')alternate\1\s*:\s*("|')(?P<url>(?:(?!\2).)*)\2''',
webpage, 'alternate URL', group="url")
test_url = utils.url_or_none(url)
if not test_url:
raise utils.ExtractorError('Invalid audio URL %s' % (url,))
return self.url_result(url=test_url, video_id=video_id, video_title=title)