iprima.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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,
  21. },
  22. },
  23. ]
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('id')
  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(
  41. r'"%s_id":(.+?),' % format_id, webpage, 'filename')
  42. if filename == 'null':
  43. continue
  44. real_id = self._search_regex(
  45. r'Prima-[0-9]{10}-([0-9]+)_', filename, 'real video id')
  46. if format_id == 'lq':
  47. quality = 0
  48. elif format_id == 'hq':
  49. quality = 1
  50. elif format_id == 'hd':
  51. quality = 2
  52. filename = 'hq/' + filename
  53. formats.append({
  54. 'format_id': format_id,
  55. 'url': base_url,
  56. 'quality': quality,
  57. 'play_path': 'mp4:' + filename.replace('"', '')[:-4],
  58. 'rtmp_live': True,
  59. 'ext': 'flv',
  60. })
  61. self._sort_formats(formats)
  62. return {
  63. 'id': real_id,
  64. 'title': self._og_search_title(webpage),
  65. 'thumbnail': self._og_search_thumbnail(webpage),
  66. 'formats': formats,
  67. 'description': self._og_search_description(webpage),
  68. }