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.

72 lines
2.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. from ..utils import (
  7. get_element_by_attribute,
  8. qualities,
  9. unescapeHTML,
  10. )
  11. class OraTVIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?ora\.tv/([^/]+/)*(?P<id>[^/\?#]+)'
  13. _TEST = {
  14. 'url': 'https://www.ora.tv/larrykingnow/2015/12/16/vine-youtube-stars-zach-king-king-bach-on-their-viral-videos-0_36jupg6090pq',
  15. 'md5': 'fa33717591c631ec93b04b0e330df786',
  16. 'info_dict': {
  17. 'id': '50178',
  18. 'ext': 'mp4',
  19. 'title': 'Vine & YouTube Stars Zach King & King Bach On Their Viral Videos!',
  20. 'description': 'md5:ebbc5b1424dd5dba7be7538148287ac1',
  21. }
  22. }
  23. def _real_extract(self, url):
  24. display_id = self._match_id(url)
  25. webpage = self._download_webpage(url, display_id)
  26. video_data = self._search_regex(
  27. r'"(?:video|current)"\s*:\s*({[^}]+?})', webpage, 'current video')
  28. m3u8_url = self._search_regex(
  29. r'hls_stream"?\s*:\s*"([^"]+)', video_data, 'm3u8 url', None)
  30. if m3u8_url:
  31. formats = self._extract_m3u8_formats(
  32. m3u8_url, display_id, 'mp4', 'm3u8_native',
  33. m3u8_id='hls', fatal=False)
  34. # similar to GameSpotIE
  35. m3u8_path = compat_urlparse.urlparse(m3u8_url).path
  36. QUALITIES_RE = r'((,[a-z]+\d+)+,?)'
  37. available_qualities = self._search_regex(
  38. QUALITIES_RE, m3u8_path, 'qualities').strip(',').split(',')
  39. http_path = m3u8_path[1:].split('/', 1)[1]
  40. http_template = re.sub(QUALITIES_RE, r'%s', http_path)
  41. http_template = http_template.replace('.csmil/master.m3u8', '')
  42. http_template = compat_urlparse.urljoin(
  43. 'http://videocdn-pmd.ora.tv/', http_template)
  44. preference = qualities(
  45. ['mobile400', 'basic400', 'basic600', 'sd900', 'sd1200', 'sd1500', 'hd720', 'hd1080'])
  46. for q in available_qualities:
  47. formats.append({
  48. 'url': http_template % q,
  49. 'format_id': q,
  50. 'preference': preference(q),
  51. })
  52. self._sort_formats(formats)
  53. else:
  54. return self.url_result(self._search_regex(
  55. r'"youtube_id"\s*:\s*"([^"]+)', webpage, 'youtube id'), 'Youtube')
  56. return {
  57. 'id': self._search_regex(
  58. r'"id"\s*:\s*(\d+)', video_data, 'video id', default=display_id),
  59. 'display_id': display_id,
  60. 'title': unescapeHTML(self._og_search_title(webpage)),
  61. 'description': get_element_by_attribute(
  62. 'class', 'video_txt_decription', webpage),
  63. 'thumbnail': self._proto_relative_url(self._search_regex(
  64. r'"thumb"\s*:\s*"([^"]+)', video_data, 'thumbnail', None)),
  65. 'formats': formats,
  66. }