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.

85 lines
2.7 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<videogroup>.+)/(?P<videoid>.+)'
  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,
  21. },
  22. },
  23. ]
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('videoid')
  27. webpage = self._download_webpage(url, video_id)
  28. player_url = 'http://embed.livebox.cz/iprimaplay/player-embed-v2.js?__tok%s__=%s' % (
  29. floor(random()*1073741824),
  30. floor(random()*1073741824))
  31. req = compat_urllib_request.Request(player_url)
  32. req.add_header('Referer', url)
  33. playerpage = self._download_webpage(req, video_id)
  34. base_url = ''.join(re.findall(r"embed\['stream'\] = '(.+?)'.+'(\?auth=)'.+'(.+?)';", playerpage)[1])
  35. zoneGEO = self._html_search_regex(r'"zoneGEO":(.+?),', webpage, 'zoneGEO')
  36. if zoneGEO != '0':
  37. base_url = base_url.replace('token', 'token_'+zoneGEO)
  38. formats = []
  39. for format_id in ['lq', 'hq', 'hd']:
  40. filename = self._html_search_regex(r'"%s_id":(.+?),' % format_id, webpage, 'filename')
  41. if filename == 'null':
  42. continue
  43. real_id = self._search_regex(r'Prima-[0-9]{10}-([0-9]+)_', filename, 'real video id')
  44. if format_id == 'lq':
  45. quality = 0
  46. elif format_id == 'hq':
  47. quality = 1
  48. elif format_id == 'hd':
  49. quality = 2
  50. filename = 'hq/'+filename
  51. formats.append({
  52. 'format_id': format_id,
  53. 'url': base_url,
  54. 'quality': quality,
  55. 'play_path': 'mp4:'+filename.replace('"', '')[:-4],
  56. 'rtmp_live': True,
  57. 'ext': 'flv',
  58. })
  59. self._sort_formats(formats)
  60. return {
  61. 'id': real_id,
  62. 'title': self._og_search_title(webpage),
  63. 'thumbnail': self._og_search_thumbnail(webpage),
  64. 'formats': formats,
  65. 'description': self._og_search_description(webpage),
  66. }