iprima.py 3.7 KB

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