summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@omgwallhack.org>2016-12-30 23:57:29 -0800
committerJoe Rayhawk <jrayhawk@omgwallhack.org>2016-12-30 23:57:29 -0800
commitcd36aae70b76c0017c30c435a7754920108b7e5b (patch)
tree4b321f111a20a95c04b35a6c8571a38866be74b4
parent6763a63e7a2341098ceeaf9b200cdf9b3041ce94 (diff)
downloadtwitchtools-cd36aae70b76c0017c30c435a7754920108b7e5b.tar.gz
twitchtools-cd36aae70b76c0017c30c435a7754920108b7e5b.zip
lstwitchvid.rb: add client_id
-rwxr-xr-xlstwitchvid.rb22
1 files changed, 15 insertions, 7 deletions
diff --git a/lstwitchvid.rb b/lstwitchvid.rb
index c0b89fd..c8dd7b5 100755
--- a/lstwitchvid.rb
+++ b/lstwitchvid.rb
@@ -10,6 +10,12 @@ user = URI.escape(ARGV[0])
broadcasts = String.new
+confdir = Dir.home + '/.config/twitch/'
+ENV['APPDATA'] && confdir = ENV['APPDATA'] + "\\twitch\\"
+ENV['XDG_CONFIG_HOME'] && confdir = ENV['XDG_CONFIG_HOME'] + '/twitch/'
+
+client_id = IO.read( confdir + 'client_id' ).chomp
+
http = Net::HTTP.new('api.twitch.tv', 443)
http.use_ssl = true
#http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -21,18 +27,20 @@ if width < 97
width=97
end
-def videos(http, path, width, broadcasts)
+def videos(http, path, width, broadcasts, client_id)
total = 100
offset = 0
while offset <= total
- response = JSON.parse(http.request(Net::HTTP::Get.new("#{path}?limit=100&offset=#{offset}&broadcasts=#{broadcasts}")).body)
+ response = JSON.parse(http.request(Net::HTTP::Get.new("#{path}?limit=100&offset=#{offset}&broadcasts=#{broadcasts}&client_id=#{client_id}")).body)
+ if response['videos']
total = response['_total']
- for video in response['videos']
- printf( "%-45s %6i %6i %-36s %-.#{width-46-37-7-7}s\n", video['url'].to_s, video['length'].to_i, video['views'].to_i, video['game'].to_s, video['title'].to_s)
-# Curses.cols
+ for video in response['videos']
+ printf( "%-45s %6i %6i %-36s %-.#{width-46-37-7-7}s\n", video['url'].to_s, video['length'].to_i, video['views'].to_i, video['game'].to_s, video['title'].to_s)
+# Curses.cols
+ end
end
offset += 100
@@ -42,8 +50,8 @@ end
print("Highlights:\n\n")
-videos(http, "/kraken/channels/#{user}/videos/", width, false)
+videos(http, "/kraken/channels/#{user}/videos/", width, false, client_id)
print("\nBroadcasts:\n\n")
-videos(http, "/kraken/channels/#{user}/videos/", width, true)
+videos(http, "/kraken/channels/#{user}/videos/", width, true, client_id)