moved twitch scripts to their own repo

This commit is contained in:
celso 2023-10-02 02:00:20 -03:00
parent 8245712ab8
commit 7ac16ccd43
2 changed files with 0 additions and 60 deletions

View File

@ -1,29 +0,0 @@
#!/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

View File

@ -1,31 +0,0 @@
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()