]>
Commit | Line | Data |
---|---|---|
d47f46e1 THD |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
e897bd82 | 4 | from ..utils import ExtractorError, clean_html, int_or_none, try_get, unified_strdate |
d47f46e1 THD |
5 | |
6 | ||
7 | class DamtomoBaseIE(InfoExtractor): | |
8 | def _real_extract(self, url): | |
9 | video_id = self._match_id(url) | |
10 | webpage, handle = self._download_webpage_handle(self._WEBPAGE_URL_TMPL % video_id, video_id, encoding='sjis') | |
11 | ||
12 | if handle.url == 'https://www.clubdam.com/sorry/': | |
13 | raise ExtractorError('You are rate-limited. Try again later.', expected=True) | |
14 | if '<h2>予期せぬエラーが発生しました。</h2>' in webpage: | |
15 | raise ExtractorError('There is an error on server-side. Try again later.', expected=True) | |
16 | ||
17 | description = self._search_regex(r'(?m)<div id="public_comment">\s*<p>\s*([^<]*?)\s*</p>', webpage, 'description', default=None) | |
18 | uploader_id = self._search_regex(r'<a href="https://www\.clubdam\.com/app/damtomo/member/info/Profile\.do\?damtomoId=([^"]+)"', webpage, 'uploader_id', default=None) | |
19 | ||
20 | data_dict = { | |
21 | mobj.group('class'): re.sub(r'\s+', ' ', clean_html(mobj.group('value'))) | |
22 | for mobj in re.finditer(r'(?s)<(p|div)\s+class="(?P<class>[^" ]+?)">(?P<value>.+?)</\1>', webpage)} | |
23 | ||
24 | # since videos do not have title, give the name of song instead | |
25 | data_dict['user_name'] = re.sub(r'\s*さん\s*$', '', data_dict['user_name']) | |
26 | title = data_dict.get('song_title') | |
27 | ||
28 | stream_tree = self._download_xml( | |
29 | self._DKML_XML_URL % video_id, video_id, note='Requesting stream information', encoding='sjis', | |
30 | # doing this has no problem since there is no character outside ASCII, | |
31 | # and never likely to happen in the future | |
32 | transform_source=lambda x: re.sub(r'\s*encoding="[^"]+?"', '', x)) | |
33 | m3u8_url = try_get(stream_tree, lambda x: x.find( | |
add96eb9 | 34 | './/d:streamingUrl', {'d': self._DKML_XML_NS}).text.strip(), str) |
d47f46e1 THD |
35 | if not m3u8_url: |
36 | raise ExtractorError('Failed to obtain m3u8 URL') | |
37 | formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4') | |
d47f46e1 THD |
38 | |
39 | return { | |
40 | 'id': video_id, | |
41 | 'title': title, | |
42 | 'uploader_id': uploader_id, | |
43 | 'description': description, | |
44 | 'uploader': data_dict.get('user_name'), | |
45 | 'upload_date': unified_strdate(self._search_regex(r'(\d{4}/\d{2}/\d{2})', data_dict.get('date'), 'upload_date', default=None)), | |
46 | 'view_count': int_or_none(self._search_regex(r'(\d+)', data_dict['audience'], 'view_count', default=None)), | |
47 | 'like_count': int_or_none(self._search_regex(r'(\d+)', data_dict['nice'], 'like_count', default=None)), | |
48 | 'track': title, | |
49 | 'artist': data_dict.get('song_artist'), | |
50 | 'formats': formats, | |
51 | } | |
52 | ||
53 | ||
54 | class DamtomoVideoIE(DamtomoBaseIE): | |
55 | IE_NAME = 'damtomo:video' | |
56 | _VALID_URL = r'https?://(?:www\.)?clubdam\.com/app/damtomo/(?:SP/)?karaokeMovie/StreamingDkm\.do\?karaokeMovieId=(?P<id>\d+)' | |
57 | _WEBPAGE_URL_TMPL = 'https://www.clubdam.com/app/damtomo/karaokeMovie/StreamingDkm.do?karaokeMovieId=%s' | |
58 | _DKML_XML_URL = 'https://www.clubdam.com/app/damtomo/karaokeMovie/GetStreamingDkmUrlXML.do?movieSelectFlg=2&karaokeMovieId=%s' | |
59 | _DKML_XML_NS = 'https://www.clubdam.com/app/damtomo/karaokeMovie/GetStreamingDkmUrlXML' | |
60 | _TESTS = [{ | |
61 | 'url': 'https://www.clubdam.com/app/damtomo/karaokeMovie/StreamingDkm.do?karaokeMovieId=2414316', | |
62 | 'info_dict': { | |
63 | 'id': '2414316', | |
64 | 'title': 'Get Wild', | |
65 | 'uploader': 'Kドロン', | |
66 | 'uploader_id': 'ODk5NTQwMzQ', | |
67 | 'track': 'Get Wild', | |
68 | 'artist': 'TM NETWORK(TMN)', | |
69 | 'upload_date': '20201226', | |
add96eb9 | 70 | }, |
d47f46e1 THD |
71 | }] |
72 | ||
73 | ||
74 | class DamtomoRecordIE(DamtomoBaseIE): | |
75 | IE_NAME = 'damtomo:record' | |
76 | _VALID_URL = r'https?://(?:www\.)?clubdam\.com/app/damtomo/(?:SP/)?karaokePost/StreamingKrk\.do\?karaokeContributeId=(?P<id>\d+)' | |
77 | _WEBPAGE_URL_TMPL = 'https://www.clubdam.com/app/damtomo/karaokePost/StreamingKrk.do?karaokeContributeId=%s' | |
78 | _DKML_XML_URL = 'https://www.clubdam.com/app/damtomo/karaokePost/GetStreamingKrkUrlXML.do?karaokeContributeId=%s' | |
79 | _DKML_XML_NS = 'https://www.clubdam.com/app/damtomo/karaokePost/GetStreamingKrkUrlXML' | |
80 | _TESTS = [{ | |
81 | 'url': 'https://www.clubdam.com/app/damtomo/karaokePost/StreamingKrk.do?karaokeContributeId=27376862', | |
82 | 'info_dict': { | |
83 | 'id': '27376862', | |
84 | 'title': 'イカSUMMER [良音]', | |
d47f46e1 THD |
85 | 'uploader': 'NANA', |
86 | 'uploader_id': 'MzAyMDExNTY', | |
87 | 'upload_date': '20210721', | |
88 | 'view_count': 4, | |
89 | 'like_count': 1, | |
90 | 'track': 'イカSUMMER [良音]', | |
91 | 'artist': 'ORANGE RANGE', | |
add96eb9 | 92 | }, |
d47f46e1 THD |
93 | }, { |
94 | 'url': 'https://www.clubdam.com/app/damtomo/karaokePost/StreamingKrk.do?karaokeContributeId=27489418', | |
95 | 'info_dict': { | |
96 | 'id': '27489418', | |
97 | 'title': '心みだれて〜say it with flowers〜(生音)', | |
98 | 'uploader_id': 'NjI1MjI2MjU', | |
99 | 'description': 'やっぱりキーを下げて正解だった感じ。リベンジ成功ということで。', | |
100 | 'uploader': '箱の「中の人」', | |
101 | 'upload_date': '20210815', | |
102 | 'view_count': 5, | |
103 | 'like_count': 3, | |
104 | 'track': '心みだれて〜say it with flowers〜(生音)', | |
105 | 'artist': '小林明子', | |
add96eb9 | 106 | }, |
d47f46e1 | 107 | }] |