iprima.py 3.4 KB

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