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.

113 lines
3.6 KiB

9 years ago
10 years ago
  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:74e9617e51bca67c3ecfb2c6f9766f45',
  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. 'thumbnail': 're:^http:.*\.jpg$',
  35. },
  36. 'params': {
  37. 'skip_download': True, # requires rtmpdump
  38. },
  39. }, {
  40. 'url': 'http://play.iprima.cz/zpravy-ftv-prima-2752015',
  41. 'only_matching': True,
  42. }]
  43. def _real_extract(self, url):
  44. mobj = re.match(self._VALID_URL, url)
  45. video_id = mobj.group('id')
  46. webpage = self._download_webpage(url, video_id)
  47. if re.search(r'Nemáte oprávnění přistupovat na tuto stránku\.\s*</div>', webpage):
  48. raise ExtractorError(
  49. '%s said: You do not have permission to access this page' % self.IE_NAME, expected=True)
  50. player_url = (
  51. 'http://embed.livebox.cz/iprimaplay/player-embed-v2.js?__tok%s__=%s' %
  52. (floor(random() * 1073741824), floor(random() * 1073741824))
  53. )
  54. req = compat_urllib_request.Request(player_url)
  55. req.add_header('Referer', url)
  56. playerpage = self._download_webpage(req, video_id)
  57. base_url = ''.join(re.findall(r"embed\['stream'\] = '(.+?)'.+'(\?auth=)'.+'(.+?)';", playerpage)[1])
  58. zoneGEO = self._html_search_regex(r'"zoneGEO":(.+?),', webpage, 'zoneGEO')
  59. if zoneGEO != '0':
  60. base_url = base_url.replace('token', 'token_' + zoneGEO)
  61. formats = []
  62. for format_id in ['lq', 'hq', 'hd']:
  63. filename = self._html_search_regex(
  64. r'"%s_id":(.+?),' % format_id, webpage, 'filename')
  65. if filename == 'null':
  66. continue
  67. real_id = self._search_regex(
  68. r'Prima-(?:[0-9]{10}|WEB)-([0-9]+)[-_]',
  69. filename, 'real video id')
  70. if format_id == 'lq':
  71. quality = 0
  72. elif format_id == 'hq':
  73. quality = 1
  74. elif format_id == 'hd':
  75. quality = 2
  76. filename = 'hq/' + filename
  77. formats.append({
  78. 'format_id': format_id,
  79. 'url': base_url,
  80. 'quality': quality,
  81. 'play_path': 'mp4:' + filename.replace('"', '')[:-4],
  82. 'rtmp_live': True,
  83. 'ext': 'flv',
  84. })
  85. self._sort_formats(formats)
  86. return {
  87. 'id': real_id,
  88. 'title': remove_end(self._og_search_title(webpage), ' | Prima PLAY'),
  89. 'thumbnail': self._og_search_thumbnail(webpage),
  90. 'formats': formats,
  91. 'description': self._search_regex(
  92. r'<p[^>]+itemprop="description"[^>]*>([^<]+)',
  93. webpage, 'description', default=None),
  94. }