caltrans.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from .common import InfoExtractor
  2. class CaltransIE(InfoExtractor):
  3. _VALID_URL = r'https?://(?:[^/]+\.)?ca\.gov/vm/loc/[^/]+/(?P<id>[a-z0-9_]+)\.htm'
  4. _TEST = {
  5. 'url': 'https://cwwp2.dot.ca.gov/vm/loc/d3/hwy50at24th.htm',
  6. 'info_dict': {
  7. 'id': 'hwy50at24th',
  8. 'ext': 'ts',
  9. 'title': 'US-50 : Sacramento : Hwy 50 at 24th',
  10. 'live_status': 'is_live',
  11. 'thumbnail': 'https://cwwp2.dot.ca.gov/data/d3/cctv/image/hwy50at24th/hwy50at24th.jpg',
  12. },
  13. }
  14. def _real_extract(self, url):
  15. video_id = self._match_id(url)
  16. webpage = self._download_webpage(url, video_id)
  17. global_vars = self._search_regex(
  18. r'<script[^<]+?([^<]+\.m3u8[^<]+)</script>',
  19. webpage, 'Global Vars')
  20. route_place = self._search_regex(r'routePlace\s*=\s*"([^"]+)"', global_vars, 'Route Place', fatal=False)
  21. location_name = self._search_regex(r'locationName\s*=\s*"([^"]+)"', global_vars, 'Location Name', fatal=False)
  22. poster_url = self._search_regex(r'posterURL\s*=\s*"([^"]+)"', global_vars, 'Poster Url', fatal=False)
  23. video_stream = self._search_regex(r'videoStreamURL\s*=\s*"([^"]+)"', global_vars, 'Video Stream URL', fatal=False)
  24. formats = self._extract_m3u8_formats(video_stream, video_id, 'ts', live=True)
  25. return {
  26. 'id': video_id,
  27. 'title': f'{route_place} : {location_name}',
  28. 'is_live': True,
  29. 'formats': formats,
  30. 'thumbnail': poster_url,
  31. }