summaryrefslogtreecommitdiff
path: root/lstwitchvid.rb
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@omgwallhack.org>2016-08-10 16:08:59 -0700
committerJoe Rayhawk <jrayhawk@omgwallhack.org>2016-08-10 16:08:59 -0700
commit7067ef1a3de8c3f809e6d49ce5912c817ac0953f (patch)
tree0427ac8406d8c5dd4d23ab0ab4193af166f821e1 /lstwitchvid.rb
parent98e32215e401fef3bdfb4d34584b49e3ad1f44eb (diff)
downloadtwitchtools-7067ef1a3de8c3f809e6d49ce5912c817ac0953f.tar.gz
twitchtools-7067ef1a3de8c3f809e6d49ce5912c817ac0953f.zip
lstwitchvid: new
Diffstat (limited to 'lstwitchvid.rb')
-rwxr-xr-xlstwitchvid.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/lstwitchvid.rb b/lstwitchvid.rb
new file mode 100755
index 0000000..c0b89fd
--- /dev/null
+++ b/lstwitchvid.rb
@@ -0,0 +1,49 @@
+#!/usr/bin/ruby
+
+#require 'curses'
+require 'json'
+require 'net/http'
+
+user = String.new
+
+user = URI.escape(ARGV[0])
+
+broadcasts = String.new
+
+http = Net::HTTP.new('api.twitch.tv', 443)
+http.use_ssl = true
+#http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+http.read_timeout = 500
+
+width = `stty size`.split[1].to_i
+
+if width < 97
+ width=97
+end
+
+def videos(http, path, width, broadcasts)
+
+ total = 100
+ offset = 0
+
+ while offset <= total
+
+ response = JSON.parse(http.request(Net::HTTP::Get.new("#{path}?limit=100&offset=#{offset}&broadcasts=#{broadcasts}")).body)
+ 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
+ end
+ offset += 100
+
+ end
+
+end
+
+print("Highlights:\n\n")
+
+videos(http, "/kraken/channels/#{user}/videos/", width, false)
+
+print("\nBroadcasts:\n\n")
+
+videos(http, "/kraken/channels/#{user}/videos/", width, true)