From 9a0a747dc0592e57ffd50649312cd1fa50f8b2f1 Mon Sep 17 00:00:00 2001 From: celso Date: Fri, 24 Mar 2023 14:40:17 -0300 Subject: [PATCH] initial commit --- brightness.sh | 7 +++++++ prtscr/prtscra.sh | 2 ++ prtscr/prtscrcr.sh | 2 ++ prtscr/prtscrsel.sh | 2 ++ screc/audiorec.sh | 3 +++ screc/fbufferrec.sh | 14 ++++++++++++++ screc/screenrecord.sh | 14 ++++++++++++++ screc/screenrecordnoa.sh | 13 +++++++++++++ sleepytime.sh | 10 ++++++++++ speedstep.py | 28 ++++++++++++++++++++++++++++ streams.sh | 2 ++ twitch/gettwurl.sh | 29 +++++++++++++++++++++++++++++ twitch/twitch-getvideo.py | 31 +++++++++++++++++++++++++++++++ xsetroot/sysstatus.sh | 12 ++++++++++++ xsetroot/wallpaper.sh | 5 +++++ xsetroot/xsetroot.sh | 34 ++++++++++++++++++++++++++++++++++ 16 files changed, 208 insertions(+) create mode 100755 brightness.sh create mode 100755 prtscr/prtscra.sh create mode 100755 prtscr/prtscrcr.sh create mode 100755 prtscr/prtscrsel.sh create mode 100755 screc/audiorec.sh create mode 100755 screc/fbufferrec.sh create mode 100755 screc/screenrecord.sh create mode 100755 screc/screenrecordnoa.sh create mode 100755 sleepytime.sh create mode 100644 speedstep.py create mode 100755 streams.sh create mode 100755 twitch/gettwurl.sh create mode 100644 twitch/twitch-getvideo.py create mode 100755 xsetroot/sysstatus.sh create mode 100755 xsetroot/wallpaper.sh create mode 100755 xsetroot/xsetroot.sh diff --git a/brightness.sh b/brightness.sh new file mode 100755 index 0000000..d3d60e6 --- /dev/null +++ b/brightness.sh @@ -0,0 +1,7 @@ +#!/bin/bash +printf "%s" "${1}" | grep "^-\?[0-9.]\+$">/dev/null || exit 1 +curval="$(xrandr --verbose | grep -o "Brightness: [0-9.]\+" | grep -o "[0-9.]\+")" +[ $(bc -l <<< "scale=1;${curval}>=0.3") -eq 1 ] &&\ + [ $(bc -l <<< "scale=1;${curval}<=2") -eq 1 ]\ + && curval="$(bc -l <<< "scale=1;${curval}+${1}")" +xrandr --output LVDS1 --brightness "${curval}" diff --git a/prtscr/prtscra.sh b/prtscr/prtscra.sh new file mode 100755 index 0000000..29b927e --- /dev/null +++ b/prtscr/prtscra.sh @@ -0,0 +1,2 @@ +#!/bin/bash +import -window root -quality 00 png:- | xclip -selection clipboard -t image/png diff --git a/prtscr/prtscrcr.sh b/prtscr/prtscrcr.sh new file mode 100755 index 0000000..37324c0 --- /dev/null +++ b/prtscr/prtscrcr.sh @@ -0,0 +1,2 @@ +#!/bin/bash +import -window $(xprop -root _NET_ACTIVE_WINDOW | awk '{print $5}') -quality 00 png:- | xclip -selection clipboard -t image/png diff --git a/prtscr/prtscrsel.sh b/prtscr/prtscrsel.sh new file mode 100755 index 0000000..dd581d3 --- /dev/null +++ b/prtscr/prtscrsel.sh @@ -0,0 +1,2 @@ +#!/bin/bash +import -quality 00 png:- | xclip -selection clipboard -t image/png diff --git a/screc/audiorec.sh b/screc/audiorec.sh new file mode 100755 index 0000000..31e840a --- /dev/null +++ b/screc/audiorec.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +ffmpeg -loglevel error -threads 4 -f alsa -probesize 10M -channels 2 -sample_rate 48000 -thread_queue_size 2048 -i default /tmp/raw.wav diff --git a/screc/fbufferrec.sh b/screc/fbufferrec.sh new file mode 100755 index 0000000..ef8bce0 --- /dev/null +++ b/screc/fbufferrec.sh @@ -0,0 +1,14 @@ +#!/bin/bash +fps="25" +bitrate="3000k" +read -p 'type in filename >' filename +if [ -z "$filename" ]; +then +filename="test" +fi +#ffmpeg -hide_banner -threads 4 -f fbdev -i /dev/fb0 /tmp/$filename +ffmpeg -hide_banner -threads:0 3 -threads:1 1 \ +-f fbdev -probesize 42M -framerate $fps -thread_queue_size 1024 -i /dev/fb0 \ +-f alsa -probesize 10M -channels 2 -sample_rate 48000 -thread_queue_size 1024 -i default \ +-c:v libopenh264 -allow_skip_frames true -b:v $bitrate \ +-c:a aac -af asetpts=N/SR/TB /tmp/$filename.mp4 diff --git a/screc/screenrecord.sh b/screc/screenrecord.sh new file mode 100755 index 0000000..4bf5742 --- /dev/null +++ b/screc/screenrecord.sh @@ -0,0 +1,14 @@ +#!/bin/bash +inres="1366x768" +fps="25" +bitrate="3000k" +read -p 'type in filename >' filename +if [ -z "$filename" ]; +then +filename="test" +fi +ffmpeg -threads:0 3 -threads:1 1 \ +-f x11grab -probesize 42M -video_size $inres -framerate $fps -thread_queue_size 1024 -i :0.0 \ +-f alsa -probesize 10M -channels 2 -sample_rate 48000 -thread_queue_size 1024 -i default \ +-c:v libopenh264 -allow_skip_frames true -b:v $bitrate \ +-c:a aac -af asetpts=N/SR/TB /tmp/$filename.mp4 diff --git a/screc/screenrecordnoa.sh b/screc/screenrecordnoa.sh new file mode 100755 index 0000000..0f5cfce --- /dev/null +++ b/screc/screenrecordnoa.sh @@ -0,0 +1,13 @@ +#!/bin/bash +inres="1366x768" +fps="30" +bitrate="3000k" +read -p 'type in filename >' filename +if [ -z "$filename" ]; +then +filename="test" +fi +ffmpeg -hide_banner -threads:0 3 -threads:1 1 \ +-f x11grab -probesize 42M -video_size $inres -framerate $fps -thread_queue_size 1024 -i :0.0 \ +-c:v libopenh264 -allow_skip_frames true -b:v $bitrate \ +/tmp/$filename.mp4 diff --git a/sleepytime.sh b/sleepytime.sh new file mode 100755 index 0000000..c8c841e --- /dev/null +++ b/sleepytime.sh @@ -0,0 +1,10 @@ +#!/bin/bash +usagemsg="usage: sleepytime.sh [time in seconds]\n%7ssleepytime.sh resume\n\nrequires read/write \ +access to /tmp\nmake sure you only have one video player open or only the first one will be paused!\n" +pid=$(ps -aux | awk '{print $11" "$2}' | grep -m 1 "^mpv\|^vlc" | grep -o "[0-9]*") +printf "%d" "${pid}" > /tmp/sleepytime_pid +[ "$1" == "resume" ] && kill -SIGCONT $(cat /tmp/sleepytime_pid) && rm /tmp/sleepytime_pid && exit 0 +printf "%d" "$1" 1>/dev/null 2>&1; [ "${?}" != 0 ] && printf "error: not a number\n${usagemsg}" && exit 2 +sleepytime="${1:-1800}" +target_time=$(expr $(date +%s) + "${sleepytime}" ); +while [ $(date +%s) -le "${target_time}" ]; do sleep 10; done; kill -SIGTSTP "${pid}" diff --git a/speedstep.py b/speedstep.py new file mode 100644 index 0000000..5da70bf --- /dev/null +++ b/speedstep.py @@ -0,0 +1,28 @@ +import os +import subprocess +import time +# available frequency steps: 2.53 GHz, 2.39 GHz, 2.26 GHz, 2.13 GHz, 2.00 GHz, 1.86 GHz, 1.73 GHz, 1.60 GHz, 1.46 GHz, 931 MHz +actual_values=["2.53GHz", "2.40GHz", "2.27GHz", "2.13GHz", "2.00GHz", "1.87GHz", "1.73GHz", "1.60GHz", "1.47GHz", "931MHz"] +steps=["2.53GHz", "2,39GHz", "2.26GHz", "2.13GHz", "2.00GHz", "1.86GHz", "1.73GHz", "1.60GHz", "1.46GHz", "931MHz"] +curstep=0 + +# the command to change max frequency is cpupower frequency-set -u states.get(key) +# the command to get current freq is sudo cpupower frequency-info -wm | awk '{print $4}' | grep "\S" + +while True: + # step down as long as temp is above 82ºC + if int(subprocess.getoutput('cat /sys/class/thermal/thermal_zone0/temp'))>=82000 and subprocess.getoutput('sudo cpupower frequency-info -wm | awk \'{print $4 $5}\' | grep "\S"')!=steps[9]: + curstep=curstep+1 + print("changing frequency to %s" % steps[curstep]) + os.system('sudo cpupower frequency-set -u %s' % actual_values[curstep]) + #subprocess.run('sudo cpupower frequency-set -u %s' % actual_values[curstep]) + time.sleep(1) + # step up as long as temp is below 70ºC + if int(subprocess.getoutput('cat /sys/class/thermal/thermal_zone0/temp'))<=70000 and subprocess.getoutput('sudo cpupower frequency-info -wm | awk \'{print $4 $5}\' | grep "\S"')!=steps[0]: + curstep=curstep-1 + print("changing frequency to %s" % steps[curstep]) + os.system('sudo cpupower frequency-set -u %s' % actual_values[curstep]) + #subprocess.run('sudo cpupower frequency-set -u %s' % actual_values[curstep]) + time.sleep(1) + # wait a second before completing loop + time.sleep(1) diff --git a/streams.sh b/streams.sh new file mode 100755 index 0000000..eb85844 --- /dev/null +++ b/streams.sh @@ -0,0 +1,2 @@ +#!/bin/bash +streamlink $(xclip -selection clipboard -o) || mpv $(xclip -selection clipboard -o) diff --git a/twitch/gettwurl.sh b/twitch/gettwurl.sh new file mode 100755 index 0000000..fdc5a30 --- /dev/null +++ b/twitch/gettwurl.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# twitch api credentials +client_id="ib8heiflx9p0u12j9p5wybh6wjnhn2" +client_secret="u3ieq39z3e7lo1ewb69l9oueexxe2l" +grant_type="client_credentials" + +# get access token +access_token=$(curl -s -X POST https://id.twitch.tv/oauth2/token -d "client_id=$client_id" -d "client_secret=$client_secret" -d "grant_type=$grant_type" | awk -F '[\"\"|:|,]' '{print $5}') +read -p 'type in username >' login + +# get user id +user_id=$(curl -s -X GET "https://api.twitch.tv/helix/users?login=$login" -H "Authorization: Bearer $access_token" -H "client-id: $client_id" | awk -F '[\"\"|:|,]' '{print $8}') + +# save json with first page of results for videos tied to the user id we just got +curl -s -X GET "https://api.twitch.tv/helix/videos?user_id=$user_id" -H "Authorization: Bearer $access_token" -H "client-id: $client_id" > /tmp/streamarchives.txt + +# loop through the json +range=$(grep -Po "url\":\"[a-zA-Z0-9 \\+|\!#\$@.\-\[\]{}=,*/<>_:'()]+\"" /tmp/streamarchives.txt | awk 'BEGIN {FS="\""} END{print NR}') +for x in $(eval echo "{1..$range}"); do + titles=$(echo -e $(cat /tmp/streamarchives.txt) | grep -Po "title\":\"[a-zA-Z0-9 %\\+|\!#\$@.\-\[\]{}=,*/<>_:'()]+\"" | awk -v x=$x 'BEGIN{FS="\""} FNR==x {print $3}') + url=$(grep -Po "url\":\"[a-zA-Z0-9 \\+|\!#\$@.\-\[\]{}=,*/<>_:'()]+\"" /tmp/streamarchives.txt | awk -v x=$x 'BEGIN{FS="\""} FNR==x {print $3}') + duration=$(grep -Po "duration\":\"[a-zA-Z0-9 %\\+|\!#\$@.\-\[\]{}=,*/<>_:'()]+\"" /tmp/streamarchives.txt | awk -v x=$x 'BEGIN{FS="\""} FNR==x {print $3}') + #echo "$url $duration $titles" + echo "$x $titles $duration" >> /tmp/titles.txt +done +#read -p "choose a vid for clipboard or leave empty to quit >" choice +choice=$(cat /tmp/titles.txt | dmenu -c -l 10 -bw 3 | awk '{print $1}') && rm /tmp/titles.txt +[ -z $choice ] && exit || grep -Po "url\":\"[a-zA-Z0-9 \\+|\!#\$@.\-\[\]{}=,*/<>_:'()]+\"" /tmp/streamarchives.txt | awk -v choice=$choice 'BEGIN {FS="\""} FNR==choice {print $3}' | xclip -r -selection clipboard && rm /tmp/streamarchives.txt diff --git a/twitch/twitch-getvideo.py b/twitch/twitch-getvideo.py new file mode 100644 index 0000000..553621c --- /dev/null +++ b/twitch/twitch-getvideo.py @@ -0,0 +1,31 @@ +from requests import * +import os + +def titles(jsonwithids): + """gets the value of the key 'title' of the first 5 items in the json dict, adds them to a list and returns that list""" + titles=[] + durations=[] + for x in range(5): + titles.append(jsonwithids[x].get('title')) + durations.append(jsonwithids[x].get('duration')) + return titles, durations + +def choice(titles, durations): + """prints the titles and prompts the user to choose one, returns the choice as a number from 0 to 4""" + for x in range(5): + print(titles[x], durations[x]) + choice=int(input('Type a number from 1 to 5 to choose video >'))-1 + return choice + +def main(): + """runs the program""" + params1={'client_id':'ib8heiflx9p0u12j9p5wybh6wjnhn2', 'client_secret':'u3ieq39z3e7lo1ewb69l9oueexxe2l', 'grant_type':'client_credentials'} + access_token=post('https://id.twitch.tv/oauth2/token', params=params1).json().get('access_token') + heads={'Authorization':'Bearer %s'% access_token,'client-id':params1.get('client_id')} + user_id=get('https://api.twitch.tv/helix/users', params={'login':input('Type in the channel name >')}, headers=heads).json().get('data')[0].get('id') + lastvideos=get('https://api.twitch.tv/helix/videos', params={'user_id':user_id}, headers=heads).json().get('data') + a,b=titles(lastvideos) + os.system('streamlink '+lastvideos[choice(a,b)].get('url')+'?t='+input('Type time in xhxmxs format (optional)>')+' 720p60,720p') + +if __name__ == '__main__': + main() diff --git a/xsetroot/sysstatus.sh b/xsetroot/sysstatus.sh new file mode 100755 index 0000000..dd1bc97 --- /dev/null +++ b/xsetroot/sysstatus.sh @@ -0,0 +1,12 @@ +clear +while true; do + curtime=$(date +%T) + curdate=$(date +'%a %d/%m') + curtemp=$(bc -l <<< "scale = 1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000") + curfreq=$(sudo cpupower frequency-info -wm | awk {'print $4 $5'} | grep "\S") + curram=$(free -h | grep Mem | awk '{print $3"/"$2}') + status="$curram - $curtempºC - @$curfreq - $curdate $curtime" + printf "%s" "${status}" + for (( i=0; i<="${#status}"; i++ )) ; do printf "\b"; done + sleep 1 +done diff --git a/xsetroot/wallpaper.sh b/xsetroot/wallpaper.sh new file mode 100755 index 0000000..adf8733 --- /dev/null +++ b/xsetroot/wallpaper.sh @@ -0,0 +1,5 @@ +#! /bin/bash +while :;do +feh --bg-max --randomize /home/celso/.config/wallpapers/ +sleep 3600 +done diff --git a/xsetroot/xsetroot.sh b/xsetroot/xsetroot.sh new file mode 100755 index 0000000..d13082f --- /dev/null +++ b/xsetroot/xsetroot.sh @@ -0,0 +1,34 @@ +## ICONS FOR FUTURE VERSION +##  wi fi +while true; do + curtime="$(date +%T)" + curtimeicon="" + curdate="$(date +'%a %d/%m')" + curtemp="$(bc -l <<< "scale = 1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000")" + curfreq="$(bc -l <<< "scale=2; ($(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq) + 5000) / 1000000")" + vol="$(amixer get Master)" + curvol=$(awk '{FS="[][]"} {print $2}' <<< "${vol}" | grep -o "[0-9]*") + curvolstatus=$(awk '{FS="[][]"} {print $6}' <<< "${vol}" | grep "\S") + curram="$(free -h | grep Mem | awk '{print $3"/"$2}')" + curramicon="" + mhz="$(bc -l <<< "${curfreq} < 1")" + if [ ${mhz} -eq 1 ]; then + curfreq="$(printf "%0.f\n" $(bc -l <<< "0.93 * 1000"))" + curfreq_suffix="MHz" + else + curfreq_suffix="GHz" + fi + if [ $curvol -ge 51 ]; then + curvolicon="" + elif [ $curvol -lt 51 ] && [ $curvol -gt 0 ]; then + curvolicon="" + else + curvolicon="" + fi + if [ $curvolstatus != "on" ]; then + curvolicon="" + fi + rootname="${curramicon} ${curram} - ${curtemp}º - @${curfreq} ${curfreq_suffix} - ${curvolicon} ${curvol}% - ${curdate} ${curtimeicon} ${curtime}" + xsetroot -name "${rootname}" + sleep 0.9 +done