#!/usr/bin/ruby #require 'curses' require 'json' require 'net/http' channel = String.new channel = 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 http.read_timeout = 500 width = `stty size`.split[1].to_i if width < 97 width=97 end def videos(http, channel, width, broadcast_type, client_id) total = 100 offset = 0 while offset <= total response = JSON.parse(http.request(Net::HTTP::Get.new("/kraken/channels/#{channel}/videos/?limit=100&offset=#{offset}&broadcast_type=#{broadcast_type}&client_id=#{client_id}")).body) if response['videos'] total = response['_total'] for video in response['videos'] printf( "%-45s %s %6i %6i %-36s %-.#{width-46-37-7-7}s\n", video['url'].to_s, video['recorded_at'].to_s, video['length'].to_i, video['views'].to_i, video['game'].to_s, video['title'].to_s) # Curses.cols end end offset += 100 end end def clips( http, channel, width, client_id ) #-H 'Accept: application/vnd.twitchtv.v5+json' #https://api.twitch.tv/kraken/clips/top?client_id=$( cat ~/.config/twitch/client_id )&channel=bungmonkey&period=all&trending=false&limit=100 end print("Clips:\n\n") print("\nUploads:\n\n") videos( http, channel, width, 'upload', client_id ) print("\nHighlights:\n\n") videos( http, channel, width, 'highlight', client_id ) print("\nBroadcasts:\n\n") videos( http, channel, width, 'archive', client_id )