audio_addict 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42a20c9ff92ff9420328e3fad7fc6bd027a639b9cdd8603deb8586584e1b2dbb
4
- data.tar.gz: b3dd3ac2feaf72ce4d90b8f870541c13df60cb22c9d8b0ba7e8575a533ccb61c
3
+ metadata.gz: 1344d6300842af6ee581d4ea2b5695c9f741ea0a839993dfae73d218280d0b88
4
+ data.tar.gz: facf7ab27a2e123012fa721e1eb4f36ed90e9fd6d0f184950b9ea6a6a2d37b39
5
5
  SHA512:
6
- metadata.gz: b1bfca5b36d0a563882a7ac014b6ba5b32a7b78ace57183a286958b020ebe8bd1f056083803ddca02e3b5ab592abefa8722e553521c27dcbfa43c096f548ec3e
7
- data.tar.gz: 660c35babd95d6fb25e14825d07cbbb2535dc365603352df155256fdfedc778eed8278d986df0fad5b209fd6784ff43d96b6594f3e9b70a14e9cb492d2acebff
6
+ metadata.gz: e95982e148ee53bba66319321918cc89ce3b17f0f1d8865677ba660a3e3bdb0dcf0ec503feea3baa4aef6434be5368b0f88293ecd43ece461ec570c082effa78
7
+ data.tar.gz: e9e0219a73b6e51390fd8c22a98195add6596e5d7b7bd81fd93f889aa9cc40b2c1f5b87a4ed95e081386152abfed1f9bae4d933a2da8d9097b3a4fb690b72b18
data/README.md CHANGED
@@ -39,6 +39,7 @@ Features
39
39
  - View list of channels
40
40
  - View currently playing track
41
41
  - Vote on the currently playing track
42
+ - Save a log of a all your liked tracks
42
43
  - Generate playlists
43
44
 
44
45
 
@@ -60,6 +61,8 @@ Commands:
60
61
  now Show network, channel and playing track
61
62
  vote Vote on the currently playing track
62
63
  playlist Generate playlists
64
+ config Manage local configuration
65
+
63
66
 
64
67
  ```
65
68
 
@@ -11,6 +11,7 @@ module AudioAddict
11
11
  router.route 'now', to: Commands::NowCmd
12
12
  router.route 'vote', to: Commands::VoteCmd
13
13
  router.route 'playlist', to: Commands::PlaylistCmd
14
+ router.route 'config', to: Commands::ConfigCmd
14
15
 
15
16
  router
16
17
  end
@@ -0,0 +1,91 @@
1
+ module AudioAddict
2
+ module Commands
3
+ class ConfigCmd < Base
4
+ summary "Manage local configuration"
5
+
6
+ usage "radio config set KEY VALUE"
7
+ usage "radio config get KEY"
8
+ usage "radio config del KEY"
9
+ usage "radio config show"
10
+ usage "radio config edit"
11
+ usage "radio config keys"
12
+ usage "radio config --help"
13
+
14
+ param "KEY", "Config key"
15
+ param "VALUE", "Config value"
16
+
17
+ option "-s --show", "Show the contents of the config file"
18
+ option "-e --edit", "Open the config file for editing"
19
+
20
+ command "get", "Show the value of this config key."
21
+ command "set", "Set the value of this config key."
22
+ command "del", "Delete the value of this config key."
23
+ command "show", "Show the entire config file contents."
24
+ command "edit", "Open the config file for editing."
25
+ command "keys", "Show a list of supported config keys and their purpose."
26
+
27
+ example "radio config edit"
28
+ example "radio config set like_log ~/like.log"
29
+ example "radio config del session_key"
30
+ example "radio config get listen_key"
31
+
32
+ def get_command(args)
33
+ key = args['KEY'].to_sym
34
+ value = Config.properties[key]
35
+ say value ? "!txtgrn!#{value}" : "!txtred!<Unset>"
36
+ end
37
+
38
+ def set_command(args)
39
+ key = args['KEY'].to_sym
40
+ value = args['VALUE']
41
+ Config.properties[key] = value
42
+ Config.save
43
+ say "!txtgrn!#{key}=#{value}"
44
+ end
45
+
46
+ def del_command(args)
47
+ key = args['KEY'].to_sym
48
+ Config.delete key
49
+ Config.save
50
+ say "!txtgrn!Deleted"
51
+ end
52
+
53
+ def show_command(args)
54
+ say "!undpur!# #{Config.path}"
55
+ if File.exist? Config.path
56
+ puts File.read Config.path
57
+ else
58
+ say "!txtred!File Not Found"
59
+ end
60
+ end
61
+
62
+ def edit_command(args)
63
+ editor = ENV['EDITOR'] || 'vi'
64
+ system "#{editor} #{Config.path}"
65
+ end
66
+
67
+ def keys_command(args)
68
+ key_guide.each do |key, value|
69
+ say "!txtgrn!#{key}"
70
+ say word_wrap " #{value}"
71
+ say ""
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def key_guide
78
+ {
79
+ session_key: "Used for authentication.\nUsually set with !txtpur!radio login!txtrst!.",
80
+ listen_key: "Used for generating playlists.\nUsually set with !txtpur!radio login!txtrst!.",
81
+ network: "Specify the AudioAddict network you are currently listening to.\nUsually set with !txtpur!radio set!txtrst!.",
82
+ channel: "Specify the AudioAddict channel you are currently listening to.\nUsually set with !txtpur!radio set!txtrst!.",
83
+ like_log: "Specify the path to store all your positive votes.\nIf this is not set, votes will only be sent to AudioAddict and not logged locally.",
84
+ cache_dir: "Specify the path to store API response cache.\nDefault: ~/.audio_addict/cache",
85
+ cache_life: "Specify the cache life period.\nDefault: 6h.",
86
+ }
87
+ end
88
+
89
+ end
90
+ end
91
+ end
@@ -15,45 +15,60 @@ module AudioAddict
15
15
  example "radio playlist init MyRockMusic"
16
16
  example "radio playlist generate MyRockMusic"
17
17
 
18
- def run(args)
18
+ def init_command(args)
19
19
  needs :network, :channel, :listen_key
20
20
 
21
- @args = args
22
- @filename = "#{@args['NAME']}"
21
+ name = args['NAME']
22
+ outfile = "#{name}.yml"
23
23
 
24
- init_command if args['init']
25
- generate_command if args['generate']
24
+ say "!txtred!Warning!txtrst!: !txtgrn!#{outfile}!txtrst! already exists!" if File.exist? outfile
25
+ proceed = prompt.yes? "Create #{outfile}?"
26
+ if proceed
27
+ generate_config outfile
28
+ say ""
29
+ generate_command({ 'NAME' => name }) # we also generate the playlist
30
+ end
26
31
  end
27
32
 
28
- private
33
+ def generate_command(args)
34
+ needs :network, :channel, :listen_key
29
35
 
30
- def init_command
31
- @outfile = "#{@filename}.yml"
36
+ name = args['NAME']
32
37
 
33
- say "!txtred!Warning!txtrst!: !txtgrn!#{@outfile}!txtrst! already exists!" if File.exist? @outfile
34
- proceed = prompt.yes? "Create #{@outfile}?"
35
- if proceed
36
- generate_config
37
- say ""
38
- generate_command # we also generate the playlist
38
+ infile = "#{name}.yml"
39
+ outfile = "#{name}.pls"
40
+
41
+ if !File.exist? infile
42
+ say "!txtred!Cannot find #{infile}"
43
+ else
44
+ say "!txtred!Warning!txtrst!: !txtgrn!#{outfile}!txtrst! already exists!" if File.exist? outfile
45
+ proceed = prompt.yes? "Create #{outfile}?"
46
+ generate_playlist infile, outfile if proceed
39
47
  end
40
48
  end
41
49
 
42
- def generate_command
43
- @infile = "#{@filename}.yml"
44
- @outfile = "#{@filename}.pls"
50
+ private
45
51
 
46
- if !File.exist? @infile
47
- say "!txtred!Cannot find #{@infile}"
48
- else
49
- say "!txtred!Warning!txtrst!: !txtgrn!#{@outfile}!txtrst! already exists!" if File.exist? @outfile
50
- proceed = prompt.yes? "Create #{@outfile}?"
51
- generate_playlist if proceed
52
+ def generate_config(outfile)
53
+ data = {
54
+ template: "http://prem2.#{radio.domain}:80/%{channel_key}?%{listen_key}"
55
+ }
56
+
57
+ channels = []
58
+
59
+ radio.channels.each do |key, channel|
60
+ channel_data = { name: channel.name, key: key, active: true }
61
+ channels << channel_data
52
62
  end
63
+
64
+ data[:channels] = channels
65
+
66
+ File.write outfile, data.to_yaml
67
+ say "Saved !txtgrn!#{outfile}"
53
68
  end
54
69
 
55
- def generate_playlist
56
- data = YAML.load_file @infile
70
+ def generate_playlist(infile, outfile)
71
+ data = YAML.load_file infile
57
72
  template = data[:template]
58
73
  channels = data[:channels].select { |c| c[:active] }
59
74
 
@@ -72,32 +87,14 @@ module AudioAddict
72
87
 
73
88
  output = output.join("\n") + "\n"
74
89
 
75
- File.write @outfile, output
76
- say "Saved !txtgrn!#{@outfile}"
90
+ File.write outfile, output
91
+ say "Saved !txtgrn!#{outfile}"
77
92
  end
78
93
 
79
94
  def template_params(channel_key)
80
95
  { listen_key: listen_key, channel_key: channel_key }
81
96
  end
82
97
 
83
- def generate_config
84
- data = {
85
- template: "http://prem2.#{radio.domain}:80/%{channel_key}?%{listen_key}"
86
- }
87
-
88
- channels = []
89
-
90
- radio.channels.each do |key, channel|
91
- channel_data = { name: channel.name, key: key, active: true }
92
- channels << channel_data
93
- end
94
-
95
- data[:channels] = channels
96
-
97
- File.write @outfile, data.to_yaml
98
- say "Saved !txtgrn!#{@outfile}"
99
- end
100
-
101
98
  def listen_key
102
99
  Config.listen_key
103
100
  end
@@ -8,39 +8,46 @@ module AudioAddict
8
8
 
9
9
  option "-u --unsafe", "Show the full session and listen keys"
10
10
 
11
- def run(args)
12
- say "!txtblu! Config Path !txtrst!: !txtgrn!#{Config.path}"
13
-
14
- say "!txtblu! Session Key !txtrst!: "
15
- if Config.session_key
16
- key = Config.session_key
17
- display_key = args['--unsafe'] ? key : "***#{key[-4, 4]}"
18
- say "!txtgrn!#{display_key}"
19
- else
20
- say "!txtred!<Unset>!txtrst! - run !txtpur!radio login!txtrst! to fix"
21
- end
11
+ def keys
12
+ {
13
+ path: {
14
+ name: "Config Path", value: Config.path },
22
15
 
23
- say "!txtblu! Listen Key !txtrst!: "
24
- if Config.listen_key
25
- key = Config.listen_key
26
- display_key = args['--unsafe'] ? key : "***#{key[-4, 4]}"
27
- say "!txtgrn!#{display_key}"
28
- else
29
- say "!txtred!<Unset>!txtrst! - run !txtpur!radio login!txtrst! to fix"
30
- end
16
+ session_key: {
17
+ name: "Session Key", command: 'login', secret: true },
31
18
 
32
- say "!txtblu! Network !txtrst!: "
33
- if Config.network
34
- say "!txtgrn!#{Config.network}"
35
- else
36
- say "!txtred!<Unset>!txtrst! - run !txtpur!radio set!txtrst! to fix"
37
- end
19
+ listen_key: {
20
+ name: "Listen Key", command: 'login', secret: true },
21
+
22
+ network: {
23
+ name: "Network", command: 'set' },
38
24
 
39
- say "!txtblu! Channel !txtrst!: "
40
- if Config.channel
41
- say "!txtgrn!#{Config.channel}"
42
- else
43
- say"!txtred!<Unset>!txtrst! - run !txtpur!radio set!txtrst! to fix"
25
+ channel: {
26
+ name: "Channel", command: 'set' },
27
+
28
+ like_log: {
29
+ name: "Like Log", command: 'config like_log PATH' },
30
+ }
31
+ end
32
+
33
+ def run(args)
34
+ keys.each do |key, info|
35
+ value = info[:value] || Config.properties[key]
36
+
37
+ if value and !args['--unsafe'] and info[:secret]
38
+ value = "***#{value[-4, 4]}"
39
+ end
40
+
41
+ if value
42
+ display_value = "!txtgrn!#{value}!txtrst!"
43
+ else
44
+ display_value = "!txtred!<Unset>!txtrst!"
45
+ if info[:command]
46
+ display_value = "#{display_value} - set with !txtpur!radio #{info[:command]}"
47
+ end
48
+ end
49
+
50
+ say "!txtblu!#{info[:name].rjust 14}!txtrst! : #{display_value}"
44
51
  end
45
52
 
46
53
  end
@@ -14,27 +14,16 @@ module AudioAddict
14
14
  end
15
15
  end
16
16
 
17
- def delete(key)
18
- properties.delete key
17
+ def delete(*keys)
18
+ keys.each { |key| properties.delete key.to_sym }
19
19
  end
20
20
 
21
21
  def save
22
- File.deep_write path, properties.to_yaml
23
- end
24
-
25
- def valid?
26
- required_keys.each do |key|
27
- return false unless has_key? key
28
- end
29
- true
30
- end
31
-
32
- def required_keys
33
- [:network, :channel, :session_key]
22
+ File.deep_write path, sorted_properties.to_yaml
34
23
  end
35
24
 
36
25
  def has_key?(key)
37
- properties.has_key? key
26
+ properties.has_key? key.to_sym
38
27
  end
39
28
 
40
29
  def properties
@@ -45,6 +34,10 @@ module AudioAddict
45
34
  File.exist?(path) ? YAML.load_file(path) : {}
46
35
  end
47
36
 
37
+ def sorted_properties
38
+ properties.sort.to_h
39
+ end
40
+
48
41
  def path
49
42
  @path ||= ENV.fetch('AUDIO_ADDICT_CONFIG_PATH', default_path)
50
43
  end
@@ -5,12 +5,6 @@ module AudioAddict
5
5
  class ArgumentError < Error; end
6
6
  class ConfigError < Error; end
7
7
 
8
- class LoginError < Error
9
- def initialize(msg="This operation requires logging in")
10
- super
11
- end
12
- end
13
-
14
8
  class APIError < Error
15
9
  attr_reader :response
16
10
 
@@ -2,6 +2,7 @@ require 'fileutils'
2
2
 
3
3
  class File
4
4
  def self.contains?(file, content)
5
+ return false unless File.exist? file
5
6
  foreach file do |line|
6
7
  return true if line.chomp == content
7
8
  end
@@ -68,10 +68,6 @@ module AudioAddict
68
68
  channels.keys.include? channel
69
69
  end
70
70
 
71
- def favorites
72
- api.member['network_favorite_channels']
73
- end
74
-
75
71
  def api
76
72
  @api ||= API.new network
77
73
  end
@@ -1,3 +1,3 @@
1
1
  module AudioAddict
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
4
+ version: 0.1.1
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-11-30 00:00:00.000000000 Z
11
+ date: 2018-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -58,20 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.4'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 0.4.1
61
+ version: '0.5'
65
62
  type: :runtime
66
63
  prerelease: false
67
64
  version_requirements: !ruby/object:Gem::Requirement
68
65
  requirements:
69
66
  - - "~>"
70
67
  - !ruby/object:Gem::Version
71
- version: '0.4'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 0.4.1
68
+ version: '0.5'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: requires
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +112,7 @@ files:
118
112
  - lib/audio_addict/cli.rb
119
113
  - lib/audio_addict/commands/base.rb
120
114
  - lib/audio_addict/commands/channels.rb
115
+ - lib/audio_addict/commands/config.rb
121
116
  - lib/audio_addict/commands/login.rb
122
117
  - lib/audio_addict/commands/now.rb
123
118
  - lib/audio_addict/commands/playlist.rb