webcamerapl.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import codecs
  2. from .common import InfoExtractor
  3. class WebcameraplIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?P<id>[\w-]+)\.webcamera\.pl'
  5. _TESTS = [{
  6. 'url': 'https://warszawa-plac-zamkowy.webcamera.pl',
  7. 'info_dict': {
  8. 'id': 'warszawa-plac-zamkowy',
  9. 'ext': 'mp4',
  10. 'title': r're:WIDOK NA PLAC ZAMKOWY W WARSZAWIE \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  11. 'live_status': 'is_live',
  12. },
  13. }, {
  14. 'url': 'https://gdansk-stare-miasto.webcamera.pl/',
  15. 'info_dict': {
  16. 'id': 'gdansk-stare-miasto',
  17. 'ext': 'mp4',
  18. 'title': r're:GDAŃSK - widok na Stare Miasto \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  19. 'live_status': 'is_live',
  20. },
  21. }]
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(url, video_id)
  25. rot13_m3u8_url = self._search_regex(r'data-src\s*=\s*"(uggc[^"]+\.z3h8)"',
  26. webpage, 'm3u8 url', default=None)
  27. if not rot13_m3u8_url:
  28. self.raise_no_formats('No video/audio found at the provided url', expected=True)
  29. m3u8_url = codecs.decode(rot13_m3u8_url, 'rot-13')
  30. formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, live=True)
  31. return {
  32. 'id': video_id,
  33. 'title': self._html_search_regex(r'<h1\b[^>]*>([^>]+)</h1>', webpage, 'title'),
  34. 'formats': formats,
  35. 'subtitles': subtitles,
  36. 'is_live': True,
  37. }