From c8cfdcbe05809ab5e1b4f22003f8c29b6c80b5ca Mon Sep 17 00:00:00 2001 From: Leon Kowarschick Date: Mon, 4 May 2020 14:48:12 +0200 Subject: [PATCH] add theatron --- .../configstore/update-notifier-npm.json | 2 +- files/.config/qutebrowser/autoconfig.yml | 10 +- files/.config/qutebrowser/bookmarks/urls | 3 + files/.xmonad/.stack-work/stack.sqlite3 | Bin 561152 -> 561152 bytes files/.xmonad/lib/Config.hs | 2 + files/scripts/Theatron/.currently_playing | 2 + files/scripts/Theatron/bId.txt | 1 + files/scripts/Theatron/clipit | 23 ++ files/scripts/Theatron/config | 42 ++++ files/scripts/Theatron/oauth | 1 + files/scripts/Theatron/pollingservice | 35 +++ files/scripts/Theatron/simplewatch | 221 ++++++++++++++++++ files/scripts/showMappings.sh | 6 - files/scripts/tmuxAutocomplete.sh | 4 - 14 files changed, 333 insertions(+), 19 deletions(-) create mode 100644 files/scripts/Theatron/.currently_playing create mode 100644 files/scripts/Theatron/bId.txt create mode 100755 files/scripts/Theatron/clipit create mode 100644 files/scripts/Theatron/config create mode 100644 files/scripts/Theatron/oauth create mode 100755 files/scripts/Theatron/pollingservice create mode 100755 files/scripts/Theatron/simplewatch delete mode 100755 files/scripts/showMappings.sh delete mode 100755 files/scripts/tmuxAutocomplete.sh diff --git a/files/.config/configstore/update-notifier-npm.json b/files/.config/configstore/update-notifier-npm.json index 195e1ad..801ee5a 100644 --- a/files/.config/configstore/update-notifier-npm.json +++ b/files/.config/configstore/update-notifier-npm.json @@ -1,4 +1,4 @@ { "optOut": false, - "lastUpdateCheck": 1588333599760 + "lastUpdateCheck": 1588520574764 } \ No newline at end of file diff --git a/files/.config/qutebrowser/autoconfig.yml b/files/.config/qutebrowser/autoconfig.yml index afab373..ac827d3 100644 --- a/files/.config/qutebrowser/autoconfig.yml +++ b/files/.config/qutebrowser/autoconfig.yml @@ -6,11 +6,5 @@ config_version: 2 settings: - statusbar.widgets: - global: - - keypress - - url - - scroll - - history - - tabs - - progress + content.notifications: + https://www.reddit.com: false diff --git a/files/.config/qutebrowser/bookmarks/urls b/files/.config/qutebrowser/bookmarks/urls index 3e3e041..d3ceb22 100644 --- a/files/.config/qutebrowser/bookmarks/urls +++ b/files/.config/qutebrowser/bookmarks/urls @@ -10,3 +10,6 @@ https://github.com/rhysd/kiro-editor rhysd/kiro-editor: A terminal UTF-8 text ed http://brson.github.io/2016/11/30/starting-with-error-chain Starting a new Rust project right, with error-chain https://docs.google.com/document/d/1SH-B4BkypsOB69B9e5HbTmhrlEHNq5M6-nuqIDzzOW4/edit#heading=h.r7oinwx5vtl9 Lebenslauf 2020 - Google Docs https://github.com/elenapan/dotfiles elenapan/dotfiles: There is no place like ~/ +https://lebenslauf.com/?theme=Belleza&utm_source=tabellarischer-lebenslauf.net&utm_medium=button&utm_campaign=tabellarischer-lebenslauf.net&utm_content=template-page Lebenslauf für Bewerbung online schreiben + PDF +https://rust-unofficial.github.io/too-many-lists/index.html Introduction - Learning Rust With Entirely Too Many Linked Lists +https://wiki.haskell.org/GHC_optimisations#Fusion GHC optimisations - HaskellWiki diff --git a/files/.xmonad/.stack-work/stack.sqlite3 b/files/.xmonad/.stack-work/stack.sqlite3 index 9802c881b8885d9cf0202aee4358c7bc1fbedece..f06a0e1e6d1a1ade0e1d44e739be2e47d0d64ddd 100644 GIT binary patch delta 43 ycmZozpwzHHX@WFk#Y7or#)`&-)&$1Z1g6#m=GFw3)&$np1h&=$_N@sV3;F>=+76xo delta 43 ycmZozpwzHHX@WFk$wV1v#*)T_)&$1Z1g6#m=GFw3)&$np1h&=$_N@sV3;F><-VT-k diff --git a/files/.xmonad/lib/Config.hs b/files/.xmonad/lib/Config.hs index 34cfda1..e713073 100644 --- a/files/.xmonad/lib/Config.hs +++ b/files/.xmonad/lib/Config.hs @@ -186,6 +186,7 @@ myKeys = [ ("M-+", sendMessage zoomIn) -- programs , ("M-p", spawn myLauncher) , ("M-b", spawn myBrowser) + , ("M-C-p", spawn (myTerminal ++ " --class termite_floating -e fff")) , ("M-S-p", Rofi.showCombi (def { Rofi.theme = Rofi.bigTheme }) [ "drun", "window", "ssh" ]) , ("M-S-e", Rofi.showNormal (def { Rofi.theme = Rofi.bigTheme }) "emoji" ) , ("M-s", spawn $ scriptFile "rofi-search.sh") @@ -280,6 +281,7 @@ myManageHook = composeAll , appName =? "pavucontrol" --> ManageHelpers.doCenterFloat , className =? "mpv" --> ManageHelpers.doRectFloat (W.RationalRect 0.9 0.9 0.1 0.1) , title =? "Something" --> doFloat + , className =? "termite_floating" --> ManageHelpers.doRectFloat(W.RationalRect 0.2 0.2 0.6 0.6) -- , isFullscreen --> doF W.focusDown <+> doFullFloat , manageDocks , namedScratchpadManageHook scratchpads diff --git a/files/scripts/Theatron/.currently_playing b/files/scripts/Theatron/.currently_playing new file mode 100644 index 0000000..92b476c --- /dev/null +++ b/files/scripts/Theatron/.currently_playing @@ -0,0 +1,2 @@ +85484 +profaheil diff --git a/files/scripts/Theatron/bId.txt b/files/scripts/Theatron/bId.txt new file mode 100644 index 0000000..d86ca24 --- /dev/null +++ b/files/scripts/Theatron/bId.txt @@ -0,0 +1 @@ +136779932 diff --git a/files/scripts/Theatron/clipit b/files/scripts/Theatron/clipit new file mode 100755 index 0000000..3824e5f --- /dev/null +++ b/files/scripts/Theatron/clipit @@ -0,0 +1,23 @@ +#!/bin/bash +#Creates a clip of the currently watched streamer, opens the editor with xdg-open +#In case we're calling the clipit function without watching a stream first +cd $(dirname "$0") +config=$(readlink -f config) +source $config +oauth="$(cat oauth|tr -d '\n')" +broadcast_id=$(cat bId.txt) +clip=$(curl -s \ + -H "Client-ID: $client_id" \ + -H "Authorization: Bearer $oauth" \ + -X POST "https://api.twitch.tv/helix/clips?broadcaster_id=$broadcast_id" | jq -c '.data[] | {"":.edit_url}' | tr -d '\"\{\}') +if [[ -z $clip ]];then + notify-send "Theatron" "Either the streamer isn't online or you're not watching anyone" +fi + +#Delete the first character(:) +clip="${clip:1}" +xdg-open $clip +# vim: ft=sh +# + +#curl -H "Authorization: OAuth " https://id.twitch.tv/oauth2/validate diff --git a/files/scripts/Theatron/config b/files/scripts/Theatron/config new file mode 100644 index 0000000..12d8640 --- /dev/null +++ b/files/scripts/Theatron/config @@ -0,0 +1,42 @@ +#!/bin/bash +#dont ask for quality, always just run the best one, always worst might be implemented if anyone asks +always_best=false + +#The default player used by streamlink with the latest breakage of VLC we can't rely on it anymore :( +player="vlc" + +#The default application launcher, currently tested on: rofi, dmenu, smenu. Only use 1 at a time +#Works fine with fzf too, but needs to be launched in terminal to work +#For the main 3: +#launcher="rofi -dmenu" +#launcher="dmenu" +#launcher="smenu -t" +launcher="rofi -dmenu" +#if this is on, every time you pick a streamer, you will get vod menu after you pick a streamer, the first entry should still be the live stream +vod_mode=true + +# How many vods(filtered by recency) to show +vod_mode_limit="25" +# How many games you want to see in the list +game_limit="100" +# This will only be used for offline mode(flag -o) +following="imaqtpie\nsodapoppin\nforsen\nasmongold" + #if true, opens up a browser window with the chat popup mode of the picked streamer, does so not knowingly if the stream loaded or not +popup_chat=false +#set up custom streamlink flags +streamlink_flags="--player-continuous-http" +#If you want clip capatibilities, if you change this from false to true you will need a new token, easiest way to obtain it is to delete oauth file, because it requires elevated privileges +clip_capabilities=true +#browse_type_option_followed_channels="Channels you're following" +#browse_type_option_followed_games="Games you're following" +#browse_type_option_all_games="All games" + +#Set the browse type to skip being asked for it every time. Set it to empty to be asked. The options are above. +default_browse_type='' +#default_browse_type=$browse_type_option_followed_channels +#default_browse_type=$browse_type_option_followed_games +#default_browse_type=$browse_type_option_all_games + +#App settings, for global, don't change +client_id="fendbm5b5q1c2820m59sbdv9z95vs4" +redirect_uri="https://theatron.davidv7.xyz/" diff --git a/files/scripts/Theatron/oauth b/files/scripts/Theatron/oauth new file mode 100644 index 0000000..9a19a7a --- /dev/null +++ b/files/scripts/Theatron/oauth @@ -0,0 +1 @@ +zgwa0kdqqku8yowsgeneylvn9ia67z diff --git a/files/scripts/Theatron/pollingservice b/files/scripts/Theatron/pollingservice new file mode 100755 index 0000000..a7b0073 --- /dev/null +++ b/files/scripts/Theatron/pollingservice @@ -0,0 +1,35 @@ +#!/bin/bash +cd $(dirname "$0") +function poll(){ + id=$(curl -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H 'Client-ID: fendbm5b5q1c2820m59sbdv9z95vs4' \ + -X GET "https://api.twitch.tv/kraken/users?login=$notify_me" | jq -c '.users[] |._id'| tr -d '"' | tr '\n' ',') + live=$(curl -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H 'Client-ID: fendbm5b5q1c2820m59sbdv9z95vs4' \ + -X GET "https://api.twitch.tv/kraken/streams/?channel=$id" | jq -c '.streams[] | .channel | {"": .name , " playing " : .game , " " : .status}' | tr -d '\{\}\,\"\:' | awk '{print $0"\n"}') + echo "$live" + if [ -z "$live" ]; then + echo "No one is on" + else + notify-send -u critical "Theatron" "$live" + name=$(echo $live | awk '{print $1}') + notify_me="${notify_me//$name}" + echo $notify_me + fi + sleep $1 +} + +# The first argument is the interval +# If the first argument is once the there is no sleep because it only gets run once +# Hopw many seconds between checks + +# Add strings for people you want to be notified about, ex. notify_me="imaqtpie,reckful" +notify_me="reckful,imaqtpie,strawbunnyhunny,pokimane,sodapoppin,methodjosh,nerites,forsen,asmongold,disguisedtoast,avoidingthepuddle,cxlibri" +if [[ $1 == "once" ]];then + poll 0 +elif [[ -n $1 ]];then +while true +do + poll "$1" +done +fi diff --git a/files/scripts/Theatron/simplewatch b/files/scripts/Theatron/simplewatch new file mode 100755 index 0000000..6b646f4 --- /dev/null +++ b/files/scripts/Theatron/simplewatch @@ -0,0 +1,221 @@ +#!/bin/bash +#Thank you curli +getFollowingChannels() { + curl -s -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H "Client-ID: $client_id" \ + -H "Authorization: OAuth $oauth" \ + -X GET "https://api.twitch.tv/kraken/streams/followed" | + jq -c '.streams[] | {"":.channel | {"Streamer ": .name , " playing ": .game}, " for ": .viewers, " viewers ": .video_height}' | + tr -d '\{\}\:\"\,' | + awk '{print $0"p"}' + } + +getTwitchUserId() { + curl -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H "Client-ID: $client_id" \ + -H "Authorization: OAuth $oauth" \ + -X GET "https://api.twitch.tv/kraken/user" | + jq -c '. | ._id' | + tr -d '"' + } + +# First argument must be the twitch user id +getFollowingGames() { + curl -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H "Client-ID: $client_id" \ + -H "Authorization: OAuth $oauth" \ + -X GET "https://api.twitch.tv/kraken/users/${1}/follows/games" | + jq -c '.follows[] | {"": .game.popularity, " viewers - ": .game.name}' | + tr -d '\{\}\:\"\,' + } + +# First argument must be the game's name +getChannelsFromGame() { + curl -s -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H "Client-ID: $client_id" \ + -X GET "https://api.twitch.tv/kraken/streams?game=${1}" | + jq -c '.streams[] | {"":.channel | {"Streamer ": .name , " playing ": .game}, " for ": .viewers, " viewers ": .video_height}' | + tr -d '\{\}\:\"\,' | + awk '{print $0"p"}' + } + +getAllGames() { + curl -s -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H "Client-ID: $client_id" \ + -H "Authorization: OAuth $oauth" \ + -X GET "https://api.twitch.tv/kraken/games/top?limit=$game_limit" | + jq -c '.top[] | {"": .viewers, " viewers - ": .game.name}' | + tr -d '\{\}\:\"\,' + } +if [[ $1 == "-v" ]]; then + echo "0.9.0" + exit 0 +fi +cd $(dirname "$0") || exit + +source config + +quality="best\n1080p60\n1080p\n720p60\n720p\n480p\n360p\naudio_only" +oauth="$(cat oauth | tr -d '\n')" + +if [[ -z ${oauth} ]]; then + echo "ERROR: Missing oauth, use theatron -p if you want to enter private mode" + notify-send "Theatron" "Copy the token into a file called oauth" + if [[ ${clip_capabilities} == "true" ]]; then + scope="clips:edit+user_read" + auth_url="https://id.twitch.tv/oauth2/authorize?client_id=$client_id&redirect_uri=$redirect_uri&response_type=token&scope=$scope" + echo "Auth url" + echo ${auth_url} + xdg-open "$auth_url" + fi + exit 1 +fi + #Private mode +if [[ $1 == "-p" || $1 == "--private" ]]; then + echo "Entering private mode, check config for list of channels" + #TODO: Make it possible to enter token into rofi + channel="$(echo -e ${following} | ${launcher})" +else + # Check if user wants to see content he's following or not + if [[ ${default_browse_type} == '' ]]; then + browse_type_options="Channels you're following\nGames you're following\nAll games\nAll streams\nChange current stream quality or restart previous stream: $(tail -1 .currently_playing)" + browse_type=$(echo -e "$browse_type_options" | ${launcher}) + echo "Selected $browse_type" + else + browse_type=${default_browse_type} + fi + # If user wants to browse the channels they follow + if [[ ${browse_type} == "Games you're following" ]]; then + # Get the user id, which is needed to get the followed games + echo "Getting your user ID..." + user_id=$(getTwitchUserId) + if [[ -z ${user_id} ]]; then + notify-send "You need a new token, remove oauth file and restart the app" + exit 1 + fi + # Get the games the user is following, note: the amount of viewers does not reflect the live amount (delayed) + echo "Getting the games you follow..." + empty_games="You're not following any games, choose me to browse top games instead\nBrowse followed channels" + games=$(getFollowingGames ${user_id}) + if [[ -z ${games} ]]; then + games="$empty_games" + fi + game=$(echo -e "${games}" | ${launcher}) + if [[ -z ${game} ]]; then + exit 1 + fi + echo $game + if [[ ${game} == "You're not following any games, choose me to browse top channels instead" ]]; then + browse_type="All games" + if [[ ${game} == "Browse followed channels" ]]; then + browse_type="Channels you're following" + fi + else + game_name=$(echo ${game#*viewers - }) + game_formatted=$(echo ${game_name} | jq -s -R -r @uri | rev | cut -c4- | rev) + # Get the channels from the selected game + echo "Getting the channels from ${game_name}..." + channel=$(getChannelsFromGame ${game_formatted} | ${launcher}) + #Check for empty pick + if [[ -z ${channel} ]]; then + notify-send "You need to pick a channel..." + exit 1 + fi + fi + fi + if [[ ${browse_type} == "Channels you're following" ]]; then + # Get all the channels the user follows + channel=$(getFollowingChannels | ${launcher}) + if [[ -z $channel ]]; then + exit 1 + fi + fi + # If user wants to browse the games they follow + # If the user wants to browse every game on Twitch + # Changed from elif to support going from one browse type to another + if [[ ${browse_type} == "All games" ]]; then + # Get all the games (top X by most viewers) + # TODO: make more requests after the first 100 + echo 'Getting all games...' + game=$(getAllGames | ${launcher}) + if [[ -z ${game} ]]; then + notify-send "Selection cancelled" + exit 1 + fi + game_name=$(echo ${game#*viewers - }) + game_formatted=$(echo ${game_name} | jq -s -R -r @uri | rev | cut -c4- | rev) + # Get the channels from the selected game + echo "Getting the channels from ${game_name}..." + channel=$(getChannelsFromGame ${game_formatted} | ${launcher}) + fi + if [[ ${browse_type} == "All streams" ]]; then + channel=$(getChannelsFromGame | ${launcher}) + fi + + if [[ ${browse_type} == "Change current stream quality"* ]]; then + pid="$(head -n 1 .currently_playing)" + channel="$(tail -1 .currently_playing)" + echo "$channel with quality $picked_quality" + echo "Killing existing ... $pid" + kill $pid + rm .currently_playing + fi + + not_following=$(echo ${channel} | awk '{print $2}') + if [[ -n ${not_following} ]]; then + channel=${not_following} + fi + if [[ -z ${channel} ]]; then + exit 1 + fi +fi +if [[ -z ${channel} ]]; then + exit 1 + notify-send "Theatron" "Didn't pick anything" +fi +if [[ ${vod_mode} == "true" ]]; then + #čšć is used to sanitize output easier, so we don't remove every : but only the json key:value colon + id=$(curl -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H "Client-ID: $client_id" \ + -X GET "https://api.twitch.tv/kraken/users?login=$channel" | + jq -c '.users[] | ._id' | tr -d '"') \ + live=$(curl -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H "Client-ID: $client_id" \ + -X GET "https://api.twitch.tv/kraken/streams/$id" | + jq -r '.stream') + + if [[ ${live} != "null"* ]]; then + live="Channel is live, click me to watch" + else + live="Channel is not yet live, use polling service and wait :( " + fi + echo "$id" >bId.txt + #Use ćšć as unique identifiers of what values are and what the keys are + video=$(curl -H 'Accept: application/vnd.twitchtv.v5+json' \ + -H "Client-ID: $client_id" \ + -X GET "https://api.twitch.tv/kraken/channels/$id/videos?limit=$vod_mode_limit" | + jq -c --unbuffered '.videos[] | {"čšć" : .title, " (čšć": .created_at, ") čšć": .url}' | + tr -d '\{\}\"\,' | sed 's/čšć://g' | + printf "%s\n%s" "$live" "$(cat -)" | ${launcher} | awk 'NF>0{print $NF}') + + # Exit if no selection + if [[ -z ${video} ]]; then + exit 1 + fi + +fi +picked_quality="best" +if [[ ${always_best} == "false" ]]; then + picked_quality="$(echo -e ${quality} | ${launcher})" +fi +if [[ ${popup_chat} == "true" || $1 == "-p" ]]; then + xdg-open https://www.twitch.tv/popout/${channel}/chat?popout= +fi +if [[ -z ${channel} ]]; then + echo "No channel picked." + exit 1 +else + streamlink https://www.twitch.tv/${channel} ${picked_quality} --player=mpv ${streamlink_flags} & + echo -e "$!\n${channel}" >.currently_playing +fi +# vim: ft=sh diff --git a/files/scripts/showMappings.sh b/files/scripts/showMappings.sh deleted file mode 100755 index 4a66816..0000000 --- a/files/scripts/showMappings.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/dash - -cat ~/.xmonad/lib/Config.hs \ - | awk '/myKeys = \[/,/\] \+\+ generatedMappings.*/' \ - | sed 's/myKeys = \[ (\|\].*generatedMappings.*//g' \ - | sed 's/^\s*, \?(\|)//g' diff --git a/files/scripts/tmuxAutocomplete.sh b/files/scripts/tmuxAutocomplete.sh deleted file mode 100755 index 076812d..0000000 --- a/files/scripts/tmuxAutocomplete.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -while read -r input; do - echo $input | sed 's/\s\+/\n/g' | sed -n '/.\{5\}.\+/p' -done | fzf --height 10 | tr -d '\n' | xargs tmux send-keys