rubio-radio 0.0.1 → 0.0.4

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: 76a2b9f65b8a23dc9b85e85c94815701339e14e3f7fda6d15fd49e2668e5efae
4
- data.tar.gz: fa6cb61dda6e988098619c91c4bb32e0d764aaff9cd1b907cbe2207391ca3ced
3
+ metadata.gz: cfd627d6056a51e35b6ba16a55f6e87ad2e05820ffe16172862c2df5222242b7
4
+ data.tar.gz: 0bbdcb38795e7a55e00a0699bc0a30e5e2f53ed6b0a0defcaf43d81b0ea641c3
5
5
  SHA512:
6
- metadata.gz: bc3eaa0c4894f9924d7acfa63e8d877b51c93096996f17351927dcd03b4c8cf2c5b0d02a014d8c8655df8b734be6bda824dd07c27b36766b3459e82b4e861bc9
7
- data.tar.gz: 2b044184d2978cbe1686c78a5453b01fc66530df583703bf20a390b86d4d35a5676749564cc3436a068e328f90239aef459d0c86e1362a626aa08561faf9c8c9
6
+ metadata.gz: 4d6682d2602e24709eabcf65f1110acaf04b6f543e516775f6b9b29661e1c886fbf3c3d647a7e33cba78b159a044aa42a823de0e1046b1cf37b749b778e98907
7
+ data.tar.gz: d5c4ae797ab9d3985fdeb56c135738f545226dcb0eb5ca199624a17d72a645f4ee4abfbdb0687492099edfa75137527e658d78f2df0414e737e55b5969304ea5
data/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Change Log
2
+
3
+ ## 0.0.4
4
+
5
+ - Upgrade to glimmer-dsl-libui v0.5.18
6
+ - Replace `table` with new `refined_table` having pagination and filtering support across all columns (including language column)
7
+ - Request the top 10,000 radio stations upon starting the app
8
+ - Command option `--count` for configuring count of top radio stations (`10_000` by default)
9
+ - Command option `--per-page` for number of rows per page to display
10
+ - Command option `--page-count` for displaying page count ("of PAGE_COUNT pages")
11
+ - Command option `--width` for initial window width
12
+ - Command option `--height` for initial window height
13
+ - Command option `--no-menu` to remove the top menu bar and save screen space when not needed (on Mac it is always on because the menu bar does not take application screen space)
14
+ - Help menu About menu item to display message box with application license
15
+ - If `--per-page` is specified and `--height` is not specified, attempt to calculate intial window height for each platform automatically based on number of rows per page
16
+
17
+ ## 0.0.3
18
+
19
+ - Fix bug
20
+
21
+ ## 0.0.2
22
+
23
+ - Support Mac and Windows
24
+
25
+ ## 0.0.1
26
+
27
+ - Initial implementation of rubio-radio
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 kojix2
3
+ Copyright (c) 2022 kojix2
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,27 +1,120 @@
1
- # Rubio
1
+ # rubio-radio
2
+ [![Gem Version](https://badge.fury.io/rb/rubio-radio.svg)](https://badge.fury.io/rb/rubio-radio)
2
3
 
3
- ![img](https://user-images.githubusercontent.com/5798442/171986696-24bedc38-3811-4c62-a5ad-89c09d015c8a.png)
4
+ Linux
5
+
6
+ ![linux screenshot](screenshots/rubio-radio-linux.png)
7
+
8
+ Mac
9
+
10
+ ![mac screenshot](screenshots/rubio-radio-mac.png)
11
+
12
+ Windows
13
+
14
+ ![windows screenshot](screenshots/rubio-radio-windows.png)
4
15
 
5
16
  :bowtie: Alpha
6
- ## installation
7
17
 
8
- Requirements : [cvlc](https://github.com/videolan/vlc)
18
+ ## Installation
19
+
20
+ ### Requirements:
21
+
22
+ **[VLC](https://github.com/videolan/vlc)**
23
+
24
+ `rubio` uses the `vlc -I dummy` as the audio playback backend.
25
+
26
+ On Mac, it is recommended that you install VLC via [Homebrew](https://brew.sh/) to ensure the `vlc` command is added to the PATH environment variable automatically:
27
+
28
+ ```
29
+ brew install vlc
30
+ ```
31
+
32
+ On Windows, install VLC using the [Windows installer](https://www.videolan.org/vlc/download-windows.html), and then add the installed VLC app directory to the PATH environment variable (e.g. `C:\Program Files (x86)\VideoLAN\VLC`) to make the `vlc` command available.
33
+
34
+ ### Ruby Gem:
9
35
 
10
36
  ```
11
37
  gem install rubio-radio
12
38
  ```
39
+
13
40
  ## Usage
14
41
 
42
+ Run with this command:
43
+
15
44
  ```
16
45
  rubio
17
46
  ```
18
47
 
19
- Default player is `cvlc`. But you can use any command line player that can take URL of radio station as its first argument.
48
+ The top 10,000 [Radio Browser](https://www.radio-browser.info/) stations are displayed by default. But, you can customize the count (note that currently, there are only about 32,000 [Radio Browser](https://www.radio-browser.info/) stations total).
49
+
50
+ ```
51
+ rubio --count 20000
52
+ ```
53
+
54
+ Default player is `vlc -I dummy`. But, you can use any command line player that can take URL of radio station as its first argument.
20
55
 
21
56
  ```
22
57
  rubio --backend mpg123
23
58
  ```
24
59
 
60
+ Learn more about `rubio` options:
61
+
62
+ ```
63
+ rubio --help
64
+ ```
65
+
66
+ ```
67
+ Usage: rubio [options]
68
+ --vlc [STR] use VLC interface STR on the backend [dummy]
69
+ --mpg123 use mpg123 on the backend
70
+ -b, --backend STR command to use as backend player ['vlc -I dummy']
71
+ -c, --count INT number of stations to fetch from radio-browser [10000]
72
+ --per-page INT number of stations per page [20]
73
+ --[no-]page-count show/hide page count
74
+ -w, --width INT main window width
75
+ -h, --height INT main window height
76
+ --[no-]menu show/hide menu
77
+ --debug output status of monitored threads
78
+ --help show this help message
79
+ --version show the rubio version number
80
+ ```
81
+
82
+ Examples:
83
+
84
+ ```
85
+ rubio --vlc # `vlc -I rc` (interactive command line interface)
86
+ rubio --mpg123 # `rubio --backend mpg123`
87
+ rubio --count 1000 # Displays the top 1,000 Radio Browser stations
88
+ ```
89
+
90
+ Small Screen Example:
91
+
92
+ ```
93
+ rubio --per-page 6 --no-menu
94
+ ```
95
+
96
+ ![small screen linux screenshot](screenshots/rubio-radio-linux-example-small.png)
97
+
98
+ Page Count Example:
99
+
100
+ ```
101
+ rubio --page-count
102
+ ```
103
+
104
+ ![page count mac screenshot](screenshots/rubio-radio-mac-example-page-count.png)
105
+
106
+ ## Links
107
+
108
+ * [Ruby](https://github.com/ruby/ruby)
109
+ * spawn
110
+ * [Radio Browser](https://www.radio-browser.info/)
111
+ * [Radio Browser API](https://de1.api.radio-browser.info/)
112
+ * [Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui)
113
+
114
+ ## Change Log
115
+
116
+ [CHANGELOG.md](CHANGELOG.md)
117
+
25
118
  ## LICENSE
26
119
 
27
- MIT
120
+ [MIT](LICENSE.txt)
data/TODO.md ADDED
@@ -0,0 +1,3 @@
1
+ # TODO
2
+
3
+ N/A
data/exe/rubio CHANGED
@@ -2,29 +2,49 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'rubio'
5
-
6
5
  require 'optparse'
7
- backend = 'cvlc'
8
- debug = false
6
+
7
+ options = { backend: 'vlc -I dummy' }
8
+
9
9
  opt = OptionParser.new
10
- opt.on('--vlc') { backend = 'cvlc' }
11
- opt.on('--mpg123') { backend = 'mpg123' }
12
- opt.on('--backend CMD') { |b| backend = b }
13
- opt.on('--debug') { debug = true }
14
- opt.on('--help') do
10
+ opt.summary_width = 23
11
+ opt.on('--vlc [STR]', 'use VLC interface STR on the backend [dummy]') do |i|
12
+ i ||= 'dummy'
13
+ options[:backend] = "vlc -I #{i}"
14
+ end
15
+ opt.on('--mpg123', 'use mpg123 on the backend') { options[:backend] = 'mpg123' }
16
+ opt.on('-b', '--backend STR', String, 'command to use as backend player [\'vlc -I dummy\']') do |b|
17
+ options[:backend] = b
18
+ end
19
+ opt.on('-c', '--count INT', Numeric, 'number of stations to fetch from radio-browser [10000]') do |c|
20
+ options[:radio_station_count] = c
21
+ end
22
+ opt.on('--per-page INT', Numeric, 'number of stations per page [20]') { |c| options[:table_per_page] = c }
23
+ opt.on('--[no-]page-count', TrueClass, 'show/hide page count') { |b| options[:show_page_count] = b }
24
+ opt.on('-w', '--width INT', Numeric, 'main window width') { |w| options[:initial_width] = w }
25
+ opt.on('-h', '--height INT', Numeric, 'main window height') { |h| options[:initial_height] = h }
26
+ opt.on('--[no-]menu', TrueClass, 'show/hide menu') { |b| options[:visible_menu] = b }
27
+ opt.on('--debug', 'output status of monitored threads') { options[:debug] = true }
28
+ opt.on('--help', 'show this help message') do
15
29
  puts opt
16
30
  exit
17
31
  end
18
- opt.on('--version') do
32
+ opt.on('--version', 'show the rubio version number') do
19
33
  puts Rubio::VERSION
20
34
  exit
21
35
  end
22
- opt.parse!(ARGV)
23
36
 
24
- radio = Rubio::Radio.new(backend, debug: debug)
25
37
  begin
26
- radio.launch
38
+ opt.parse!(ARGV)
39
+ rescue OptionParser::InvalidOption, OptionParser::AmbiguousOption => e
40
+ puts e.message
41
+ puts opt
42
+ exit
43
+ end
44
+
45
+ begin
46
+ Rubio::Radio.launch(**options)
27
47
  rescue StandardError => e
28
- radio&.player&.stop_all
48
+ Rubio::Radio.launched_application&.player&.stop_all
29
49
  raise e
30
50
  end
data/lib/rubio/player.rb CHANGED
@@ -4,7 +4,7 @@ module Rubio
4
4
  class Player
5
5
  attr_accessor :backend, :pid, :thr, :status, :history
6
6
 
7
- def initialize(backend = 'cvlc')
7
+ def initialize(backend = OS.linux? ? 'cvlc' : 'vlc -I rc')
8
8
  raise unless backend.is_a?(String)
9
9
 
10
10
  @backend = backend
@@ -25,11 +25,11 @@ module Rubio
25
25
  end
26
26
 
27
27
  def play(url)
28
- # do not include spaces in the command line
28
+ # Do not include spaces in the command line
29
29
  # if a space exist :
30
30
  # * sh -c command url # this process with @pid will be killed
31
31
  # * cmmand url # will not be killd because pid is differennt
32
- # if no space : command url
32
+ # if no space :
33
33
  # * cmmand url # will be killed by @pid
34
34
  raise if url.match(/\s/)
35
35
 
@@ -42,7 +42,7 @@ module Rubio
42
42
  def stop
43
43
  return unless alive?
44
44
 
45
- r = Process.kill(:TERM, pid)
45
+ r = Process.kill(OS.windows? ? :KILL : :TERM, pid)
46
46
  @thr = nil
47
47
  @pid = nil
48
48
  r
@@ -50,7 +50,7 @@ module Rubio
50
50
 
51
51
  def stop_all
52
52
  @history.each do |pid, thr|
53
- Process.kill(:TERM, pid) if thr.alive?
53
+ Process.kill(OS.windows? ? :KILL : :TERM, pid) if thr.alive?
54
54
  end
55
55
  end
56
56
  end
data/lib/rubio/radio.rb CHANGED
@@ -4,40 +4,109 @@ require 'glimmer-dsl-libui'
4
4
 
5
5
  module Rubio
6
6
  class Radio
7
- include Glimmer
7
+ include Glimmer::LibUI::Application
8
+
9
+ options :backend, :initial_width, :initial_height
10
+ option :radio_station_count, default: 10_000
11
+ option :debug, default: false
12
+ option :visible_menu, default: true
13
+ option :show_page_count, default: false
14
+ option :table_per_page, default: 20
8
15
 
9
16
  attr_reader :stations, :player
10
17
 
11
- def initialize(backend, debug: false)
12
- @stations_all, @table = RadioBrowser.topvote(1000)
18
+ before_body do
19
+ @stations_all, @table = RadioBrowser.topvote(radio_station_count)
13
20
  @stations = @stations_all.dup
14
21
  @station_uuid = nil
15
22
  @player = Player.new(backend)
23
+ @initial_width = (initial_width || 400).to_i
24
+ @initial_height = (initial_height || calculate_initial_height).to_i
16
25
 
17
26
  monitor_thread(debug)
18
27
  end
19
28
 
20
- def monitor_thread(debug)
21
- Glimmer::LibUI.timer(1) do
22
- p @player.history if debug
23
- next if @station_uuid.nil? || @player.alive?
29
+ body do
30
+ radio_menu_bar
24
31
 
25
- message_box("player '#{@player.backend}' stopped!", @player.thr.to_s)
26
- stop_uuid(@station_uuid)
27
- @station_uuid = nil
28
- true
32
+ window('Rubio', @initial_width, @initial_height) do
33
+ vertical_box do
34
+ horizontal_box do
35
+ @station_table = refined_table(
36
+ table_columns: {
37
+ 'Play' => { button: {
38
+ on_clicked: lambda { |row|
39
+ station = @station_table.paginated_model_array[row]
40
+ select_station(station)
41
+ }
42
+ } },
43
+ 'name' => :text,
44
+ 'language' => :text
45
+ },
46
+ model_array: stations,
47
+ per_page: table_per_page.to_i,
48
+ visible_page_count: show_page_count
49
+ )
50
+ end
51
+ end
52
+
53
+ on_closing do
54
+ @player.stop_all
55
+ end
56
+ end
57
+ end
58
+
59
+ def radio_menu_bar
60
+ return unless OS.mac? || visible_menu
61
+
62
+ menu('Radio') do
63
+ menu_item('Stop') do
64
+ on_clicked do
65
+ stop_uuid(@station_uuid)
66
+ @station_uuid = nil
67
+ end
68
+ end
69
+
70
+ if OS.mac?
71
+ about_menu_item do
72
+ on_clicked do
73
+ about_message_box
74
+ end
75
+ end
76
+ end
77
+
78
+ quit_menu_item do
79
+ on_clicked do
80
+ @player.stop_all
81
+ end
82
+ end
83
+ end
84
+
85
+ menu('Help') do
86
+ menu_item('About') do
87
+ on_clicked do
88
+ about_message_box
89
+ end
90
+ end
29
91
  end
30
92
  end
31
93
 
32
- def selected_station_at(idx)
33
- raise unless idx.is_a?(Integer)
94
+ def about_message_box
95
+ license = begin
96
+ File.read(File.expand_path('../../LICENSE.txt', __dir__))
97
+ rescue StandardError
98
+ ''
99
+ end
100
+ product = "rubio-radio #{Rubio::VERSION}"
101
+ message_box(product, "#{product}\n\n#{license}")
102
+ end
34
103
 
35
- station_uuid = stations[idx].stationuuid
104
+ def select_station(station)
105
+ station_uuid = station.stationuuid
36
106
  stop_uuid(@station_uuid)
37
107
  if @station_uuid == station_uuid
38
108
  @station_uuid = nil
39
- else
40
- play_uuid(station_uuid)
109
+ elsif play_uuid(station_uuid)
41
110
  @station_uuid = station_uuid
42
111
  end
43
112
  end
@@ -48,7 +117,7 @@ module Rubio
48
117
  @player.play(station.url)
49
118
  rescue StandardError => e
50
119
  message_box(e.message)
51
- raise e
120
+ return false
52
121
  end
53
122
  station.playing = true
54
123
  end
@@ -61,44 +130,31 @@ module Rubio
61
130
  station.playing = false
62
131
  end
63
132
 
64
- def launch
65
- window('Rubio', 400, 200) do
66
- vertical_box do
67
- horizontal_box do
68
- stretchy false
69
- search_entry do |se|
70
- on_changed do
71
- filter_value = se.text
72
- if filter_value.empty?
73
- @stations.replace @stations_all.dup
74
- else
75
- @stations.replace(@stations_all.filter do |row_data|
76
- row_data.name.downcase.include?(filter_value.downcase)
77
- end)
78
- end
79
- end
80
- end
81
- end
82
- horizontal_box do
83
- table do
84
- button_column('Play') do
85
- on_clicked do |row|
86
- selected_station_at(row)
87
- end
88
- end
89
- text_column('name')
90
- text_column('language')
91
- cell_rows <= [self, :stations]
92
- end
93
- end
94
- end
95
- on_closing do
96
- @player.stop_all
97
- end
98
- end.show
133
+ private
134
+
135
+ def calculate_initial_height
136
+ if OS.linux?
137
+ 107 + (visible_menu ? 26 : 0) + 24 * table_per_page.to_i
138
+ elsif OS.mac? && OS.host_cpu == 'arm64'
139
+ 90 + 24 * table_per_page.to_i
140
+ elsif OS.mac?
141
+ 85 + 19 * table_per_page.to_i
142
+ else # Windows
143
+ 95 + 19 * table_per_page.to_i
144
+ end
99
145
  end
100
146
 
101
- private
147
+ def monitor_thread(debug)
148
+ Glimmer::LibUI.timer(1) do
149
+ p @player.history if debug
150
+ next if @station_uuid.nil? || @player.alive?
151
+
152
+ message_box("player '#{@player.backend}' stopped!", @player.thr.to_s)
153
+ stop_uuid(@station_uuid)
154
+ @station_uuid = nil
155
+ true
156
+ end
157
+ end
102
158
 
103
159
  def uuid_to_station(uuid)
104
160
  idx = @table[uuid]
data/lib/rubio/station.rb CHANGED
@@ -1,18 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubio
4
- BaseStation = Struct.new(:stationuuid, :name, :language, :url)
5
-
6
- class Station < BaseStation
7
- attr_accessor :playing
4
+ Station = Struct.new(:stationuuid, :name, :language, :url, :play) do
5
+ attr_reader :playing
8
6
 
9
7
  def initialize(*args, **kwargs)
10
8
  super(*args, **kwargs)
11
- @playing = false
9
+ self.playing = false
12
10
  end
13
11
 
14
- def play
15
- @playing ? '■' : '▶'
12
+ def playing=(value)
13
+ self.play = value ? '■' : '▶'
14
+ @playing = value
16
15
  end
17
16
  end
18
17
  end
data/lib/rubio/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubio
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.4'
5
5
  end
metadata CHANGED
@@ -1,29 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubio-radio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
+ - Andy Maleh
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2022-06-04 00:00:00.000000000 Z
12
+ date: 2022-08-05 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: glimmer-dsl-libui
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ">="
18
+ - - '='
18
19
  - !ruby/object:Gem::Version
19
- version: '0'
20
+ version: 0.5.18
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ">="
25
+ - - '='
25
26
  - !ruby/object:Gem::Version
26
- version: '0'
27
+ version: 0.5.18
27
28
  description: Rubio is a simple radio player written in Ruby.
28
29
  email:
29
30
  - 2xijok@gmail.com
@@ -32,8 +33,10 @@ executables:
32
33
  extensions: []
33
34
  extra_rdoc_files: []
34
35
  files:
36
+ - CHANGELOG.md
35
37
  - LICENSE.txt
36
38
  - README.md
39
+ - TODO.md
37
40
  - exe/rubio
38
41
  - lib/rubio.rb
39
42
  - lib/rubio/player.rb