1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2025-01-09 14:47:55 +01:00
youtube-dl/youtube_dl/extractor/changba.py

63 lines
1.8 KiB
Python
Raw Normal View History

# coding: utf-8
from __future__ import unicode_literals
2019-04-19 00:56:15 +02:00
import base64
from .common import InfoExtractor
2019-04-18 23:42:34 +02:00
from ..utils import (
int_or_none,
RegexNotFoundError,
)
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 = [{
2019-04-19 15:54:47 +02:00
'url': 'https://changba.com/s/PBZkNLjjPmuE_nW7EuUNpg?&cbcode=Kxhsv6044ik&from=pcrecommend',
'md5': '88aa70b832c4071cffd7e06d759bc7e8',
'info_dict': {
2019-04-19 15:54:47 +02:00
'id': '1146278955',
'ext': 'mp4',
2019-04-19 15:54:47 +02:00
'title': ' ',
2019-04-19 16:25:04 +02:00
'vcodec': None
}
}, {
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-19 16:25:04 +02:00
'vcodec': 'none'
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'
)
2019-04-19 15:54:47 +02:00
ext = None
2019-04-19 16:25:04 +02:00
vcodec = None
2019-04-15 23:02:55 +02:00
try:
src_url = self._search_regex(r'var a="([^"]*)', webpage, 'url')
2019-04-19 15:54:47 +02:00
ext = 'mp3'
2019-04-19 16:25:04 +02:00
vcodec = 'none'
2019-04-18 23:42:34 +02:00
except RegexNotFoundError:
2019-04-19 00:56:15 +02:00
encoded = self._search_regex(
2019-04-19 15:54:47 +02:00
r'video_url: \'([0-9A-Za-z]+=*)', webpage, 'video url'
2019-04-19 00:56:15 +02:00
)
src_url = base64.b64decode(encoded).decode('utf-8')
2019-04-19 15:54:47 +02:00
ext = 'mp4'
2019-04-19 00:56:15 +02:00
return {
'url': src_url,
'id': id,
'ext': ext,
'title': title,
2019-04-19 16:25:04 +02:00
'vcodec': vcodec
}