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.

145 lines
5.3 KiB

9 years ago
9 years ago
9 years ago
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 (
  6. compat_urllib_parse_urlparse,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. int_or_none,
  12. update_url_query,
  13. xpath_element,
  14. xpath_text,
  15. )
  16. class AfreecaTVIE(InfoExtractor):
  17. IE_DESC = 'afreecatv.com'
  18. _VALID_URL = r'''(?x)
  19. https?://
  20. (?:
  21. (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
  22. (?:
  23. /app/(?:index|read_ucc_bbs)\.cgi|
  24. /player/[Pp]layer\.(?:swf|html)
  25. )\?.*?\bnTitleNo=|
  26. vod\.afreecatv\.com/PLAYER/STATION/
  27. )
  28. (?P<id>\d+)
  29. '''
  30. _TESTS = [{
  31. 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
  32. 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
  33. 'info_dict': {
  34. 'id': '36164052',
  35. 'ext': 'mp4',
  36. 'title': '데일리 에이프릴 요정들의 시상식!',
  37. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  38. 'uploader': 'dailyapril',
  39. 'uploader_id': 'dailyapril',
  40. 'upload_date': '20160503',
  41. }
  42. }, {
  43. 'url': 'http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=18605867',
  44. 'info_dict': {
  45. 'id': '36153164',
  46. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
  47. 'thumbnail': 're:^https?://(?:video|st)img.afreecatv.com/.*$',
  48. 'uploader': 'dailyapril',
  49. 'uploader_id': 'dailyapril',
  50. },
  51. 'playlist_count': 2,
  52. 'playlist': [{
  53. 'md5': 'd8b7c174568da61d774ef0203159bf97',
  54. 'info_dict': {
  55. 'id': '36153164_1',
  56. 'ext': 'mp4',
  57. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
  58. 'upload_date': '20160502',
  59. },
  60. }, {
  61. 'md5': '58f2ce7f6044e34439ab2d50612ab02b',
  62. 'info_dict': {
  63. 'id': '36153164_2',
  64. 'ext': 'mp4',
  65. 'title': "BJ유트루와 함께하는 '팅커벨 메이크업!'",
  66. 'upload_date': '20160502',
  67. },
  68. }],
  69. }, {
  70. 'url': 'http://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652',
  71. 'only_matching': True,
  72. }, {
  73. 'url': 'http://vod.afreecatv.com/PLAYER/STATION/15055030',
  74. 'only_matching': True,
  75. }]
  76. @staticmethod
  77. def parse_video_key(key):
  78. video_key = {}
  79. m = re.match(r'^(?P<upload_date>\d{8})_\w+_(?P<part>\d+)$', key)
  80. if m:
  81. video_key['upload_date'] = m.group('upload_date')
  82. video_key['part'] = m.group('part')
  83. return video_key
  84. def _real_extract(self, url):
  85. video_id = self._match_id(url)
  86. parsed_url = compat_urllib_parse_urlparse(url)
  87. info_url = compat_urlparse.urlunparse(parsed_url._replace(
  88. netloc='afbbs.afreecatv.com:8080',
  89. path='/api/video/get_video_info.php'))
  90. video_xml = self._download_xml(
  91. update_url_query(info_url, {'nTitleNo': video_id}), video_id)
  92. if xpath_element(video_xml, './track/video/file') is None:
  93. raise ExtractorError('Specified AfreecaTV video does not exist',
  94. expected=True)
  95. title = xpath_text(video_xml, './track/title', 'title')
  96. uploader = xpath_text(video_xml, './track/nickname', 'uploader')
  97. uploader_id = xpath_text(video_xml, './track/bj_id', 'uploader id')
  98. duration = int_or_none(xpath_text(video_xml, './track/duration',
  99. 'duration'))
  100. thumbnail = xpath_text(video_xml, './track/titleImage', 'thumbnail')
  101. entries = []
  102. for i, video_file in enumerate(video_xml.findall('./track/video/file')):
  103. video_key = self.parse_video_key(video_file.get('key', ''))
  104. if not video_key:
  105. continue
  106. entries.append({
  107. 'id': '%s_%s' % (video_id, video_key.get('part', i + 1)),
  108. 'title': title,
  109. 'upload_date': video_key.get('upload_date'),
  110. 'duration': int_or_none(video_file.get('duration')),
  111. 'url': video_file.text,
  112. })
  113. info = {
  114. 'id': video_id,
  115. 'title': title,
  116. 'uploader': uploader,
  117. 'uploader_id': uploader_id,
  118. 'duration': duration,
  119. 'thumbnail': thumbnail,
  120. }
  121. if len(entries) > 1:
  122. info['_type'] = 'multi_video'
  123. info['entries'] = entries
  124. elif len(entries) == 1:
  125. info['url'] = entries[0]['url']
  126. info['upload_date'] = entries[0].get('upload_date')
  127. else:
  128. raise ExtractorError(
  129. 'No files found for the specified AfreecaTV video, either'
  130. ' the URL is incorrect or the video has been made private.',
  131. expected=True)
  132. return info