iprima.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from random import random
  5. from math import floor
  6. from .common import InfoExtractor
  7. from ..utils import (
  8. ExtractorError,
  9. remove_end,
  10. sanitized_Request,
  11. )
  12. class IPrimaIE(InfoExtractor):
  13. _VALID_URL = r'https?://play\.iprima\.cz/(?:[^/]+/)*(?P<id>[^?#]+)'
  14. _TESTS = [{
  15. 'url': 'http://play.iprima.cz/particka/particka-92',
  16. 'info_dict': {
  17. 'id': '39152',
  18. 'ext': 'flv',
  19. 'title': 'Partička (92)',
  20. 'description': 'md5:74e9617e51bca67c3ecfb2c6f9766f45',
  21. 'thumbnail': 'http://play.iprima.cz/sites/default/files/image_crops/image_620x349/3/491483_particka-92_image_620x349.jpg',
  22. },
  23. 'params': {
  24. 'skip_download': True, # requires rtmpdump
  25. },
  26. }, {
  27. 'url': 'http://play.iprima.cz/particka/tchibo-particka-jarni-moda',
  28. 'info_dict': {
  29. 'id': '9718337',
  30. 'ext': 'flv',
  31. 'title': 'Tchibo Partička - Jarní móda',
  32. 'thumbnail': 're:^http:.*\.jpg$',
  33. },
  34. 'params': {
  35. 'skip_download': True, # requires rtmpdump
  36. },
  37. }, {
  38. 'url': 'http://play.iprima.cz/zpravy-ftv-prima-2752015',
  39. 'only_matching': True,
  40. }]
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. video_id = mobj.group('id')
  44. webpage = self._download_webpage(url, video_id)
  45. if re.search(r'Nemáte oprávnění přistupovat na tuto stránku\.\s*</div>', webpage):
  46. raise ExtractorError(
  47. '%s said: You do not have permission to access this page' % self.IE_NAME, expected=True)
  48. player_url = (
  49. 'http://embed.livebox.cz/iprimaplay/player-embed-v2.js?__tok%s__=%s' %
  50. (floor(random() * 1073741824), floor(random() * 1073741824))
  51. )
  52. req = sanitized_Request(player_url)
  53. req.add_header('Referer', url)
  54. playerpage = self._download_webpage(req, video_id)
  55. base_url = ''.join(re.findall(r"embed\['stream'\] = '(.+?)'.+'(\?auth=)'.+'(.+?)';", playerpage)[1])
  56. zoneGEO = self._html_search_regex(r'"zoneGEO":(.+?),', webpage, 'zoneGEO')
  57. if zoneGEO != '0':
  58. base_url = base_url.replace('token', 'token_' + zoneGEO)
  59. formats = []
  60. for format_id in ['lq', 'hq', 'hd']:
  61. filename = self._html_search_regex(
  62. r'"%s_id":(.+?),' % format_id, webpage, 'filename')
  63. if filename == 'null':
  64. continue
  65. real_id = self._search_regex(
  66. r'Prima-(?:[0-9]{10}|WEB)-([0-9]+)[-_]',
  67. filename, 'real video id')
  68. if format_id == 'lq':
  69. quality = 0
  70. elif format_id == 'hq':
  71. quality = 1
  72. elif format_id == 'hd':
  73. quality = 2
  74. filename = 'hq/' + filename
  75. formats.append({
  76. 'format_id': format_id,
  77. 'url': base_url,
  78. 'quality': quality,
  79. 'play_path': 'mp4:' + filename.replace('"', '')[:-4],
  80. 'rtmp_live': True,
  81. 'ext': 'flv',
  82. })
  83. self._sort_formats(formats)
  84. return {
  85. 'id': real_id,
  86. 'title': remove_end(self._og_search_title(webpage), ' | Prima PLAY'),
  87. 'thumbnail': self._og_search_thumbnail(webpage),
  88. 'formats': formats,
  89. 'description': self._search_regex(
  90. r'<p[^>]+itemprop="description"[^>]*>([^<]+)',
  91. webpage, 'description', default=None),
  92. }