miomio_tv.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. class MiomioTvIE(InfoExtractor):
  5. IE_NAME = 'miomio.tv'
  6. _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
  7. _TEST = {
  8. 'url': 'http://www.miomio.tv/watch/cc179734/',
  9. 'md5': '48de02137d0739c15b440a224ad364b9',
  10. 'info_dict': {
  11. 'id': '179734',
  12. 'title': u'\u624b\u7ed8\u52a8\u6f2b\u9b3c\u6ce3\u4f46\u4e01\u5168\u7a0b\u753b\u6cd5',
  13. 'ext': 'flv'
  14. }
  15. }
  16. def _real_extract(self, url):
  17. video_id = self._match_id(url)
  18. webpage = self._download_webpage(url, video_id)
  19. title = self._html_search_regex(r'<meta\s+name="description"\s+content="\s*([^"]*)\s*"', webpage, 'title')
  20. ref_path = self._search_regex(r'src="(/mioplayer/.*?)"', webpage, 'ref_path')
  21. referer = 'http://www.miomio.tv{}'.format(ref_path)
  22. xml_config = self._search_regex(r'flashvars="type=sina&amp;(.*?)&amp;cid=', webpage, 'xml config')
  23. self._request_webpage("http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id={}&r=cc{}".format(id, 945), video_id)
  24. xml_url = 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{}'.format(xml_config)
  25. vidconfig = self._download_xml(xml_url, video_id)
  26. file_els = vidconfig.findall('.//durl')
  27. entries = []
  28. for file_el in file_els:
  29. segment_id = file_el.find('order').text.strip()
  30. segment_title = '_'.join([title, segment_id])
  31. segment_duration = file_el.find('length').text.strip()
  32. segment_url = file_el.find('url').text.strip()
  33. entries.append({
  34. 'id': segment_id,
  35. 'title': segment_title,
  36. 'duration': segment_duration,
  37. 'url': segment_url
  38. })
  39. http_headers = {
  40. 'Referer': referer,
  41. 'Accept-Language': 'en,en-US;q=0.7,de;q=0.3',
  42. 'Accept-Encoding': 'gzip, deflate',
  43. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
  44. }
  45. if len(entries) == 1:
  46. return {
  47. 'id': video_id,
  48. 'title': title,
  49. 'url': entries[0]['url'],
  50. 'http_headers': http_headers
  51. }
  52. return {
  53. '_type': 'multi_video',
  54. 'id': video_id,
  55. 'title': title,
  56. 'entries': entries,
  57. 'http_headers': http_headers
  58. }