audio_addict 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1a2413418f94134ab1e8ad4bc556c9e31e4bc25f93821d7464761f226d33c51
4
- data.tar.gz: 71e19ca4ff20d6b903687361239b119041eb142420b305edcaf0d6b23e261a07
3
+ metadata.gz: 463dda325c6bd171a44438bea714b4f0058ddc3c34cf5a5cd8cba93d32bf278a
4
+ data.tar.gz: 0643c29d7061962195bb97aff3db432b8d79d766c9ac31c94edca328742ad53b
5
5
  SHA512:
6
- metadata.gz: 738afe0afba2a9ee10b62b1f1a9748f88d5a0d81b57bfae2f417ced6b47926fc932423b8cc03e9a72190dd44fd01decefd4de757f4282e05edd973db139f4b98
7
- data.tar.gz: 402a9e2f05661831b0a5f7943bed9abf8cb9771c1c23e1d3942deaac54bfb65b71b0cc04d73961bc6a456adbc6d0b7ae250204b67e9321c9cde3303ce6f928e2
6
+ metadata.gz: bf473be5bba0733b671697664c51cc7250240dfa3dea3839ff01fd55edbb34645e7c8ca01837f86ccf621ee3630b9fcaf5ea6eec68cefd8158c1370deccda6f7
7
+ data.tar.gz: 0c3cdd6c9741159363ac71ea9b353a4cea9aec56fbc0fab783fe84a8f32d9ea93576fe41f2068cb6710c98547cfcedf6e439980ed674a61194265edec2e90c53
data/README.md CHANGED
@@ -65,7 +65,7 @@ Commands:
65
65
  channels Show list of channels
66
66
  now Show network, channel and playing track
67
67
  history Show track history for the current channel
68
- vote Vote on the currently playing track
68
+ vote Vote on a recently played track
69
69
  playlist Generate playlists
70
70
  config Manage local configuration
71
71
  log Manage local like log
data/bin/radio CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'audio_addict'
3
+ include Colsole
3
4
 
4
5
  router = AudioAddict::CLI.router
5
6
 
@@ -35,9 +35,16 @@ module AudioAddict
35
35
  track_history.first
36
36
  end
37
37
 
38
- def vote(direction = :up)
39
- track_id = current_track.id
40
- endpoint = "tracks/#{track_id}/vote/#{id}"
38
+ def similar_channels
39
+ similar = properties['similar_channels']
40
+ return [] unless similar
41
+ ids = similar.map { |s| s['similar_channel_id'] }
42
+ radio.search_by_id ids
43
+ end
44
+
45
+ def vote(direction = :up, track: nil)
46
+ track ||= current_track.id
47
+ endpoint = "tracks/#{track}/vote/#{id}"
41
48
 
42
49
  if direction == :delete
43
50
  radio.api.delete endpoint
@@ -5,13 +5,17 @@ module AudioAddict
5
5
 
6
6
  help "List and search channels in the currently set radio network"
7
7
 
8
- usage "radio channels [SEARCH]"
8
+ usage "radio channels [SEARCH --info]"
9
9
  usage "radio channels --help"
10
10
 
11
+ option "-i --info", "Show results with additional info, such as channel description and related channels"
12
+
11
13
  param "SEARCH", "Channel name or a partial name to search for"
12
14
 
13
15
  example "radio channels"
16
+ example "radio channels --info"
14
17
  example "radio channels metal"
18
+ example "radio channels metal -i"
15
19
 
16
20
  def run(args)
17
21
  needs :network
@@ -23,8 +27,38 @@ module AudioAddict
23
27
  channels = search ? radio.search(search) : radio.channels
24
28
 
25
29
  channels = channels.values
30
+ if args['--info']
31
+ show_verbose channels
32
+ else
33
+ show_compact channels
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def show_verbose(channels)
40
+ channels.each do |channel|
41
+ say ""
42
+ say "!txtgrn!#{channel.name.ljust 22} !txtrst!# #{channel.key}"
43
+ say ""
44
+ say word_wrap "#{channel.description}"
45
+ say ""
46
+
47
+ similar = channel.similar_channels
48
+
49
+ if similar.any?
50
+ say "Similar Channels:"
51
+ similar.each do |key, similar|
52
+ say "- !txtblu!#{similar.name.ljust 20}!txtrst! # #{key}"
53
+ end
54
+ say ""
55
+ end
56
+ end
57
+ end
58
+
59
+ def show_compact(channels)
26
60
  channels.each do |channel|
27
- say "!txtgrn!#{channel.key.rjust 25} !txtblu!#{channel.name.strip}"
61
+ say "!txtblu!#{channel.key.rjust 25} !txtgrn!#{channel.name.strip}"
28
62
  end
29
63
  end
30
64
 
@@ -10,8 +10,8 @@ module AudioAddict
10
10
  needs :network, :channel
11
11
  say "!undgrn!#{radio.name} > #{current_channel.name}"
12
12
  say ''
13
- tracks.each do |channel|
14
- say "!txtgrn! #{channel.artist.rjust max_artist_len}!txtrst! : !txtblu!#{channel.title}"
13
+ tracks.each do |track|
14
+ say "!txtgrn! #{track.artist.rjust max_artist_len}!txtrst! : !txtblu!#{track.title}"
15
15
  end
16
16
  end
17
17
 
@@ -3,25 +3,33 @@ module AudioAddict
3
3
  class LogCmd < Base
4
4
  summary "Manage local like log"
5
5
 
6
- usage "radio log show"
6
+ usage "radio log show [SEARCH]"
7
7
  usage "radio log tail [--lines N]"
8
8
  usage "radio log sort"
9
9
  usage "radio log --help"
10
10
 
11
11
  option "-l --lines N", "Number of lines to show [default: 5]"
12
12
 
13
+ param "SEARCH", "Show only log lines matching this string"
14
+
13
15
  command "show", "Show the entire like log"
14
16
  command "tail", "Show the last few rows of the like log"
15
17
  command "sort", "Sort the log alphabetically and save it"
16
18
 
17
19
  example "radio log show"
20
+ example "radio log show paramore"
18
21
  example "radio log tail"
19
22
  example "radio log tail --lines 10"
20
23
  example "radio log sort"
21
24
 
22
25
  def show_command(args)
23
26
  setup
24
- puts File.read(logfile)
27
+ search = args['SEARCH']
28
+ if search
29
+ puts File.readlines(logfile).select { |l| l.downcase.include? search.downcase }
30
+ else
31
+ puts File.read(logfile)
32
+ end
25
33
  end
26
34
 
27
35
  def tail_command(args)
@@ -8,7 +8,7 @@ module AudioAddict
8
8
  usage "radio now"
9
9
  usage "radio now --help"
10
10
 
11
- def run(args)
11
+ def run(args = nil)
12
12
  needs :network, :channel
13
13
 
14
14
  say "!txtblu! Network !txtrst!: !txtgrn!#{radio.name}!txtrst! # #{radio.network}"
@@ -1,44 +1,73 @@
1
1
  module AudioAddict
2
2
  module Commands
3
3
  class VoteCmd < Base
4
- summary "Vote on the currently playing track"
4
+ summary "Vote on a recently played track"
5
5
 
6
- help "Start an interactive voting prompt for the currently playing track."
6
+ help "Start an interactive voting prompt for the currently playing track or for previously played tracks."
7
7
 
8
- usage "radio vote [--all]"
8
+ usage "radio vote [--all --past]"
9
9
  usage "radio vote --help"
10
10
 
11
11
  option "-a --all", "Show all voting options"
12
+ option "-p --past", "Vote on previously played tracks"
13
+
14
+ example "radio vote"
15
+ example "radio vote --all"
16
+ example "radio vote --past"
17
+ example "radio vote --all --past"
18
+ example "radio vote -ap"
12
19
 
13
20
  def run(args)
14
21
  needs :network, :channel, :session_key
22
+ @args = args
23
+ vote_mode == :now ? vote_now : vote_past
24
+ end
15
25
 
16
- prompt_style = args['--all'] ? :menu : :simple
26
+ private
17
27
 
18
- NowCmd.new.run args
19
- puts ""
20
- answer = get_user_vote style: prompt_style
21
- unless answer == :cancel
22
- say "Voting... "
23
- current_channel.vote answer
24
- resay "!txtgrn!Voted"
28
+ def vote_past
29
+ track = get_user_track
30
+ unless track == :cancel
31
+ vote = get_user_vote
32
+ send_vote vote, track unless vote == :cancel
25
33
  end
26
34
  end
27
35
 
28
- private
36
+ def vote_now
37
+ NowCmd.new.run
38
+ puts ""
39
+ vote = get_user_vote
40
+ send_vote vote unless vote == :cancel
41
+ end
29
42
 
30
- def get_user_vote(style: :menu)
31
- if style == :menu
32
- menu_prompt
33
- else
34
- simple_prompt
35
- end
43
+ def send_vote(vote, track = nil)
44
+ say "Voting... "
45
+ current_channel.vote vote, track: track
46
+ resay "!txtgrn!Voted"
47
+ end
48
+
49
+ def tracks
50
+ @tracks ||= current_channel.track_history
51
+ end
52
+
53
+ def max_artist_len
54
+ tracks.map { |t| t.artist.size }.max
55
+ end
56
+
57
+ def get_user_track
58
+ options = tracks.map { |t| ["#{t.artist.ljust max_artist_len} > #{t.title}", t.id]}.to_h
59
+ options = { "Cancel" => :cancel }.merge options
60
+ prompt.select "Track:", options, marker: '>'
61
+ end
62
+
63
+ def get_user_vote
64
+ vote_style == :menu ? menu_prompt : simple_prompt
36
65
  end
37
66
 
38
67
  def menu_prompt
39
68
  options = { "Like" => :up, "Dislike" => :down,
40
69
  "Unvote" => :delete, "Cancel" => :cancel }
41
- prompt.select "Your Vote :", options, marker: '>'
70
+ prompt.select "Vote:", options, marker: '>'
42
71
  end
43
72
 
44
73
  def simple_prompt
@@ -46,6 +75,14 @@ module AudioAddict
46
75
  like ? :up : :cancel
47
76
  end
48
77
 
78
+ def vote_style
79
+ @args['--all'] ? :menu : :simple
80
+ end
81
+
82
+ def vote_mode
83
+ @args['--past'] ? :past : :now
84
+ end
85
+
49
86
  end
50
87
  end
51
88
  end
@@ -60,6 +60,11 @@ module AudioAddict
60
60
  end
61
61
  end
62
62
 
63
+ def search_by_id(ids)
64
+ ids = [ids] unless ids.is_a? Array
65
+ channels.select { |_key, channel| ids.include? channel.id }
66
+ end
67
+
63
68
  def [](channel_key)
64
69
  channels[channel_key]
65
70
  end
@@ -1,3 +1,3 @@
1
1
  module AudioAddict
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
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.4
4
+ version: 0.1.5
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-03 00:00:00.000000000 Z
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole