audio_addict 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/audio_addict/cli.rb +1 -0
- data/lib/audio_addict/commands/api.rb +43 -0
- data/lib/audio_addict/commands/log.rb +44 -17
- data/lib/audio_addict/commands/playlist.rb +13 -7
- data/lib/audio_addict/commands/set.rb +5 -1
- data/lib/audio_addict/log.rb +46 -0
- data/lib/audio_addict/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4976f81d40edb501b5e1bd16d741a2145aede7a91cac66606c4c8812429feb7
|
4
|
+
data.tar.gz: 6011eeaf3b2c74e2648af08d0cfb25dd999e976a06fabc8181d80ca1fe6ce703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f40c5d64faabc2c5d37d6d4734ff212484f46e8aa8467c8a8adb0159f2f3b465e940eeb67c99f8dceb5c9721b8d74856be6aeb3fcc8883c6a601e35dd28782
|
7
|
+
data.tar.gz: 6abed1cd956046de5e9ca2c6f25ecde44d039ea7d014288146ce203390cee0174bd1feb34865c6d114cfbf498d111477033aa2ef2dd351c62294196bd90d3a55
|
data/README.md
CHANGED
data/lib/audio_addict/cli.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
module AudioAddict
|
2
|
+
module Commands
|
3
|
+
class APICmd < Base
|
4
|
+
summary "Make direct calls to the AudioAddict API"
|
5
|
+
|
6
|
+
help "This command sends a request to the provided API endpoint. The currently configured network is automatically prepended to the endpoint path, and the output is converted to YAML format."
|
7
|
+
|
8
|
+
usage "radio api [get|post|delete] ENDPOINT"
|
9
|
+
usage "radio api --help"
|
10
|
+
|
11
|
+
param "ENDPOINT", "API endpoint path"
|
12
|
+
|
13
|
+
example "radio channels"
|
14
|
+
example "radio get track_history/channel/1"
|
15
|
+
example "radio post tracks/1/vote/2/up"
|
16
|
+
|
17
|
+
def run(args)
|
18
|
+
needs :network
|
19
|
+
@args = args
|
20
|
+
|
21
|
+
response = api.send(api_method, endpoint)
|
22
|
+
puts response.to_yaml
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def api_method
|
28
|
+
return :post if @args['post']
|
29
|
+
return :delete if @args['delete']
|
30
|
+
return :get
|
31
|
+
end
|
32
|
+
|
33
|
+
def endpoint
|
34
|
+
@args['ENDPOINT']
|
35
|
+
end
|
36
|
+
|
37
|
+
def api
|
38
|
+
@api ||= API.new current_network
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -6,54 +6,81 @@ module AudioAddict
|
|
6
6
|
usage "radio log show [SEARCH]"
|
7
7
|
usage "radio log tail [--lines N]"
|
8
8
|
usage "radio log sort"
|
9
|
+
usage "radio log browse"
|
10
|
+
usage "radio log tree [--save FILE]"
|
9
11
|
usage "radio log --help"
|
10
12
|
|
11
13
|
option "-l --lines N", "Number of lines to show [default: 5]"
|
14
|
+
option "-s --save FILE", "Save the tree output to a YAML file"
|
12
15
|
|
13
16
|
param "SEARCH", "Show only log lines matching this string"
|
14
17
|
|
15
18
|
command "show", "Show the entire like log"
|
16
19
|
command "tail", "Show the last few rows of the like log"
|
17
20
|
command "sort", "Sort the log alphabetically and save it"
|
21
|
+
command "browse", "Browse the log file interactively"
|
22
|
+
command "tree", "Show or save the log as YAML"
|
18
23
|
|
19
24
|
example "radio log show"
|
20
25
|
example "radio log show paramore"
|
21
26
|
example "radio log tail"
|
22
27
|
example "radio log tail --lines 10"
|
23
28
|
example "radio log sort"
|
29
|
+
example "radio log tree --save out.yml"
|
24
30
|
|
25
31
|
def show_command(args)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
puts File.readlines(logfile).select { |l| l.downcase.include? search.downcase }
|
30
|
-
else
|
31
|
-
puts File.read(logfile)
|
32
|
-
end
|
32
|
+
needs :like_log
|
33
|
+
query = args['SEARCH']
|
34
|
+
puts query ? log.search(query) : log.data
|
33
35
|
end
|
34
36
|
|
35
37
|
def tail_command(args)
|
36
|
-
|
38
|
+
needs :like_log
|
37
39
|
lines = args['--lines'].to_i
|
38
|
-
puts
|
40
|
+
puts log.data[-lines..-1]
|
39
41
|
end
|
40
42
|
|
41
43
|
def sort_command(args)
|
42
|
-
|
43
|
-
|
44
|
-
File.write logfile, lines.sort.join
|
44
|
+
needs :like_log
|
45
|
+
log.sort
|
45
46
|
say "!txtgrn!Sorted"
|
46
47
|
end
|
47
48
|
|
49
|
+
def browse_command(args=nil)
|
50
|
+
tree = log.tree
|
51
|
+
|
52
|
+
say ""
|
53
|
+
network = prompt.select "Network:", tree.keys, marker: '>', filter: true
|
54
|
+
channel = prompt.select "Channel:", tree[network].keys, marker: '>', filter: true, per_page: page_size
|
55
|
+
artist = prompt.select "Artist:", tree[network][channel].keys, marker: '>', filter: true, per_page: page_size
|
56
|
+
|
57
|
+
say "Songs:"
|
58
|
+
tree[network][channel][artist].each { |song| say "- !txtgrn!#{song}" }
|
59
|
+
say ""
|
60
|
+
|
61
|
+
browse_command if prompt.yes?("Again?")
|
62
|
+
end
|
63
|
+
|
64
|
+
def tree_command(args)
|
65
|
+
yaml = log.tree.to_yaml
|
66
|
+
filename = args['--save']
|
67
|
+
|
68
|
+
if filename
|
69
|
+
File.write filename, yaml
|
70
|
+
say "!txtgrn!Saved #{filename}"
|
71
|
+
else
|
72
|
+
puts yaml
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
48
76
|
private
|
49
77
|
|
50
|
-
def
|
51
|
-
|
52
|
-
raise Error, "File not found: #{logfile}" unless File.exist? logfile
|
78
|
+
def log
|
79
|
+
@log ||= Log.new
|
53
80
|
end
|
54
81
|
|
55
|
-
def
|
56
|
-
@
|
82
|
+
def page_size
|
83
|
+
@page_size ||= detect_terminal_size[1] - 4
|
57
84
|
end
|
58
85
|
|
59
86
|
end
|
@@ -58,11 +58,11 @@ module AudioAddict
|
|
58
58
|
template: "http://prem2.#{radio.domain}:80/%{channel_key}?%{listen_key}"
|
59
59
|
}
|
60
60
|
|
61
|
-
channels =
|
61
|
+
channels = {}
|
62
62
|
|
63
63
|
radio.channels.each do |key, channel|
|
64
|
-
|
65
|
-
channels
|
64
|
+
key = fix_key key.to_sym
|
65
|
+
channels[key] = channel.name
|
66
66
|
end
|
67
67
|
|
68
68
|
data[:channels] = channels
|
@@ -74,7 +74,7 @@ module AudioAddict
|
|
74
74
|
def generate_playlist(infile, outfile)
|
75
75
|
data = YAML.load_file infile
|
76
76
|
template = data[:template]
|
77
|
-
channels = data[:channels]
|
77
|
+
channels = data[:channels]
|
78
78
|
|
79
79
|
output = []
|
80
80
|
output << "[playlist]"
|
@@ -82,10 +82,10 @@ module AudioAddict
|
|
82
82
|
|
83
83
|
index = 0
|
84
84
|
|
85
|
-
channels.each do |
|
85
|
+
channels.each do |key, name|
|
86
86
|
index += 1
|
87
|
-
output << "File#{index}=#{template}" % template_params(
|
88
|
-
output << "Title#{index}=#{
|
87
|
+
output << "File#{index}=#{template}" % template_params(key)
|
88
|
+
output << "Title#{index}=#{name}"
|
89
89
|
output << "Length#{index}=0"
|
90
90
|
end
|
91
91
|
|
@@ -103,6 +103,12 @@ module AudioAddict
|
|
103
103
|
Config.listen_key
|
104
104
|
end
|
105
105
|
|
106
|
+
# This is a patch to circumvent some anomalies in the AudioAddict API
|
107
|
+
def fix_key(key)
|
108
|
+
key = :electrohouse if current_network == 'di' and key == :electro
|
109
|
+
key
|
110
|
+
end
|
111
|
+
|
106
112
|
end
|
107
113
|
end
|
108
114
|
end
|
@@ -8,7 +8,7 @@ module AudioAddict
|
|
8
8
|
usage "radio set [CHANNEL NETWORK]"
|
9
9
|
usage "radio set --help"
|
10
10
|
|
11
|
-
param "CHANNEL", "AudioAddict channel key. You can use a partial key here or leave empty for an interactive prompt."
|
11
|
+
param "CHANNEL", "AudioAddict channel key. You can use a partial key here or leave empty for an interactive prompt.\nUse '-' to set the first channel in the network."
|
12
12
|
param "NETWORK", "AudioAddict network key. You can use a partial key here or leave empty for an interactive prompt."
|
13
13
|
|
14
14
|
example "radio set"
|
@@ -16,6 +16,7 @@ module AudioAddict
|
|
16
16
|
example "radio set dance digitally"
|
17
17
|
example "radio set dance di"
|
18
18
|
example "radio set metal rockradio"
|
19
|
+
example "radio set - rockradio"
|
19
20
|
|
20
21
|
def run(args)
|
21
22
|
channel = args['CHANNEL']
|
@@ -50,6 +51,9 @@ module AudioAddict
|
|
50
51
|
if !channel
|
51
52
|
channel_menu
|
52
53
|
|
54
|
+
elsif channel == '-'
|
55
|
+
save_channel radio.channels.keys.first
|
56
|
+
|
53
57
|
elsif radio.valid_channel? channel
|
54
58
|
save_channel channel
|
55
59
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module AudioAddict
|
2
|
+
class Log
|
3
|
+
def path
|
4
|
+
@path ||= Config.like_log
|
5
|
+
end
|
6
|
+
|
7
|
+
def data
|
8
|
+
@data ||= data!
|
9
|
+
end
|
10
|
+
|
11
|
+
def data!
|
12
|
+
if File.exist? path
|
13
|
+
File.readlines(path).map(&:strip)
|
14
|
+
else
|
15
|
+
[]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def search(query)
|
20
|
+
data.select { |l| l.downcase.include? query.downcase }
|
21
|
+
end
|
22
|
+
|
23
|
+
def sort
|
24
|
+
File.write path, data.sort.join
|
25
|
+
end
|
26
|
+
|
27
|
+
def tree
|
28
|
+
@tree ||= tree!
|
29
|
+
end
|
30
|
+
|
31
|
+
def tree!
|
32
|
+
result = {}
|
33
|
+
|
34
|
+
data.each do |line|
|
35
|
+
network, channel, artist, song = line.split(' :: ')
|
36
|
+
result[network] ||= {}
|
37
|
+
result[network][channel] ||= {}
|
38
|
+
result[network][channel][artist] ||= []
|
39
|
+
result[network][channel][artist] << song
|
40
|
+
end
|
41
|
+
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/audio_addict/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audio_addict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/audio_addict/cache.rb
|
111
111
|
- lib/audio_addict/channel.rb
|
112
112
|
- lib/audio_addict/cli.rb
|
113
|
+
- lib/audio_addict/commands/api.rb
|
113
114
|
- lib/audio_addict/commands/base.rb
|
114
115
|
- lib/audio_addict/commands/channels.rb
|
115
116
|
- lib/audio_addict/commands/config.rb
|
@@ -125,6 +126,7 @@ files:
|
|
125
126
|
- lib/audio_addict/exceptions.rb
|
126
127
|
- lib/audio_addict/extensions/file.rb
|
127
128
|
- lib/audio_addict/inspectable.rb
|
129
|
+
- lib/audio_addict/log.rb
|
128
130
|
- lib/audio_addict/radio.rb
|
129
131
|
- lib/audio_addict/track.rb
|
130
132
|
- lib/audio_addict/version.rb
|