youtube-dl/youtube_dl/extractor/chirbit.py

92 lines
2.9 KiB
Python
Raw Permalink Normal View History

2015-02-20 09:49:45 +00:00
# coding: utf-8
from __future__ import unicode_literals
2016-10-14 16:01:46 +00:00
import re
2015-02-20 09:49:45 +00:00
from .common import InfoExtractor
from ..compat import compat_b64decode
from ..utils import parse_duration
2015-02-20 09:49:45 +00:00
class ChirbitIE(InfoExtractor):
2015-02-23 15:28:14 +00:00
IE_NAME = 'chirbit'
_VALID_URL = r'https?://(?:www\.)?chirb\.it/(?:(?:wp|pl)/|fb_chirbit_player\.swf\?key=)?(?P<id>[\da-zA-Z]+)'
_TESTS = [{
'url': 'http://chirb.it/be2abG',
2015-02-20 09:49:45 +00:00
'info_dict': {
'id': 'be2abG',
2015-02-20 09:49:45 +00:00
'ext': 'mp3',
'title': 'md5:f542ea253f5255240be4da375c6a5d7e',
'description': 'md5:f24a4e22a71763e32da5fed59e47c770',
'duration': 306,
2017-01-22 19:27:38 +00:00
'uploader': 'Gerryaudio',
},
'params': {
'skip_download': True,
2015-02-20 09:49:45 +00:00
}
}, {
'url': 'https://chirb.it/fb_chirbit_player.swf?key=PrIPv5',
'only_matching': True,
}, {
'url': 'https://chirb.it/wp/MN58c2',
'only_matching': True,
}]
2015-02-20 09:49:45 +00:00
def _real_extract(self, url):
audio_id = self._match_id(url)
webpage = self._download_webpage(
'http://chirb.it/%s' % audio_id, audio_id)
data_fd = self._search_regex(
r'data-fd=(["\'])(?P<url>(?:(?!\1).)+)\1',
webpage, 'data fd', group='url')
# Reverse engineered from https://chirb.it/js/chirbit.player.js (look
# for soundURL)
audio_url = compat_b64decode(data_fd[::-1]).decode('utf-8')
2015-02-20 09:49:45 +00:00
title = self._search_regex(
r'class=["\']chirbit-title["\'][^>]*>([^<]+)', webpage, 'title')
description = self._search_regex(
r'<h3>Description</h3>\s*<pre[^>]*>([^<]+)</pre>',
webpage, 'description', default=None)
duration = parse_duration(self._search_regex(
r'class=["\']c-length["\'][^>]*>([^<]+)',
webpage, 'duration', fatal=False))
2017-01-22 19:27:38 +00:00
uploader = self._search_regex(
r'id=["\']chirbit-username["\'][^>]*>([^<]+)',
webpage, 'uploader', fatal=False)
2015-02-20 09:49:45 +00:00
return {
'id': audio_id,
'url': audio_url,
'title': title,
'description': description,
'duration': duration,
2017-01-22 19:27:38 +00:00
'uploader': uploader,
2015-02-20 09:49:45 +00:00
}
2015-02-20 13:48:12 +00:00
2015-02-20 13:48:12 +00:00
class ChirbitProfileIE(InfoExtractor):
2015-02-23 15:28:14 +00:00
IE_NAME = 'chirbit:profile'
2016-09-08 11:29:05 +00:00
_VALID_URL = r'https?://(?:www\.)?chirbit\.com/(?:rss/)?(?P<id>[^/]+)'
2015-02-20 13:48:12 +00:00
_TEST = {
'url': 'http://chirbit.com/ScarletBeauty',
'info_dict': {
'id': 'ScarletBeauty',
},
'playlist_mincount': 3,
2015-02-20 13:48:12 +00:00
}
def _real_extract(self, url):
profile_id = self._match_id(url)
2016-10-14 16:01:46 +00:00
webpage = self._download_webpage(url, profile_id)
2015-02-20 13:48:12 +00:00
entries = [
2016-10-14 16:01:46 +00:00
self.url_result(self._proto_relative_url('//chirb.it/' + video_id))
for _, video_id in re.findall(r'<input[^>]+id=([\'"])copy-btn-(?P<id>[0-9a-zA-Z]+)\1', webpage)]
2015-02-20 13:48:12 +00:00
2016-10-14 16:01:46 +00:00
return self.playlist_result(entries, profile_id)