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