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.

107 lines
3.5 KiB

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