afreecatv.py 3.0 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. xpath_text,
  12. )
  13. class AfreecaTVIE(InfoExtractor):
  14. IE_DESC = 'afreecatv.com'
  15. _VALID_URL = r'''(?x)^
  16. https?://(?:(live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
  17. (?:
  18. /app/(?:index|read_ucc_bbs)\.cgi|
  19. /player/[Pp]layer\.(?:swf|html))
  20. \?.*?\bnTitleNo=(?P<id>\d+)'''
  21. _TEST = {
  22. 'url': 'http://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin=',
  23. 'md5': 'f72c89fe7ecc14c1b5ce506c4996046e',
  24. 'info_dict': {
  25. 'id': '36164052',
  26. 'ext': 'mp4',
  27. 'title': '데일리 에이프릴 요정들의 시상식!',
  28. 'thumbnail': 're:^https?://videoimg.afreecatv.com/.*$',
  29. 'uploader': 'dailyapril',
  30. 'uploader_id': 'dailyapril',
  31. }
  32. }
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. parsed_url = compat_urllib_parse_urlparse(url)
  36. info_url = compat_urlparse.urlunparse(parsed_url._replace(
  37. netloc='afbbs.afreecatv.com:8080',
  38. path='/api/video/get_video_info.php'))
  39. video_xml = self._download_xml(info_url, video_id)
  40. if xpath_text(video_xml, './track/flag', default='FAIL') != 'SUCCEED':
  41. raise ExtractorError('Specified AfreecaTV video does not exist',
  42. expected=True)
  43. title = xpath_text(video_xml, './track/title', 'title')
  44. uploader = xpath_text(video_xml, './track/nickname', 'uploader')
  45. uploader_id = xpath_text(video_xml, './track/bj_id', 'uploader id')
  46. duration = int_or_none(xpath_text(video_xml, './track/duration',
  47. 'duration'))
  48. thumbnail = xpath_text(video_xml, './track/titleImage', 'thumbnail')
  49. entries = []
  50. for video_file in video_xml.findall('./track/video/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