iprima.py 3.7 KB

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