Skip to content

Commit

Permalink
refresh TIME_DATE, TIME_CLOCK every tries (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
hui1601 committed Feb 27, 2024
1 parent f96c30a commit 5d3ec69
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
52 changes: 36 additions & 16 deletions AutoVOD.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ determineSource
while true; do
# Store the orignal values
variables=("VIDEO_TITLE" "VIDEO_PLAYLIST" "VIDEO_DESCRIPTION" "RCLONE_FILENAME" "RCLONE_DIR" "LOCAL_FILENAME")
TIME_DATE_CACHE=$($TIME_DATE) # We don't need to execute same command repeatedly
TIME_CLOCK_CACHE=$($TIME_CLOCK)
for var in "${variables[@]}"; do
original_var=original_$var
eval "$original_var=\$$var"
eval "replace_var=\$$var"
replace_var=${replace_var//TIME_DATE/$TIME_DATE_CACHE}
replace_var=${replace_var//TIME_CLOCK/$TIME_CLOCK_CACHE}
eval "$var=\$replace_var"
done

fetchMetadata() {
Expand Down Expand Up @@ -256,26 +262,40 @@ while true; do
;;

"local")
if [ "$RE_ENCODE" == "true" ]; then
echo "$($CC) Re-encoding stream"
if ! streamlink $STREAM_SOURCE_URL $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" --stdout | ffmpeg -i pipe:0 -c:v $RE_ENCODE_CODEC -crf $RE_ENCODE_CRF -preset $RE_ECODE_PRESET -hide_banner -loglevel $RE_ENCODE_LOG -f matroska $LOCAL_FILENAME >/dev/null 2>&1; then
echo "$($CC) ffmpeg failed re-encoding the stream"
else # If the stream was re-encoded
echo "$($CC) Stream re-encoded as $LOCAL_FILENAME"
TEMP_FILE=$(mktemp stream.XXXXXX)

if ! streamlink $STREAM_SOURCE_URL $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" -o - >$TEMP_FILE; then
echo "$($CC) streamlink failed saving the stream"
if [ "$SAVE_ON_FAIL" == "true" ] && [ "$(stat -c %b $TEMP_FILE)" != "0" ]; then
#? Save the temp file if rclone fails
NEW_LOCAL_FILENAME="${LOCAL_FILENAME}_failed.$LOCAL_EXTENSION"
mv "$TEMP_FILE" "$NEW_LOCAL_FILENAME" # Rename the local file
echo "$($CC) Local failed file renamed to $NEW_LOCAL_FILENAME"
fi
rm -f $TEMP_FILE
else
# If you just want to save the stream locally to your machine
if ! streamlink $STREAM_SOURCE_URL $STREAMLINK_OPTIONS "${STREAMLINK_FLAGS[@]}" -o - >"$LOCAL_FILENAME.$LOCAL_EXTENSION"; then
echo "$($CC) streamlink failed saving the stream to disk"
if [ "$SAVE_ON_FAIL" == "true" ]; then
#? Save the temp file if rclone fails
NEW_LOCAL_FILENAME="${LOCAL_FILENAME}_failed.$LOCAL_EXTENSION"
mv "$LOCAL_FILENAME.$LOCAL_EXTENSION" "$NEW_LOCAL_FILENAME" # Rename the local file
echo "$($CC) Local failed file renamed to $NEW_LOCAL_FILENAME"
if [ "$RE_ENCODE" == "true" ]; then
echo "$($CC) Re-encoding stream"
if ! ffmpeg -i "$TEMP_FILE" -c:v $RE_ENCODE_CODEC -crf $RE_ENCODE_CRF -preset $RE_ECODE_PRESET -hide_banner -loglevel $RE_ENCODE_LOG -f matroska $LOCAL_FILENAME >/dev/null 2>&1; then
echo "$($CC) ffmpeg failed re-encoding the stream"
else # If the stream was re-encoded
echo "$($CC) Stream re-encoded as $LOCAL_FILENAME"
fi
else
echo "$($CC) Stream saved to disk as $LOCAL_FILENAME.$LOCAL_EXTENSION"
TIME_DATE_CHECK=$($TIME_DATE)
# If you just want to save the stream locally to your machine
if ! mv "$TEMP_FILE" "$LOCAL_FILENAME.$LOCAL_EXTENSION"; then
echo "$($CC) failed to move temp file to disk." # May be disk R/O mode?
if [ "$SAVE_ON_FAIL" == "true" ]; then
# Failed to move. so, we cannot do anything :(
echo "$($CC) Local failed file renamed to $TEMP_FILE"
else
rm -f $TEMP_FILE
fi
else
echo "$($CC) Stream saved to disk as $LOCAL_FILENAME.$LOCAL_EXTENSION"
rm -f $TEMP_FILE
TIME_DATE_CHECK=$($TIME_DATE)
fi
fi
fi
;;
Expand Down
12 changes: 6 additions & 6 deletions default.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ API_URL="" #? API for fetching stream metadata. (e.g: https://example.com
STREAMER_TITLE="initial_title" #? The title of the stream. (This is only available if API_CALLS is set to true.) [! Do not change these values]
STREAMER_GAME="inital_game" #? The current game the user is playing. (This is only available if API_CALLS is set to true.) [! Do not change these values]
#? $STREAMER_NAME - The name of the streamer.
#? $($TIME_DATE) - The current date (day/month/year).
#? $($TIME_CLOCK) - The current time (hour:minute:second).
#? TIME_DATE - The current date (day/month/year).
#? TIME_CLOCK - The current time (hour:minute:second).

#* Streamlink settings (Valid for all upload providers)
STREAMLINK_QUALITY="best" #* Options: worst, 360p, 480p, 720p, 720p60, 1080p60, best
Expand All @@ -29,18 +29,18 @@ STREAMLINK_LOGS="error" #* Optio
VIDEO_DURATION="12:00:00" #? XX:XX:XX (Notice: YouTube has a upload limit of 12 hours per video).
SPLIT_INTO_PARTS="false" #? If you want to split the video into parts, set this to true. (if this is enabled VIDEO_DURATION is ignored).
SPLIT_VIDEO_DURATION="06:00:00" #? Set the duration of each part. (XX:XX:XX)
SAVE_ON_FAIL="false" #? If you want to save the video that failed to upload, set this to true.
SAVE_ON_FAIL="false" #? If you want to save the non-empty video that failed to upload, set this to true.

#* YouTube upload settings (Only valid if UPLOAD_SERVICE is set to youtube)
VIDEO_TITLE="$STREAMER_NAME - $($TIME_DATE)" #? Title of the video.
VIDEO_TITLE="$STREAMER_NAME - TIME_DATE" #? Title of the video.
VIDEO_DESCRIPTION="Uploaded using https://github.com/jenslys/AutoVOD" #? YouTube video description.
VIDEO_VISIBILITY="unlisted" #* Options: unlisted, private, public
VIDEO_PLAYLIST="$STREAMER_NAME VODs" #? Playlist to upload to.

#* Rclone upload settings (Only valid if UPLOAD_SERVICE is set to rclone)
RCLONE_REMOTE="remote-name" #? Rclone remote to upload to.
RCLONE_DIR="" #? Directory to upload to.
RCLONE_FILENAME="$STREAMER_NAME"_"$($TIME_DATE)" #? Filename of the video on the remote. (Dont use spaces in the filename, use dashes or undersores instead.)
RCLONE_FILENAME="$STREAMER_NAME"_"TIME_DATE" #? Filename of the video on the remote. (Dont use spaces in the filename, use dashes or undersores instead.)
RCLONE_FILEEXT="mkv" #? File extension of the video on the remote.

#* Re-Stream settings (Only valid if UPLOAD_SERVICE is set to restream)
Expand All @@ -51,7 +51,7 @@ AUDIO_CODEC="aac"
FILE_FORMAT="flv"

#* Local settings (Only valid if UPLOAD_SERVICE is set to local)
LOCAL_FILENAME="$STREAMER_NAME"_"$($TIME_DATE)" #? Filename/filepath of the local recording. (Dont use spaces in the filename, use dashes or undersores instead.)
LOCAL_FILENAME="$STREAMER_NAME"_"TIME_DATE" #? Filename/filepath of the local recording. (Dont use spaces in the filename, use dashes or undersores instead.)
LOCAL_EXTENSION="mkv" #? File extension of the local recording.

#* Re-Encoding settings (Currently only works if UPLOAD_SERVICE is set to rclone or local)
Expand Down

0 comments on commit 5d3ec69

Please sign in to comment.