seize 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +47 -0
- data/bin/seize +29 -0
- data/lib/seize/commands.rb +55 -0
- data/lib/seize/twitch.rb +28 -0
- data/lib/seize/utils.rb +17 -0
- data/lib/seize/version.rb +3 -0
- data/lib/seize.rb +2 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c0a77ac7df5f8f2b06c20b6603beec12646cbf6
|
4
|
+
data.tar.gz: d6cdf2d609a9acedb94e1607363aa3a19311702d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f2334221b115ab125fdf6afec291875ceda9cda89fb646679a1c74b127befbe59ea7913856f788fc24fac8956c6eb2c4e8e0bd12a74d857e8467b057afdb4e6
|
7
|
+
data.tar.gz: eacf842c16c1ffc131fad1e808d43a5304bac5456b4979d4e962f658b4e05d600fa116618b07b3f62013ce9b4b28078827463272c87176a4618c37aaf30772e6
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Twinge
|
2
|
+
|
3
|
+
<img src='https://cloud.githubusercontent.com/assets/9126138/13517238/c1ca3650-e17e-11e5-8171-56d1c3cc924c.png'>
|
4
|
+
|
5
|
+
Twinge is a CLI for [twitch.tv](http://twitch.tv). It can do a few things, including listing the top channels that are currently live and checking the status of a single stream. Twinge also provides a simple interface into [livestreamer](https://github.com/chrippa/livestreamer) so that launching a stream from the terminal is quick and easy.
|
6
|
+
|
7
|
+
## Example Usage
|
8
|
+
|
9
|
+
`$ twinge list` will list the top streams currently live on twitch.tv
|
10
|
+
|
11
|
+
By default Twinge will list the 25 most popular streams. This number can be increased or decreased with an optional number argument `-n`.
|
12
|
+
|
13
|
+
`$ twinge list -n 50`
|
14
|
+
|
15
|
+
Twinge also provides a shortcut to easily launch a stream with livestreamer.
|
16
|
+
|
17
|
+
```
|
18
|
+
$ twinge watch nl_kripp
|
19
|
+
```
|
20
|
+
|
21
|
+
Twinge can also check the status of a current channel.
|
22
|
+
|
23
|
+
```
|
24
|
+
$ twinge check nl_kripp
|
25
|
+
nl_kripp is playing Hearthstone: Heroes of Warcraft with 13,539 viewers.
|
26
|
+
```
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
With pip:
|
31
|
+
|
32
|
+
```
|
33
|
+
pip install twinge
|
34
|
+
```
|
35
|
+
|
36
|
+
Manually:
|
37
|
+
|
38
|
+
```
|
39
|
+
cd ~
|
40
|
+
git clone https://github.com/scwood/twinge
|
41
|
+
cd twinge
|
42
|
+
python setup.py install
|
43
|
+
```
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
MIT
|
data/bin/seize
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'docopt'
|
4
|
+
require 'seize'
|
5
|
+
|
6
|
+
doc = 'Usage:
|
7
|
+
seize list [--number=<value>]
|
8
|
+
seize watch <channel> [--quality=<value>]
|
9
|
+
seize check <channel>
|
10
|
+
seize (-h | --help | --version)
|
11
|
+
|
12
|
+
Options:
|
13
|
+
-h --help Show this screen.
|
14
|
+
--version Show version.
|
15
|
+
--number=<value> Number of streams to list from 1-100. [default: 25]
|
16
|
+
--quality=<value> Livestreamer quality. [default: best]'
|
17
|
+
|
18
|
+
begin
|
19
|
+
args = Docopt.docopt(doc, {:version => Seize::VERSION})
|
20
|
+
if args['watch']
|
21
|
+
Seize.watch(args['<channel>'], args['--quality'])
|
22
|
+
elsif args['list']
|
23
|
+
Seize.list(args['--number'])
|
24
|
+
elsif args['check']
|
25
|
+
Seize.check(args['<channel>'])
|
26
|
+
end
|
27
|
+
rescue Docopt::Exit => e
|
28
|
+
puts e.message
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require 'seize/twitch'
|
4
|
+
require 'seize/utils'
|
5
|
+
|
6
|
+
module Seize
|
7
|
+
def self.watch(channel, quality)
|
8
|
+
exec("livestreamer https://twitch.tv/#{channel} #{quality}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.list(number)
|
12
|
+
line_length = 79
|
13
|
+
number_length = 5
|
14
|
+
name_length = 20
|
15
|
+
viewers_length = 12
|
16
|
+
game_length = 40
|
17
|
+
row_template = " %-#{number_length}{number}" \
|
18
|
+
" %-#{name_length}{name}" \
|
19
|
+
" %-#{viewers_length}{viewers}" \
|
20
|
+
" %{game}\n"
|
21
|
+
result = ''
|
22
|
+
line = '-' * line_length << "\n"
|
23
|
+
result << line
|
24
|
+
result << row_template % {
|
25
|
+
:number => '#',
|
26
|
+
:name => 'channel',
|
27
|
+
:viewers => 'viewers',
|
28
|
+
:game => 'game'
|
29
|
+
}
|
30
|
+
result << line
|
31
|
+
streams = Seize::Twitch.get_streams(limit: number)['streams']
|
32
|
+
streams.each_with_index do |stream, i|
|
33
|
+
result << row_template % {
|
34
|
+
:number => "#{i+1}.",
|
35
|
+
:name => Seize::Utils.truncate(stream['channel']['name'], name_length),
|
36
|
+
:viewers => Seize::Utils.commaize(stream['viewers']),
|
37
|
+
:game => Seize::Utils.truncate(stream['game'], game_length)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
puts result
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.check(channel_name)
|
44
|
+
channel = Seize::Twitch.get_channel(channel_name)
|
45
|
+
if channel.nil?
|
46
|
+
puts 'error: channel does not exist'
|
47
|
+
elsif channel['stream'].nil?
|
48
|
+
puts "#{channel_name} is offline"
|
49
|
+
else
|
50
|
+
game = channel['stream']['game']
|
51
|
+
viewers = Seize::Utils.commaize(channel['stream']['viewers'])
|
52
|
+
puts "#{channel_name} is playing #{game} with #{viewers} viewers"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/seize/twitch.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module Seize
|
4
|
+
module Twitch
|
5
|
+
BASE_URL = 'https://api.twitch.tv/kraken'
|
6
|
+
HEADERS = {:accept => 'application/vnd.twitchtv.v3+json',
|
7
|
+
:'client-id' => '2n7irufqjtyyayigyc4ubzq174axeex'}
|
8
|
+
|
9
|
+
# TODO support games paramater
|
10
|
+
def self.get_streams(limit: nil)
|
11
|
+
streams_response = RestClient.get("#{BASE_URL}/streams", {
|
12
|
+
:params => { :limit => limit }, :headers => HEADERS,
|
13
|
+
})
|
14
|
+
JSON.parse(streams_response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_channel(channel_name)
|
18
|
+
begin
|
19
|
+
channel_response = RestClient.get(
|
20
|
+
"#{BASE_URL}/streams/#{channel_name}",
|
21
|
+
{ :headers => HEADERS })
|
22
|
+
JSON.parse(channel_response)
|
23
|
+
rescue RestClient::NotFound
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/seize/utils.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Seize
|
2
|
+
module Utils
|
3
|
+
def self.truncate(string, length)
|
4
|
+
if string.nil?
|
5
|
+
'None'
|
6
|
+
elsif string.length <= length
|
7
|
+
string
|
8
|
+
else
|
9
|
+
string[0..length-3] + '...'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.commaize(number)
|
14
|
+
number.to_s.reverse.split('').each_slice(3).map(&:join).join(',').reverse
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/seize.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spencer Wood
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: docopt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: 'Full documentation: https://github.com/scwood/seize'
|
42
|
+
email:
|
43
|
+
- spencercwood@gmail.com
|
44
|
+
executables:
|
45
|
+
- seize
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- README.md
|
50
|
+
- bin/seize
|
51
|
+
- lib/seize.rb
|
52
|
+
- lib/seize/commands.rb
|
53
|
+
- lib/seize/twitch.rb
|
54
|
+
- lib/seize/utils.rb
|
55
|
+
- lib/seize/version.rb
|
56
|
+
homepage: https://github.com/scwood/seize
|
57
|
+
licenses: []
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.5.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Twitch.tv CLI interface
|
79
|
+
test_files: []
|