afreecatv.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse_urlparse,
  6. compat_urlparse,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. int_or_none,
  11. )
  12. class AfreecaTVIE(InfoExtractor):
  13. IE_DESC = 'afreecatv.com'
  14. _VALID_URL = r'''(?x)^
  15. https?://(?:(live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
  16. (?:
  17. /app/(?:index|read_ucc_bbs)\.cgi|
  18. /player/[Pp]layer\.(?:swf|html))
  19. \?.*?\bnTitleNo=(?P<id>\d+)'''
  20. _TEST = {
  21. 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
  22. 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
  23. 'info_dict': {
  24. 'id': '36164052',
  25. 'ext': 'mp4',
  26. 'title': '데일리 에이프릴 요정들의 시상식!',
  27. 'thumbnail': 're:^https?://videoimg.afreecatv.com/.*$',
  28. 'uploader': 'dailyapril',
  29. 'uploader_id': 'dailyapril',
  30. }
  31. }
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. parsed_url = compat_urllib_parse_urlparse(url)
  35. info_url = compat_urlparse.urlunparse(parsed_url._replace(
  36. netloc='afbbs.afreecatv.com:8080',
  37. path='/api/video/get_video_info.php'))
  38. video_xml = self._download_xml(info_url, video_id)
  39. track = video_xml.find('track')
  40. if track.find('flag').text != 'SUCCEED':
  41. raise ExtractorError('Specified AfreecaTV video does not exist',
  42. expected=True)
  43. title = track.find('title').text
  44. uploader = track.find('nickname').text
  45. uploader_id = track.find('bj_id').text
  46. duration = int_or_none(track.find('duration').text)
  47. thumbnail = track.find('titleImage').text
  48. entries = []
  49. for video in track.findall('video'):
  50. for video_file in video.findall('file'):
  51. entries.append({
  52. 'id': video_file.get('key'),
  53. 'title': title,
  54. 'duration': int_or_none(video_file.get('duration')),
  55. 'formats': [{'url': video_file.text}]
  56. })
  57. info = {
  58. 'id': video_id,
  59. 'title': title,
  60. 'uploader': uploader,
  61. 'uploader_id': uploader_id,
  62. 'duration': duration,
  63. 'thumbnail': thumbnail,
  64. }
  65. if len(entries) > 1:
  66. info['_type'] = 'multi_video'
  67. info['entries'] = entries
  68. elif len(entries) == 1:
  69. info['formats'] = entries[0]['formats']
  70. else:
  71. raise ExtractorError(
  72. 'No files found for the specified AfreecaTV video, either'
  73. ' the URL is incorrect or the video has been made private.',
  74. expected=True)
  75. return info