miomio.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import random
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. xpath_text,
  7. int_or_none,
  8. ExtractorError,
  9. )
  10. class MioMioIE(InfoExtractor):
  11. IE_NAME = 'miomio.tv'
  12. _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
  13. _TESTS = [{
  14. # "type=video" in flashvars
  15. 'url': 'http://www.miomio.tv/watch/cc88912/',
  16. 'md5': '317a5f7f6b544ce8419b784ca8edae65',
  17. 'info_dict': {
  18. 'id': '88912',
  19. 'ext': 'flv',
  20. 'title': '【SKY】字幕 铠武昭和VS平成 假面骑士大战FEAT战队 魔星字幕组 字幕',
  21. 'duration': 5923,
  22. },
  23. }, {
  24. 'url': 'http://www.miomio.tv/watch/cc184024/',
  25. 'info_dict': {
  26. 'id': '43729',
  27. 'title': '《动漫同人插画绘制》',
  28. },
  29. 'playlist_mincount': 86,
  30. }]
  31. def _real_extract(self, url):
  32. video_id = self._match_id(url)
  33. webpage = self._download_webpage(url, video_id)
  34. title = self._html_search_meta(
  35. 'description', webpage, 'title', fatal=True)
  36. mioplayer_path = self._search_regex(
  37. r'src="(/mioplayer/[^"]+)"', webpage, 'ref_path')
  38. xml_config = self._search_regex(
  39. r'flashvars="type=(?:sina|video)&amp;(.+?)&amp;',
  40. webpage, 'xml config')
  41. # skipping the following page causes lags and eventually connection drop-outs
  42. self._request_webpage(
  43. 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random.randint(100, 999)),
  44. video_id)
  45. # the following xml contains the actual configuration information on the video file(s)
  46. vid_config = self._download_xml(
  47. 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config),
  48. video_id)
  49. http_headers = {
  50. 'Referer': 'http://www.miomio.tv%s' % mioplayer_path,
  51. }
  52. if not int_or_none(xpath_text(vid_config, 'timelength')):
  53. raise ExtractorError('Unable to load videos!', expected=True)
  54. entries = []
  55. for f in vid_config.findall('./durl'):
  56. segment_url = xpath_text(f, 'url', 'video url')
  57. if not segment_url:
  58. continue
  59. order = xpath_text(f, 'order', 'order')
  60. segment_id = video_id
  61. segment_title = title
  62. if order:
  63. segment_id += '-%s' % order
  64. segment_title += ' part %s' % order
  65. entries.append({
  66. 'id': segment_id,
  67. 'url': segment_url,
  68. 'title': segment_title,
  69. 'duration': int_or_none(xpath_text(f, 'length', 'duration'), 1000),
  70. 'http_headers': http_headers,
  71. })
  72. if len(entries) == 1:
  73. segment = entries[0]
  74. segment['id'] = video_id
  75. segment['title'] = title
  76. return segment
  77. return {
  78. '_type': 'multi_video',
  79. 'id': video_id,
  80. 'entries': entries,
  81. 'title': title,
  82. 'http_headers': http_headers,
  83. }