Skip to content

Commit

Permalink
imagine messing this up... is it just me or is it 3:00 AM?
Browse files Browse the repository at this point in the history
  • Loading branch information
ancalentari committed Jun 14, 2020
1 parent d3a12d4 commit 920dc52
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions twitch-recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,29 @@ def run(self):

# fix videos from previous recording session
try:
video_list = [f for f in os.listdir(recorded_path) if
os.path.isfile(os.path.join(recorded_path, f))]
video_list = [f for f in os.listdir(recorded_path) if os.path.isfile(os.path.join(recorded_path, f))]
if len(video_list) > 0:
logging.info("fixing previously recorded files")
logging.info("processing previously recorded files")
for f in video_list:
recorded_filename = os.path.join(recorded_path, f)
processed_filename = os.path.join(processed_path, f)
if self.disable_ffmpeg:
shutil.move(recorded_filename, processed_filename)
else:
self.ffmpeg_copy_and_fix_errors(recorded_filename, processed_filename)
self.process_recorded_file(recorded_filename, processed_filename)
except Exception as e:
logging.error(e)

logging.info("checking for %s every %s seconds, recording with %s quality",
self.username, self.refresh, self.quality)
self.loop_check(recorded_path, processed_path)

def process_recorded_file(self, recorded_filename, processed_filename):
if self.disable_ffmpeg:
logging.info("moving: %s", recorded_filename)
shutil.move(recorded_filename, processed_filename)
else:
logging.info("fixing %s", recorded_filename)
self.ffmpeg_copy_and_fix_errors(recorded_filename, processed_filename)

def ffmpeg_copy_and_fix_errors(self, recorded_filename, processed_filename):
logging.info("fixing %s", recorded_filename)
try:
subprocess.call(
[self.ffmpeg_path, "-err_detect", "ignore_err", "-i", recorded_filename, "-c", "copy",
Expand All @@ -113,7 +116,6 @@ def check_user(self):
status = TwitchResponseStatus.UNAUTHORIZED
if e.response.status_code == 404:
status = TwitchResponseStatus.NOT_FOUND

return status, info

def loop_check(self, recorded_path, processed_path):
Expand Down Expand Up @@ -144,25 +146,20 @@ def loop_check(self, recorded_path, processed_path):
filename = "".join(x for x in filename if x.isalnum() or x in [" ", "-", "_", "."])

recorded_filename = os.path.join(recorded_path, filename)
processed_filename = os.path.join(processed_path, filename)

# start streamlink process
subprocess.call(
["streamlink", "--twitch-oauth-token", self.access_token, "twitch.tv/" + self.username,
self.quality, "-o", recorded_filename])

logging.info("recording stream is done, fixing video file")
logging.info("recording stream is done, processing video file")
if os.path.exists(recorded_filename) is True:
try:
subprocess.call(
[self.ffmpeg_path, "-err_detect", "ignore_err", "-i", recorded_filename, "-c", "copy",
os.path.join(processed_path, filename)])
os.remove(recorded_filename)
except Exception as e:
logging.error(e)
self.process_recorded_file(recorded_filename, processed_filename)
else:
logging.info("skip fixing, file not found")

logging.info("fixing is done, going back to checking...")
logging.info("processing is done, going back to checking...")
time.sleep(self.refresh)


Expand Down

0 comments on commit 920dc52

Please sign in to comment.