Advertisement
Guest User

twitcast auto recording

a guest
Nov 28th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import argparse
  3. import os
  4. import requests
  5. import time
  6. from datetime import datetime
  7.  
  8. def _get_stream_info(user):
  9.     url = f'https://twitcasting.tv/streamserver.php?target={user}&mode=client'
  10.     r = requests.get(url, headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0' })
  11.     data = r.json()
  12.     return data
  13.  
  14.  
  15. def check_live_status(user):
  16.     data = _get_stream_info(user)
  17.     return data['movie']['live']
  18.  
  19.  
  20. if __name__ == '__main__':
  21.     parser = argparse.ArgumentParser(description='TwitCasting live stream monitor.')
  22.     parser.add_argument('user_id', help='The user id to record. i.e. the string after "https://twitcasting.tv/" in URL')
  23.     args = parser.parse_args()
  24.  
  25.     while True:
  26.         live_status = check_live_status(args.user_id)
  27.         if live_status == False:
  28.             print(f'User {args.user_id} is offline, retrying every 15 seconds...')
  29.         while live_status == False:
  30.             time.sleep(15)
  31.             live_status = check_live_status(args.user_id)
  32.  
  33.         t = datetime.now().strftime('%Y%m%d%H%M%S')
  34.         os.system(f'yt-dlp http://twitcasting.tv/{args.user_id} --no-part -o "%(uploader_id)s/[%(id)s] %(title)s-{t}.ts"')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement