1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-12-02 05:07:55 +01:00
youtube-dl/youtube_dl/extractor/changba.py

79 lines
2.4 KiB
Python
Raw Normal View History

# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import int_or_none
class ChangbaIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?changba\.com/s/(?P<id>[0-9A-Za-z-_]+)'
2019-04-15 22:38:29 +02:00
_TESTS = [{
'url': 'https://changba.com/s/0GHVw6vyXv9N2FhaFi2WJg',
2019-04-15 22:38:29 +02:00
'md5': 'ea55d17e939f3e2dabf483e47e8e5693',
'info_dict': {
'id': '1152860688',
'ext': 'mp4',
2019-04-15 22:38:29 +02:00
'title': '对你爱不完【炫酷慢摇】 ',
}
}, {
2019-04-15 22:38:29 +02:00
'url': 'http://changba.com/s/nZqfbS_vCnieNNjJ7UiEGw?',
'md5': 'e401463ffb03ed8900a0bccc641335e1',
'info_dict': {
'id': '1091968526',
'ext': 'mp3',
'title': '下雪 ',
}
}, {
2019-04-15 23:21:51 +02:00
'url': 'http://changba.com/s/CPiNWbAa1qy0po0llqIJbg',
'md5': '7adcc9afb85ace8ff854bdd0e8567f50',
2019-04-15 23:21:51 +02:00
'info_dict': {
'id': '136918054',
'ext': 'mp3',
'title': '红豆 ',
}
}, {
2019-04-15 23:21:51 +02:00
'url': 'http://changba.com/s/-N00JJ30YruunrER5eBcWw',
'md5': 'cd68f8da8d8c69afbb8e4dbbbfa8b277',
'info_dict': {
'id': '172671761',
'ext': 'mp3',
'title': '天与地 ',
}
2019-04-15 22:38:29 +02:00
}]
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
id = self._search_regex(r'workid=([0-9]+)', webpage, 'id')
title = self._search_regex(
r'<div[^>]+class="title"[^>]*>([^<]+)', webpage, 'title'
)
isvideo = self._search_regex(r'&isvideo=([0-9])', webpage, 'isvideo')
ext = 'mp3' if int_or_none(isvideo) == 0 else 'mp4'
SITE_SUBDOMAINS = [
'lzscuw',
'upscuw',
'aliuwmp3',
'upuwmp3',
'qiniuuwmp3'
]
2019-04-15 23:02:55 +02:00
try:
src_url = self._search_regex(r'var a="([^"]*)', webpage, 'url')
2019-04-15 23:02:55 +02:00
except:
for subdomain in SITE_SUBDOMAINS:
try:
src_url = 'http://{}.changba.com/{}.{}'.format(
subdomain, str(id), ext
)
except:
continue
return {
'url': src_url,
'id': id,
'ext': ext,
'title': title,
}