summaryrefslogtreecommitdiff
path: root/util/twitch.cr
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@action.fairlystable.org>2024-01-14 01:03:09 -0800
committerJoe Rayhawk <jrayhawk@fairlystable.org>2024-01-14 01:06:31 -0800
commite9b6b9695212cebdfa8f94c1a05cad5d54511043 (patch)
tree8b9733c71fc1458d71e55cabfd0187fd622d6efb /util/twitch.cr
parentd5858e2ef8f382b9e53308301ff7c7df3bf4b745 (diff)
downloadtwitcr-e9b6b9695212cebdfa8f94c1a05cad5d54511043.tar.gz
twitcr-e9b6b9695212cebdfa8f94c1a05cad5d54511043.zip
Attempt to modernize followers/followees APIHEADmaster
Signed-off-by: Joe Rayhawk <jrayhawk@fairlystable.org>
Diffstat (limited to 'util/twitch.cr')
-rw-r--r--util/twitch.cr50
1 files changed, 34 insertions, 16 deletions
diff --git a/util/twitch.cr b/util/twitch.cr
index 43980d0..32c79f1 100644
--- a/util/twitch.cr
+++ b/util/twitch.cr
@@ -60,7 +60,9 @@ when "clips"
when "game"
pp JSON.parse( client.get_games( ARGV[1].to_u64? || ARGV[1] ) )
when "streams"
- if ARGV[1]?
+ if ARGV[2]?
+ list_streams( settings, JSON.parse( client.get_streams( game_id = client.game_id( ARGV[1] ), ARGV[2] ) ) )
+ elsif ARGV[1]?
list_streams( settings, JSON.parse( client.get_streams( game_id = client.game_id( ARGV[1] ) ) ) )
else
list_streams( settings, JSON.parse( client.get_streams() ) )
@@ -186,9 +188,11 @@ def list_user_followees( settings, client )
# format overhead
foh = format.delete( "^ " ).size
- follows = JSON.parse( client.get_user_follows( from: id ) )["data"]
+ follows = JSON.parse( client.get_channels_followed( from: id ) )
- followsuids = follows.as_a.map { |follow| follow["to_id"].as_s.to_u64 }
+ pp follows
+
+ followsuids = follows["data"].as_a.map { |follow| follow["broadcaster_id"].as_s.to_u64 }
streams = Hash( UInt64, JSON::Any ).new
channels = Hash( UInt64, JSON::Any ).new
@@ -206,9 +210,9 @@ def list_user_followees( settings, client )
users[ user["id"].as_s.to_u64 ] = user
end
- follows.as_a.each do |follow|
+ follows["data"].as_a.each do |follow|
- uid = follow["to_id"].as_s.to_u64
+ uid = follow["broadcaster_id"].as_s.to_u64
channel = ( channels[uid]? || JSON.parse( "{}" ) )
stream = ( streams[uid]? || JSON.parse( "{}" ) )
@@ -219,7 +223,7 @@ def list_user_followees( settings, client )
begin
printf( format,
*fcell( follow["followed_at"]?.to_s ),
- *fcell( follow["to_login"]?.to_s ),
+ *fcell( follow["broadcaster_login"]?.to_s ),
*fcell( stream["viewer_count"]?.to_s ),
#*fcell( channel["followers"]?.to_s ),
*fcell( user["view_count"]?.to_s ),
@@ -236,10 +240,10 @@ def list_user_followees( settings, client )
pp user
end
- pp follows["pagination"]
-
end
+ pp follows["pagination"]
+
end
def list_user_followers( settings, client )
@@ -257,15 +261,29 @@ def list_user_followers( settings, client )
# format overhead
foh = format.delete( "^ " ).size
- puts( "\nLast 100 followers:\n" )
if ARGV.size > 2
- followersjson = JSON.parse( client.get_user_follows( to: id, after: ARGV[2] ) )
+ followersjson = JSON.parse( client.get_channel_followers( to: id, after: ARGV[2] ) )
else
- followersjson = JSON.parse( client.get_user_follows( to: id ) )
+ followersjson = JSON.parse( client.get_channel_followers( to: id ) )
+ end
+
+ total = followersjson["total"].as_i
+ puts( "Total followers: " + total.to_s )
+
+ if ( total == 0 )
+ puts( "No followers." )
+ return
+ end
+
+ puts( "\nLast 100 followers:\n" )
+ followers = followersjson["data"].as_a
+ if followers.empty?
+ puts( "Empty list. Missing moderator:read:followers scope." )
+ return
end
- followers = followersjson["data"]
- followersuids = followers.as_a.map { |follow| follow["from_id"].as_s.to_u64 }
+
+ followersuids = followers.map { |follow| follow["user_id"].as_s.to_u64 }
streams = Hash( UInt64, JSON::Any ).new
channels = Hash( UInt64, JSON::Any ).new
@@ -283,7 +301,7 @@ def list_user_followers( settings, client )
users[ user["id"].as_s.to_u64 ] = user
end
- followers.as_a.each do |follow|
+ followers.each do |follow|
uid = follow["from_id"].as_s.to_u64
@@ -435,11 +453,11 @@ def list_streams( settings, response )
begin
printf( format,
- *fcell( "twitch.tv/#{stream["user_name"].to_s}" ),
+ *fcell( "twitch.tv/#{stream["user_login"].to_s}" ),
*fcell( stream["type"].as_s[0].to_s ),
*fcell( stream["viewer_count"].as_i.to_s ),
#*fcell( stream["channel"]["followers"].as_i.to_s ),
- *fcell( stream["game_id"].as_s ),
+ *fcell( stream["game_name"].as_s ),
*fcell( stream["title"].to_s ),
)
rescue