somadic 0.0.3 → 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
  SHA1:
3
- metadata.gz: e781f2967b238c8b0babce28ff7688a48bf01ce9
4
- data.tar.gz: b35d981810b5b6f87dabaebf1155892d239935dd
3
+ metadata.gz: de245545ac8fcf5c46871ccc33da669bf8e110de
4
+ data.tar.gz: 3f22648c7c61efd72a150d68126c5fd49eb1de0b
5
5
  SHA512:
6
- metadata.gz: c68b44cbae2e7bff1a956bf78cb43a00dabf092a58ecd6f52acf25a71408a4c1702b47bd566124d5059dc153033860065ad491a965860005a5ddba7589ef017e
7
- data.tar.gz: 370cce2131766c31daa4b96f8e0f3e09b013500a71b384c0ff01fd0190b032ab20b8cdab87f3c9452cecbe0fba26e7fb164c57bfeaa5d70cf19805f3310e0373
6
+ metadata.gz: bcd9c0b0a9951feb56d54dad3baa2ed9fa5959ce1f262f2e66b6bc0621a143217b225634d44d6f574b289639956ac6c3147eee06ef3d207b46f15f407265752b
7
+ data.tar.gz: f562e66865f8f06bad224712ada70d7ec6d414a4d7f380a9f7d48d4c7a7a6793aa4273e395b7b622c23552b974c59697b1c7218bb3d014325b4c80966e98849e
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Somadic
2
2
 
3
- Somadic is a bare-bones terminal-based player for [somafm.com](http://somafm.com) and [di.fm](http://di.fm).
4
- It uses `mplayer` to do the heavy lifting. It's a hot Curses mess, but it works on my machine.
3
+ Somadic is a bare-bones terminal-based player for [somafm.com](http://somafm.com), [di.fm](http://di.fm),
4
+ and [SLAY Radio](http://www.slayradio.org). It uses `mplayer` to do the heavy lifting. It's also a hot
5
+ Curses mess, but it works on my machine.
5
6
 
6
7
  ```
7
8
  $ somadic di:breaks
@@ -28,8 +29,8 @@ Usage: somadic [options] [preset_name | [site1:channel1 ...]]
28
29
 
29
30
  You can specify either a `preset_name` or an arbitrary list of `site:channel` identifiers.
30
31
 
31
- site: either `di` or `soma`
32
- channel: a valid channel on `site`
32
+ site: `di`, `soma`, or `slayradio`
33
+ channel: a valid channel on `site`, or `slayradio` if site is slayradio
33
34
 
34
35
  DI premium channels require an environment variable: DI_FM_PREMIUM_ID.
35
36
 
@@ -62,6 +63,7 @@ a YAML file in `~/.somadic/presets`, say `chill.yaml`, with the following conten
62
63
  - soma:secretagent
63
64
  - di:psychill
64
65
  - soma:lush
66
+ - slayradio:slayradio
65
67
  ```
66
68
 
67
69
  You can then start somadic with the preset's name:
@@ -11,10 +11,7 @@ require 'yaml'
11
11
  SOMADIC_PATH = ENV['HOME'] + '/.somadic'
12
12
 
13
13
  base_path = File.expand_path(File.dirname(__FILE__))
14
- Dir["#{base_path}/curses/lib/*.rb"].each do |file|
15
- Somadic::Logger.debug("require #{file}")
16
- require file
17
- end
14
+ Dir["#{base_path}/curses/lib/*.rb"].each { |file| require file }
18
15
 
19
16
  Signal.trap("INT") do |sig|
20
17
  @channel.stop
@@ -29,8 +26,9 @@ end
29
26
  @optparser = OptionParser.new do |o|
30
27
  o.banner = 'Usage: somadic [options] site:channel [site:channel]'
31
28
  o.separator ''
32
- o.separator 'The `site` parameter can be di or soma. `channel` should be'
33
- o.separator 'a valid channel on that site.'
29
+ o.separator 'The `site` parameter can be di, soma, or slayradio. `channel`'
30
+ o.separator "should be a valid channel on that site except when it's slayradio,"
31
+ o.separator 'when `channel` should also be slayradio (slayradio:slayradio).'
34
32
  o.separator ''
35
33
  o.separator 'DI premium channels require an environment variable: ' \
36
34
  'DI_FM_PREMIUM_ID.'
@@ -69,8 +67,10 @@ def start_playing
69
67
  @options[:premium_id] = ENV['DI_FM_PREMIUM_ID']
70
68
  if who == 'di'
71
69
  @channel = Somadic::Channel::DI.new(@options)
72
- else
70
+ elsif who == 'soma'
73
71
  @channel = Somadic::Channel::Soma.new(@options)
72
+ else
73
+ @channel = Somadic::Channel::SlayRadio.new(@options)
74
74
  end
75
75
  @channel.start
76
76
  end
@@ -151,8 +151,10 @@ def goto_channel(channel)
151
151
  @options[:channel] = what
152
152
  if who == 'di'
153
153
  @channel = Somadic::Channel::DI.new(@options)
154
- else
154
+ elsif who == 'soma'
155
155
  @channel = Somadic::Channel::Soma.new(@options)
156
+ else
157
+ @channel = Somadic::Channel::SlayRadio.new(@options)
156
158
  end
157
159
  @channel.start
158
160
  end
@@ -162,8 +164,18 @@ def goto_next_channel
162
164
  end
163
165
 
164
166
  def goto_next_channel_random
165
- who = @channel.is_a?(Somadic::Channel::DI) ? 'di' : 'soma'
166
- what = @channel.channels.reject { |c| c[:name] == @display.channel[:name] }.sample[:name]
167
+ who = if @channel.is_a?(Somadic::Channel::DI)
168
+ 'di'
169
+ elsif @channel.is_a?(Somadic::Channel::Soma)
170
+ 'soma'
171
+ else
172
+ 'slayradio'
173
+ end
174
+ what = if who == 'slayradio'
175
+ 'slayradio'
176
+ else
177
+ @channel.channels.reject { |c| c[:name] == @display.channel[:name] }.sample[:name]
178
+ end
167
179
  goto_channel("#{who}:#{what}")
168
180
  end
169
181
 
@@ -11,10 +11,7 @@ require 'yaml'
11
11
  SOMADIC_PATH = ENV['HOME'] + '/.somadic'
12
12
 
13
13
  base_path = File.expand_path(File.dirname(__FILE__))
14
- Dir["#{base_path}/curses/lib/*.rb"].each do |file|
15
- Somadic::Logger.debug("require #{file}")
16
- require file
17
- end
14
+ Dir["#{base_path}/curses/lib/*.rb"].each { |file| require file }
18
15
 
19
16
  Signal.trap("INT") do |sig|
20
17
  @channel.stop
@@ -29,8 +26,9 @@ end
29
26
  @optparser = OptionParser.new do |o|
30
27
  o.banner = 'Usage: somadic [options] site:channel [site:channel]'
31
28
  o.separator ''
32
- o.separator 'The `site` parameter can be di or soma. `channel` should be'
33
- o.separator 'a valid channel on that site.'
29
+ o.separator 'The `site` parameter can be di, soma, or slayradio. `channel`'
30
+ o.separator "should be a valid channel on that site except when it's slayradio,"
31
+ o.separator 'when `channel` should also be slayradio (slayradio:slayradio).'
34
32
  o.separator ''
35
33
  o.separator 'DI premium channels require an environment variable: ' \
36
34
  'DI_FM_PREMIUM_ID.'
@@ -69,8 +67,10 @@ def start_playing
69
67
  @options[:premium_id] = ENV['DI_FM_PREMIUM_ID']
70
68
  if who == 'di'
71
69
  @channel = Somadic::Channel::DI.new(@options)
72
- else
70
+ elsif who == 'soma'
73
71
  @channel = Somadic::Channel::Soma.new(@options)
72
+ else
73
+ @channel = Somadic::Channel::SlayRadio.new(@options)
74
74
  end
75
75
  @channel.start
76
76
  end
@@ -151,8 +151,10 @@ def goto_channel(channel)
151
151
  @options[:channel] = what
152
152
  if who == 'di'
153
153
  @channel = Somadic::Channel::DI.new(@options)
154
- else
154
+ elsif who == 'soma'
155
155
  @channel = Somadic::Channel::Soma.new(@options)
156
+ else
157
+ @channel = Somadic::Channel::SlayRadio.new(@options)
156
158
  end
157
159
  @channel.start
158
160
  end
@@ -162,8 +164,18 @@ def goto_next_channel
162
164
  end
163
165
 
164
166
  def goto_next_channel_random
165
- who = @channel.is_a?(Somadic::Channel::DI) ? 'di' : 'soma'
166
- what = @channel.channels.reject { |c| c[:name] == @display.channel[:name] }.sample[:name]
167
+ who = if @channel.is_a?(Somadic::Channel::DI)
168
+ 'di'
169
+ elsif @channel.is_a?(Somadic::Channel::Soma)
170
+ 'soma'
171
+ else
172
+ 'slayradio'
173
+ end
174
+ what = if who == 'slayradio'
175
+ 'slayradio'
176
+ else
177
+ @channel.channels.reject { |c| c[:name] == @display.channel[:name] }.sample[:name]
178
+ end
167
179
  goto_channel("#{who}:#{what}")
168
180
  end
169
181
 
@@ -8,7 +8,14 @@ module Somadic
8
8
  def initialize(options)
9
9
  @url = options[:url]
10
10
  playlist = @url.split('/').last
11
- name = playlist[0..playlist.index('.pls') - 1]
11
+ if playlist.end_with?('.pls')
12
+ name = playlist[0..playlist.index('.pls') - 1]
13
+ elsif playlist.end_with?('.m3u')
14
+ name = playlist[0..playlist.index('.m3u') - 1]
15
+ else
16
+ Somadic::Logger.error("BaseChannel#initialize: bad playlist #{playlist}")
17
+ return
18
+ end
12
19
  @channel = find_channel(name)
13
20
 
14
21
  @mp = Mplayer.new(options)
@@ -0,0 +1,66 @@
1
+ # A wrapper around a SLAYradio channel.
2
+ module Somadic
3
+ module Channel
4
+ class SlayRadio < Somadic::BaseChannel
5
+ CHANNEL_NAME = 'slayradio'
6
+
7
+ def initialize(options)
8
+ @options = options
9
+ @options[:channel] = CHANNEL_NAME
10
+ @channels = load_channels
11
+ super(options.merge({ url: 'http://www.slayradio.org/tune_in.php/128kbps/slayradio.128.m3u' }))
12
+ end
13
+
14
+ # Overrides BaseChannel
15
+ def find_channel(name)
16
+ Somadic::Logger.debug("SlayRadio#find_channel(#{name})")
17
+ { id: 0, name: name, display_name: name }
18
+ end
19
+
20
+ # Observer callback.
21
+ def update(time, song)
22
+ @song = song if song
23
+ songs = refresh_playlist
24
+ channel = { id: 0, name: @options[:channel], display_name: @options[:channel] }
25
+ @listeners.each do |l|
26
+ l.update(channel, songs) if l.respond_to?(:update)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def load_channels
33
+ [{id: 0, name: @options[:channel], display_name: @options[:channel]}]
34
+ end
35
+
36
+ def refresh_playlist
37
+ url = 'https://www.slayradio.org/api.php?query=rotationalhistory'
38
+ page = open(url).read
39
+ json = JSON.parse(page)
40
+ songs = []
41
+ json['data'].each do |song|
42
+ artist = song['artist']
43
+ title = song['title']
44
+ if artist == title
45
+ track = artist
46
+ else
47
+ track = "#{artist} - #{title}"
48
+ end
49
+ songs << { started: Time.at(song['nowplaying'].to_i),
50
+ votes: {up: 0, down: 0},
51
+ duration: duration(song['duration'].to_i),
52
+ artist: artist,
53
+ title: title,
54
+ track: track }
55
+ end
56
+ songs
57
+ rescue => e
58
+ Somadic::Logger.error("SlayRadio#refresh_playlist: error #{e}")
59
+ end
60
+
61
+ def duration(val)
62
+ Time.at(val/1000).to_i
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,3 +1,3 @@
1
1
  module Somadic
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: somadic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Thomas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-05 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mono_logger
@@ -174,6 +174,7 @@ files:
174
174
  - lib/somadic/audio_addict.rb
175
175
  - lib/somadic/base_channel.rb
176
176
  - lib/somadic/channel/di.rb
177
+ - lib/somadic/channel/slay_radio.rb
177
178
  - lib/somadic/channel/soma.rb
178
179
  - lib/somadic/logger.rb
179
180
  - lib/somadic/mplayer.rb