Skip to content

Commit 920dc52

Browse files
author
ancalentari
committed
imagine messing this up... is it just me or is it 3:00 AM?
1 parent d3a12d4 commit 920dc52

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

twitch-recorder.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,29 @@ def run(self):
6767

6868
# fix videos from previous recording session
6969
try:
70-
video_list = [f for f in os.listdir(recorded_path) if
71-
os.path.isfile(os.path.join(recorded_path, f))]
70+
video_list = [f for f in os.listdir(recorded_path) if os.path.isfile(os.path.join(recorded_path, f))]
7271
if len(video_list) > 0:
73-
logging.info("fixing previously recorded files")
72+
logging.info("processing previously recorded files")
7473
for f in video_list:
7574
recorded_filename = os.path.join(recorded_path, f)
7675
processed_filename = os.path.join(processed_path, f)
77-
if self.disable_ffmpeg:
78-
shutil.move(recorded_filename, processed_filename)
79-
else:
80-
self.ffmpeg_copy_and_fix_errors(recorded_filename, processed_filename)
76+
self.process_recorded_file(recorded_filename, processed_filename)
8177
except Exception as e:
8278
logging.error(e)
8379

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

84+
def process_recorded_file(self, recorded_filename, processed_filename):
85+
if self.disable_ffmpeg:
86+
logging.info("moving: %s", recorded_filename)
87+
shutil.move(recorded_filename, processed_filename)
88+
else:
89+
logging.info("fixing %s", recorded_filename)
90+
self.ffmpeg_copy_and_fix_errors(recorded_filename, processed_filename)
91+
8892
def ffmpeg_copy_and_fix_errors(self, recorded_filename, processed_filename):
89-
logging.info("fixing %s", recorded_filename)
9093
try:
9194
subprocess.call(
9295
[self.ffmpeg_path, "-err_detect", "ignore_err", "-i", recorded_filename, "-c", "copy",
@@ -113,7 +116,6 @@ def check_user(self):
113116
status = TwitchResponseStatus.UNAUTHORIZED
114117
if e.response.status_code == 404:
115118
status = TwitchResponseStatus.NOT_FOUND
116-
117119
return status, info
118120

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

146148
recorded_filename = os.path.join(recorded_path, filename)
149+
processed_filename = os.path.join(processed_path, filename)
147150

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

153-
logging.info("recording stream is done, fixing video file")
156+
logging.info("recording stream is done, processing video file")
154157
if os.path.exists(recorded_filename) is True:
155-
try:
156-
subprocess.call(
157-
[self.ffmpeg_path, "-err_detect", "ignore_err", "-i", recorded_filename, "-c", "copy",
158-
os.path.join(processed_path, filename)])
159-
os.remove(recorded_filename)
160-
except Exception as e:
161-
logging.error(e)
158+
self.process_recorded_file(recorded_filename, processed_filename)
162159
else:
163160
logging.info("skip fixing, file not found")
164161

165-
logging.info("fixing is done, going back to checking...")
162+
logging.info("processing is done, going back to checking...")
166163
time.sleep(self.refresh)
167164

168165

0 commit comments

Comments
 (0)