Advertisement
JLindvig

SkylineWebcam PyScript

Mar 6th, 2022
1,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. import aiohttp
  2. import aiofiles
  3.  
  4. @service
  5. @time_trigger
  6. def run_on_startup_or_reload():
  7.     input_text.php_session_id.set_value('')
  8.  
  9. @service
  10. @time_trigger('period(now + 5sec, 18sec)')
  11. def playa_las_vistas():
  12.  
  13.     URL = 'https://www.skylinewebcams.com/en/webcam/espana/canarias/santa-cruz-de-tenerife/playa-las-vistas.html'
  14.     FILENAME = 'playa-las-vistas.m3u8'
  15.     PATH = './www/images/webcams/'
  16.     HEADERS = {
  17.         'authority': 'hd-auth.skylinewebcams.com',
  18.         'origin': 'https://www.skylinewebcams.com',
  19.         'referer': 'https://www.skylinewebcams.com/',
  20.         'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
  21.     }
  22.  
  23.     php_session_id = input_text.php_session_id
  24.     async with aiohttp.ClientSession(cookie_jar = aiohttp.CookieJar()) as s:
  25.         if php_session_id == '':
  26.             async with s.get(URL, headers = HEADERS) as r:
  27.                 cookies = s.cookie_jar.filter_cookies('https://www.skylinewebcams.com').items()
  28.                 for key, cookie in cookies:
  29.                     if str(cookie.key) == 'PHPSESSID':
  30.                         php_session_id = cookie.value
  31.                         input_text.php_session_id.set_value(php_session_id)
  32.  
  33.         URL = 'https://hd-auth.skylinewebcams.com/live.m3u8?a=' + php_session_id
  34.         async with s.get(URL, headers = HEADERS) as r:
  35.             content = r.read()
  36.             async with aiofiles.open(PATH + FILENAME, 'wb') as f:
  37.                 await f.write(content)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement