2 from __future__ import unicode_literals
7 import xml.etree.ElementTree
9 # Soompi uses the same subtitle encryption as crunchyroll
10 from .crunchyroll import CrunchyrollIE
13 class SoompiIE(CrunchyrollIE):
15 _VALID_URL = r'^https?://tv\.soompi\.com/en/watch/(?P<id>[0-9]+)'
17 'url': 'http://tv.soompi.com/en/watch/29235',
21 'title': 'Episode 1096',
22 'description': '2015-05-20'
25 'skip_download': True,
29 def _get_episodes(self, webpage, episode_filter=None):
30 episodes = json.loads(
31 self._search_regex(r'\s+VIDEOS\s+= (\[.+?\]);', webpage, "episodes meta"))
32 return [ep for ep in episodes if episode_filter is None or episode_filter(ep)]
34 def _get_subtitles(self, video_id, show_format_xml):
36 subtitle_info_nodes = show_format_xml.findall('./{default}preload/subtitles/subtitle')
37 subtitle_nodes = show_format_xml.findall('./{default}preload/subtitle')
40 for i in subtitle_info_nodes:
41 sub_langs[i.attrib["id"]] = i.attrib["title"]
43 for s in subtitle_nodes:
44 lang_code = sub_langs.get(s.attrib["id"], None)
48 sub_id = int(s.attrib["id"])
49 iv = base64.b64decode(s.find("iv").text)
50 data = base64.b64decode(s.find("data").text)
51 subtitle = self._decrypt_subtitles(data, iv, sub_id).decode('utf-8')
52 sub_root = xml.etree.ElementTree.fromstring(subtitle)
54 subtitles[lang_code] = [{
55 'ext': 'srt', 'data': self._convert_subtitles_to_srt(sub_root)
57 'ext': 'ass', 'data': self._convert_subtitles_to_ass(sub_root)
61 def _real_extract(self, url):
62 video_id = self._match_id(url)
64 webpage = self._download_webpage(
65 url, video_id, note="Downloading episode page",
66 errnote="Video may not be available for your location")
67 vid_formats = re.findall(r"\?quality=q([0-9]+)", webpage)
69 show_meta = json.loads(
70 self._search_regex(r'\s+var show = (\{.+?\});', webpage, "show meta"))
71 episodes = self._get_episodes(
72 webpage, episode_filter=lambda x: x['id'] == video_id)
74 title = episodes[0]["name"]
75 description = episodes[0]["description"]
76 duration = int(episodes[0]["duration"])
77 slug = show_meta["slug"]
80 show_format_xml = None
81 for vf in vid_formats:
82 show_format_url = "http://tv.soompi.com/en/show/%s/%s-config.xml?mode=hls&quality=q%s" \
83 % (slug, video_id, vf)
84 show_format_xml = self._download_xml(
85 show_format_url, video_id, note="Downloading q%s show xml" % vf)
86 avail_formats = self._extract_m3u8_formats(
87 show_format_xml.find('./{default}preload/stream_info/file').text,
88 video_id, ext="mp4", m3u8_id=vf, preference=int(vf))
89 formats.extend(avail_formats)
90 self._sort_formats(formats)
92 subtitles = self.extract_subtitles(video_id, show_format_xml)
97 'description': description,
100 'subtitles': subtitles
104 class SoompiShowIE(SoompiIE):
105 IE_NAME = 'soompi:show'
106 _VALID_URL = r'^https?://tv\.soompi\.com/en/shows/(?P<id>[0-9a-zA-Z\-_]+)'
108 'url': 'http://tv.soompi.com/en/shows/liar-game',
111 'title': 'Liar Game',
112 'description': 'md5:52c02bce0c1a622a95823591d0589b66',
114 'playlist_count': 14,
117 def _real_extract(self, url):
118 show_id = self._match_id(url)
120 webpage = self._download_webpage(url, show_id, note="Downloading show page")
121 title = self._og_search_title(webpage).replace("SoompiTV | ", "")
122 description = self._og_search_description(webpage)
124 episodes = self._get_episodes(webpage)
127 entries.append(self.url_result(
128 'http://tv.soompi.com/en/watch/%s' % ep['id'], 'Soompi', ep['id']))
130 return self.playlist_result(entries, show_id, title, description)