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.

93 lines
2.9 KiB

  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. )
  9. class MioMioIE(InfoExtractor):
  10. IE_NAME = 'miomio.tv'
  11. _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.miomio.tv/watch/cc179734/',
  14. 'md5': '48de02137d0739c15b440a224ad364b9',
  15. 'info_dict': {
  16. 'id': '179734',
  17. 'ext': 'flv',
  18. 'title': '手绘动漫鬼泣但丁全程画法',
  19. 'duration': 354,
  20. },
  21. }, {
  22. 'url': 'http://www.miomio.tv/watch/cc184024/',
  23. 'info_dict': {
  24. 'id': '43729',
  25. 'title': '《动漫同人插画绘制》',
  26. },
  27. 'playlist_mincount': 86,
  28. }]
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. webpage = self._download_webpage(url, video_id)
  32. title = self._html_search_meta(
  33. 'description', webpage, 'title', fatal=True)
  34. mioplayer_path = self._search_regex(
  35. r'src="(/mioplayer/[^"]+)"', webpage, 'ref_path')
  36. xml_config = self._search_regex(
  37. r'flashvars="type=sina&amp;(.+?)&amp;',
  38. webpage, 'xml config')
  39. # skipping the following page causes lags and eventually connection drop-outs
  40. self._request_webpage(
  41. 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random.randint(100, 999)),
  42. video_id)
  43. # the following xml contains the actual configuration information on the video file(s)
  44. vid_config = self._download_xml(
  45. 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config),
  46. video_id)
  47. http_headers = {
  48. 'Referer': 'http://www.miomio.tv%s' % mioplayer_path,
  49. }
  50. entries = []
  51. for f in vid_config.findall('./durl'):
  52. segment_url = xpath_text(f, 'url', 'video url')
  53. if not segment_url:
  54. continue
  55. order = xpath_text(f, 'order', 'order')
  56. segment_id = video_id
  57. segment_title = title
  58. if order:
  59. segment_id += '-%s' % order
  60. segment_title += ' part %s' % order
  61. entries.append({
  62. 'id': segment_id,
  63. 'url': segment_url,
  64. 'title': segment_title,
  65. 'duration': int_or_none(xpath_text(f, 'length', 'duration'), 1000),
  66. 'http_headers': http_headers,
  67. })
  68. if len(entries) == 1:
  69. segment = entries[0]
  70. segment['id'] = video_id
  71. segment['title'] = title
  72. return segment
  73. return {
  74. '_type': 'multi_video',
  75. 'id': video_id,
  76. 'entries': entries,
  77. 'title': title,
  78. 'http_headers': http_headers,
  79. }