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.

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