joj.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. import re
  5. class JojIE(InfoExtractor):
  6. _VALID_URL = r'https?://[a-z0-9]+\.joj\.sk/([^/]+/)*(?P<title_query>(?P<release_date>[0-9]{4}(-[0-9]{2}){2}).*)' # noqa
  7. _TESTS = [{
  8. 'url': 'https://www.joj.sk/nove-byvanie/archiv/2017-05-28-nove-byvanie', # noqa
  9. 'info_dict': {
  10. 'id': 'a388ec4c-6019-4a4a-9312-b1bee194e932',
  11. 'ext': 'mp4',
  12. 'title': 'Nové Bývanie',
  13. 'release_date': '20170528'
  14. }
  15. }, {
  16. 'url': 'http://nasi.joj.sk/epizody/2016-09-06-stari-rodicia',
  17. 'info_dict': {
  18. 'id': 'f18b2c5f-9ea8-4941-a164-a814c53306ad',
  19. 'ext': 'mp4',
  20. 'title': 'Starí Rodičia',
  21. 'release_date': '20160906'
  22. }
  23. }]
  24. media_src_url = 'http://n16.joj.sk/storage/'
  25. xml_source_url = 'https://media.joj.sk/services/Video.php?clip='
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. release_date = mobj.group('release_date').replace('-', '')
  29. webpage = self._download_webpage(url, 'id')
  30. video_id = self._html_search_regex(
  31. r'https?://([a-z0-9]+\.)joj\.sk/embed/(?P<video_id>[a-f0-9\-]+)',
  32. webpage, 'id', group='video_id')
  33. xml_playlist_url = self.xml_source_url + video_id
  34. xml_playlist_et = self._download_xml(xml_playlist_url, 'XML playlist')
  35. formats = []
  36. for file_el in xml_playlist_et.findall('files/file'):
  37. try:
  38. height = int(file_el.attrib['id'].replace('p', ''))
  39. except ValueError:
  40. height = 0
  41. formats.append({'height': height,
  42. 'url': self.media_src_url + file_el.attrib['path'].replace( # noqa
  43. 'dat/', '', 1)})
  44. self._sort_formats(formats)
  45. return {
  46. 'id': video_id,
  47. 'title': self._og_search_title(webpage).title(),
  48. 'formats': formats,
  49. 'release_date': release_date
  50. }