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.

90 lines
3.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. float_or_none,
  7. int_or_none,
  8. parse_iso8601,
  9. )
  10. class ClipRsIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?clip\.rs/(?P<id>[^/]+)/\d+'
  12. _TEST = {
  13. 'url': 'http://www.clip.rs/premijera-frajle-predstavljaju-novi-spot-za-pesmu-moli-me-moli/3732',
  14. 'md5': 'c412d57815ba07b56f9edc7b5d6a14e5',
  15. 'info_dict': {
  16. 'id': '1488842.1399140381',
  17. 'ext': 'mp4',
  18. 'title': 'PREMIJERA Frajle predstavljaju novi spot za pesmu Moli me, moli',
  19. 'description': 'md5:56ce2c3b4ab31c5a2e0b17cb9a453026',
  20. 'duration': 229,
  21. 'timestamp': 1459850243,
  22. 'upload_date': '20160405',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. video_id = self._search_regex(
  29. r'id=(["\'])mvp:(?P<id>.+?)\1', webpage, 'mvp id', group='id')
  30. response = self._download_json(
  31. 'http://qi.ckm.onetapi.pl/', video_id,
  32. query={
  33. 'body[id]': video_id,
  34. 'body[jsonrpc]': '2.0',
  35. 'body[method]': 'get_asset_detail',
  36. 'body[params][ID_Publikacji]': video_id,
  37. 'body[params][Service]': 'www.onet.pl',
  38. 'content-type': 'application/jsonp',
  39. 'x-onet-app': 'player.front.onetapi.pl',
  40. })
  41. error = response.get('error')
  42. if error:
  43. raise ExtractorError(
  44. '%s said: %s' % (self.IE_NAME, error['message']), expected=True)
  45. video = response['result'].get('0')
  46. formats = []
  47. for _, formats_dict in video['formats'].items():
  48. if not isinstance(formats_dict, dict):
  49. continue
  50. for format_id, format_list in formats_dict.items():
  51. if not isinstance(format_list, list):
  52. continue
  53. for f in format_list:
  54. if not f.get('url'):
  55. continue
  56. formats.append({
  57. 'url': f['url'],
  58. 'format_id': format_id,
  59. 'height': int_or_none(f.get('vertical_resolution')),
  60. 'width': int_or_none(f.get('horizontal_resolution')),
  61. 'abr': float_or_none(f.get('audio_bitrate')),
  62. 'vbr': float_or_none(f.get('video_bitrate')),
  63. })
  64. self._sort_formats(formats)
  65. meta = video.get('meta', {})
  66. title = self._og_search_title(webpage, default=None) or meta['title']
  67. description = self._og_search_description(webpage, default=None) or meta.get('description')
  68. duration = meta.get('length') or meta.get('lenght')
  69. timestamp = parse_iso8601(meta.get('addDate'), ' ')
  70. return {
  71. 'id': video_id,
  72. 'title': title,
  73. 'description': description,
  74. 'duration': duration,
  75. 'timestamp': timestamp,
  76. 'formats': formats,
  77. }