Reorganized chat downloader
This commit is contained in:
@@ -1,51 +1,30 @@
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TwitchVideoRecorder:
|
||||
access_token = None
|
||||
is_running = False
|
||||
refresh_timeout = 15
|
||||
streamlink_process = None
|
||||
|
||||
def __init__(self, authenticator, streamer_name, recording_folder, quality="480p", on_finish=None):
|
||||
# global configuration
|
||||
self.disable_ffmpeg = False
|
||||
self.refresh_timeout = 15
|
||||
self.recording_folder = recording_folder
|
||||
self.stream_uid = None
|
||||
self.on_finish = on_finish
|
||||
def run(self, streamer_name, output_file, quality="480p"):
|
||||
self._record_stream(streamer_name, output_file, quality)
|
||||
|
||||
# twitch configuration
|
||||
self.streamer_name = streamer_name
|
||||
self.quality = quality
|
||||
self.authenticator = authenticator
|
||||
def stop(self):
|
||||
if self.streamlink_process:
|
||||
self.streamlink_process.kill()
|
||||
|
||||
def run(self):
|
||||
# make sure the interval to check user availability is not less than 15 seconds
|
||||
if self.refresh_timeout < 15:
|
||||
logger.warning("check interval should not be lower than 15 seconds")
|
||||
self.refresh_timeout = 15
|
||||
logger.warning("check interval set to 15 seconds")
|
||||
|
||||
self.record_stream(self.streamer_name, recording_path)
|
||||
|
||||
def record_stream(self, channel, recording_path):
|
||||
filename = self.streamer_name + " - " + datetime.datetime.now() \
|
||||
.strftime("%Y-%m-%d %Hh%Mm%Ss") + " - " + channel.get("title") + ".mp4"
|
||||
|
||||
filename = "".join(x for x in filename if x.isalnum() or x in [" ", "-", "_", "."])
|
||||
recorded_filename = os.path.join(recording_path, filename)
|
||||
|
||||
# start streamlink process
|
||||
subprocess.call([
|
||||
def _record_stream(self, streamer_name, output_file, quality):
|
||||
# subprocess.call()
|
||||
self.streamlink_process = subprocess.Popen([
|
||||
"streamlink",
|
||||
"--twitch-disable-ads",
|
||||
"twitch.tv/" + self.streamer_name,
|
||||
self.quality,
|
||||
"twitch.tv/" + streamer_name,
|
||||
quality,
|
||||
"-o",
|
||||
recorded_filename
|
||||
output_file
|
||||
])
|
||||
|
||||
return recorded_filename
|
||||
self.is_running = True
|
||||
|
||||
Reference in New Issue
Block a user