feat: better config loading

This commit is contained in:
coolnsx
2023-10-06 16:53:16 +05:30
parent 409b372560
commit 95471a8bd8

20
screen
View File

@@ -13,7 +13,7 @@ menu() {
compress() {
duration=$(ffprobe -hide_banner -i "$tmp_file" 2>&1 | sed -nE 's|.*Duration: ([^,]*).*|\1|p')
i=19
i=20
while :; do
ffmpeg -loglevel error -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -i "$tmp_file" -vf 'format=nv12,hwupload' -c:v h264_vaapi -qp "$i" "$process_file" -y -progress - | while read -r line; do
@@ -61,20 +61,32 @@ stop() {
;;
*nextcloud)
info "icloud" "" "Uploading to NextCloud"
#shellcheck disable=SC1091
. "$HOME"/.secrets
#load nextcloud creds only
load_nextcloud_creds
cloudname="screenrecord-$(date +"%F_%H-%M-%S").mp4"
#upload to nextcloud instance, universal code
curl -s "$NC_HOST/remote.php/dav/files/${NC_USER}${NC_FOLDER_PATH}/$cloudname" -u "$NC_USER:$NC_PASS" -T "$tmp_file" && curl -u "$NC_USER:$NC_PASS" "$NC_HOST/ocs/v2.php/apps/files_sharing/api/v1/shares" -H 'content-type: application/json' -H 'accept: application/json, text/plain, */*' -H 'OCS-APIRequest: true' --data-raw "{\"path\":\"${NC_FOLDER_PATH}/$cloudname\",\"shareType\":3,\"attributes\":\"[]\"}" | sed -nE 's|.*"url":"([^"]*)".*|\1|p' | sed 's/\\//g' | wl-copy && info "com.github.davidmhewitt.clipped" "2000" "uploaded and copied link to clipboard" && return 0
info "" "2000" "Unable to upload to Nextcloud,moved the file from temp to your home folder as <unix_timestamp>.mp4" && mv "$tmp_file" "$HOME/$(date +%s).mp4" && return 1
info "nextcloud" "10000" "Uploading to NextCloud"
curl -s "$NC_HOST/remote.php/dav/files/${NC_USER}${NC_FOLDER_PATH}/$cloudname" -H "Authorization: Basic $NC_AUTH" -T "$tmp_file" || (info "" "2000" "Unable to upload to Nextcloud,moved the file from temp to your home folder as $cloudname" && mv "$tmp_file" "$HOME/$cloudname" && return 1)
info "nextcloud" "" "Getting File Id"
file_id=$(curl -s "$NC_HOST/remote.php/dav/files/${NC_USER}${NC_FOLDER_PATH}" -X 'PROPFIND' -H "Authorization: Basic $NC_AUTH" --data-raw '<?xml version="1.0"?><d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns" xmlns:ocs="http://open-collaboration-services.org/ns"><d:prop><oc:fileid /><nc:system-tags /></d:prop></d:propfind>' | sed 's|d:response|\n|g' | sed -nE "s|.*<d:href>.*$cloudname.*<oc:fileid>([^<]*).*|\1|p" | head -1)
[ "$file_id" = "$NC_FOLDER_ID" ] && file_id=""
info "nextcloud" "10000" "Setting Retention Policy & Generating Share Link"
curl -sX PUT "$NC_HOST/remote.php/dav/systemtags-relations/files/$file_id/1" -H "Authorization: Basic $NC_AUTH" -: -s -H "Authorization: Basic $NC_AUTH" "$NC_HOST/ocs/v2.php/apps/files_sharing/api/v1/shares" -H 'content-type: application/json' -H 'accept: application/json, text/plain, */*' -H 'OCS-APIRequest: true' --data-raw "{\"path\":\"${NC_FOLDER_PATH}/$cloudname\",\"shareType\":3,\"attributes\":\"[]\"}" | sed -nE 's|.*"url":"([^"]*)".*|\1|p' | sed 's/\\//g' | wl-copy && info "com.github.davidmhewitt.clipped" "2000" "Share Link Created and copied to clipboard"
;;
*discord)
#shellcheck disable=SC1091
. "$HOME"/.secrets
#load discord creds only
load_discord_creds
base_url="https://discord.com/api/v10"
channel=$(curl -s "$base_url/guilds/$SERVER_ID/channels" -H "Authorization: $TOKEN" | tr '{}' '\n' | sed -nE 's|.*"id":"([^"]*)".*last_message_id.*"name":"([^"]*)".*|\1\t\2|p' | menu "Select Channel: ")