You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
10 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_xpath
  6. from ..utils import (
  7. determine_ext,
  8. ExtractorError,
  9. int_or_none,
  10. xpath_text,
  11. )
  12. class AfreecaTVIE(InfoExtractor):
  13. IE_NAME = 'afreecatv'
  14. IE_DESC = 'afreecatv.com'
  15. _VALID_URL = r'''(?x)
  16. https?://
  17. (?:
  18. (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
  19. (?:
  20. /app/(?:index|read_ucc_bbs)\.cgi|
  21. /player/[Pp]layer\.(?:swf|html)
  22. )\?.*?\bnTitleNo=|
  23. vod\.afreecatv\.com/PLAYER/STATION/
  24. )
  25. (?P<id>\d+)
  26. '''
  27. _TESTS = [{
  28. 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
  29. 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
  30. 'info_dict': {
  31. 'id': '36164052',
  32. 'ext': 'mp4',
  33. 'title': '데일리 에이프릴 요정들의 시상식!',
  34. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  35. 'uploader': 'dailyapril',
  36. 'uploader_id': 'dailyapril',
  37. 'upload_date': '20160503',
  38. },
  39. 'skip': 'Video is gone',
  40. }, {
  41. 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
  42. 'info_dict': {
  43. 'id': '36153164',
  44. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
  45. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  46. 'uploader': 'dailyapril',
  47. 'uploader_id': 'dailyapril',
  48. },
  49. 'playlist_count': 2,
  50. 'playlist': [{
  51. 'md5': 'd8b7c174568da61d774ef0203159bf97',
  52. 'info_dict': {
  53. 'id': '36153164_1',
  54. 'ext': 'mp4',
  55. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
  56. 'upload_date': '20160502',
  57. },
  58. }, {
  59. 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
  60. 'info_dict': {
  61. 'id': '36153164_2',
  62. 'ext': 'mp4',
  63. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
  64. 'upload_date': '20160502',
  65. },
  66. }],
  67. 'skip': 'Video is gone',
  68. }, {
  69. 'url': 'http://vod.afreecatv.com/PLAYER/STATION/18650793',
  70. 'info_dict': {
  71. 'id': '18650793',
  72. 'ext': 'mp4',
  73. 'title': '오늘은 다르다! 쏘님의 우월한 위아래~ 댄스리액션!',
  74. 'thumbnail': r're:^https?://.*\.jpg$',
  75. 'uploader': '윈아디',
  76. 'uploader_id': 'badkids',
  77. 'duration': 107,
  78. },
  79. 'params': {
  80. 'skip_download': True,
  81. },
  82. }, {
  83. 'url': 'http://vod.afreecatv.com/PLAYER/STATION/10481652',
  84. 'info_dict': {
  85. 'id': '10481652',
  86. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
  87. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  88. 'uploader': 'dailyapril',
  89. 'uploader_id': 'dailyapril',
  90. 'duration': 6492,
  91. },
  92. 'playlist_count': 2,
  93. 'playlist': [{
  94. 'md5': 'd8b7c174568da61d774ef0203159bf97',
  95. 'info_dict': {
  96. 'id': '20160502_c4c62b9d_174361386_1',
  97. 'ext': 'mp4',
  98. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 1)",
  99. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  100. 'uploader': 'dailyapril',
  101. 'uploader_id': 'dailyapril',
  102. 'upload_date': '20160502',
  103. 'duration': 3601,
  104. },
  105. }, {
  106. 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
  107. 'info_dict': {
  108. 'id': '20160502_39e739bb_174361386_2',
  109. 'ext': 'mp4',
  110. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!' (part 2)",
  111. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  112. 'uploader': 'dailyapril',
  113. 'uploader_id': 'dailyapril',
  114. 'upload_date': '20160502',
  115. 'duration': 2891,
  116. },
  117. }],
  118. 'params': {
  119. 'skip_download': True,
  120. },
  121. }, {
  122. # non standard key
  123. 'url': 'http://vod.afreecatv.com/PLAYER/STATION/20515605',
  124. 'info_dict': {
  125. 'id': '20170411_BE689A0E_190960999_1_2_h',
  126. 'ext': 'mp4',
  127. 'title': '혼자사는여자집',
  128. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  129. 'uploader': '♥이슬이',
  130. 'uploader_id': 'dasl8121',
  131. 'upload_date': '20170411',
  132. 'duration': 213,
  133. },
  134. 'params': {
  135. 'skip_download': True,
  136. },
  137. }, {
  138. # adult video
  139. 'url': 'http://vod.afreecatv.com/PLAYER/STATION/26542731',
  140. 'info_dict': {
  141. 'id': '20171001_F1AE1711_196617479_1',
  142. 'ext': 'mp4',
  143. 'title': '[생]서아 초심 찾기 방송 (part 1)',
  144. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  145. 'uploader': 'BJ서아',
  146. 'uploader_id': 'bjdyrksu',
  147. 'upload_date': '20171001',
  148. 'duration': 3600,
  149. 'age_limit': 18,
  150. },
  151. 'params': {
  152. 'skip_download': True,
  153. },
  154. }, {
  155. 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
  156. 'only_matching': True,
  157. }, {
  158. 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030',
  159. 'only_matching': True,
  160. }]
  161. @staticmethod
  162. def parse_video_key(key):
  163. video_key = {}
  164. m = re.match(r'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key)
  165. if m:
  166. video_key['upload_date'] = m.group('upload_date')
  167. video_key['part'] = int(m.group('part'))
  168. return video_key
  169. def _real_extract(self, url):
  170. video_id = self._match_id(url)
  171. video_xml = self._download_xml(
  172. 'http://afbbs.afreecatv.com:8080/api/video/get_video_info.php',
  173. video_id, query={
  174. 'nTitleNo': video_id,
  175. 'partialView': 'SKIP_ADULT',
  176. })
  177. flag = xpath_text(video_xml, './track/flag', 'flag', default=None)
  178. if flag and flag != 'SUCCEED':
  179. raise ExtractorError(
  180. '%s said: %s' % (self.IE_NAME, flag), expected=True)
  181. video_element = video_xml.findall(compat_xpath('./track/video'))[1]
  182. if video_element is None or video_element.text is None:
  183. raise ExtractorError('Specified AfreecaTV video does not exist',
  184. expected=True)
  185. video_url = video_element.text.strip()
  186. title = xpath_text(video_xml, './track/title', 'title', fatal=True)
  187. uploader = xpath_text(video_xml, './track/nickname', 'uploader')
  188. uploader_id = xpath_text(video_xml, './track/bj_id', 'uploader id')
  189. duration = int_or_none(xpath_text(
  190. video_xml, './track/duration', 'duration'))
  191. thumbnail = xpath_text(video_xml, './track/titleImage', 'thumbnail')
  192. common_entry = {
  193. 'uploader': uploader,
  194. 'uploader_id': uploader_id,
  195. 'thumbnail': thumbnail,
  196. }
  197. info = common_entry.copy()
  198. info.update({
  199. 'id': video_id,
  200. 'title': title,
  201. 'duration': duration,
  202. })
  203. if not video_url:
  204. entries = []
  205. file_elements = video_element.findall(compat_xpath('./file'))
  206. one = len(file_elements) == 1
  207. for file_num, file_element in enumerate(file_elements, start=1):
  208. file_url = file_element.text
  209. if not file_url:
  210. continue
  211. key = file_element.get('key', '')
  212. upload_date = self._search_regex(
  213. r'^(\d{8})_', key, 'upload date', default=None)
  214. file_duration = int_or_none(file_element.get('duration'))
  215. format_id = key if key else '%s_%s' % (video_id, file_num)
  216. if determine_ext(file_url) == 'm3u8':
  217. formats = self._extract_m3u8_formats(
  218. file_url, video_id, 'mp4', entry_protocol='m3u8_native',
  219. m3u8_id='hls',
  220. note='Downloading part %d m3u8 information' % file_num)
  221. else:
  222. formats = [{
  223. 'url': file_url,
  224. 'format_id': 'http',
  225. }]
  226. if not formats:
  227. continue
  228. self._sort_formats(formats)
  229. file_info = common_entry.copy()
  230. file_info.update({
  231. 'id': format_id,
  232. 'title': title if one else '%s (part %d)' % (title, file_num),
  233. 'upload_date': upload_date,
  234. 'duration': file_duration,
  235. 'formats': formats,
  236. })
  237. entries.append(file_info)
  238. entries_info = info.copy()
  239. entries_info.update({
  240. '_type': 'multi_video',
  241. 'entries': entries,
  242. })
  243. return entries_info
  244. info = {
  245. 'id': video_id,
  246. 'title': title,
  247. 'uploader': uploader,
  248. 'uploader_id': uploader_id,
  249. 'duration': duration,
  250. 'thumbnail': thumbnail,
  251. }
  252. if determine_ext(video_url) == 'm3u8':
  253. info['formats'] = self._extract_m3u8_formats(
  254. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  255. m3u8_id='hls')
  256. else:
  257. app, playpath = video_url.split('mp4:')
  258. info.update({
  259. 'url': app,
  260. 'ext': 'flv',
  261. 'play_path': 'mp4:' + playpath,
  262. 'rtmp_live': True, # downloading won't end without this
  263. })
  264. return info