vlc-client 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 2bf06f6577ac01caa2f087f52810c0f9f8f9d909
4
- data.tar.gz: 28223c029ee4a5df6eaa988f724766e9fcaae4e6
3
+ metadata.gz: b141e2f7f60baf5ac577461081fbaade9ff4c051
4
+ data.tar.gz: d7d66afcdf65b58fc266413eaa4a286e312ff846
5
5
  SHA512:
6
- metadata.gz: 5103d85a95e92e33f8a7a07b42f4882517888dd38e49217cb8d3cabdc70171b7e848f480dde1443a99543bd2e20de2419a451d2baee2077cdda442252bfabbb3
7
- data.tar.gz: 1f4271b37a1a6e2058e98edf66747d9f10c0558867cf7bd47ba52a1ea558d79dbddf0b5a81df5a06824ba39cf648fec65304e9aeceef8f30b8a954060deb9475
6
+ metadata.gz: 73fcaa9d7b0bf70fe306e30b31a1559d3ed298fbfbee48d5577dd1fcd1ef3b0fe19e192bc63635c640132ce226417856d50fa984ad630a06234e4d70dc4757ce
7
+ data.tar.gz: 92c826484688bd0265ff2eaecf7f34c0c72f921fc0653a7ce34630b30b622314c08e4b3ddf49ed23252b6f516b9b625a9672b1d4939cd05e7e65bd089ddfd2e9
@@ -1,15 +1,17 @@
1
1
  language: ruby
2
+ before_install:
3
+ - gem install bundler -v 1.10
2
4
  script: bundle exec rake --verbose --trace
3
5
  bundler_args: --without development
4
6
  matrix:
5
7
  allow_failures:
6
8
  - rvm: ruby-head
7
9
  rvm:
8
- - jruby-19mode
9
- - 1.8.7
10
- - 1.9.2
10
+ - jruby
11
+ - rbx-2
11
12
  - 1.9.3
12
13
  - 2.0.0
13
14
  - 2.1.0
15
+ - 2.2.0
14
16
  - ruby-head
15
17
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  vlc-client manages a [VLC media player](http://www.videolan.org/vlc/) instance through it's RC interface.
4
4
 
5
- ## Installation
5
+ ### Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
@@ -16,22 +16,18 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install vlc-client
18
18
 
19
- ## Usage
19
+ ### Usage
20
20
 
21
- ### Create a client and connect to a running VLC media player instance.
21
+ ##### Create a client and connect to a running VLC media player instance.
22
22
 
23
23
  ```ruby
24
24
 
25
- #Expects a VLC media player running on 192.168.1.10:9999
26
- #e.g. vlc --extraintf rc --rc-host 192.168.1.10:9999
25
+ vlc = VLC::Client.new('192.168.1.10', 9999) #Expects a VLC media player running on `192.168.1.10:9999`, e.g. `vlc --extraintf rc --rc-host 192.168.1.10:9999`
27
26
 
28
- vlc = VLC::Client.new('192.168.1.10', 9999)
29
- # => "#<VLC::Client:0x0000000229c370 @server=#<VLC::Server:0x0000000229c6e0 @headless=false, @port=9999, @host=\"192.168.1.10\", @pid=10514>, @self_managed=true, @connection=#<VLC::Connection:0x0000000229c258 @port=9999, @host=\"192.168.1.10\", @socket=#<TCPSocket:fd 5>>>"
30
-
31
- vlc.connect
27
+ vlc.connect # connect to server
32
28
  # => true
33
29
 
34
- vlc.play('http://example.org/media.mp3') #play media
30
+ vlc.play('http://example.org/media.mp3') # play media
35
31
  # => true
36
32
 
37
33
  vlc.playing?
@@ -43,16 +39,15 @@ vlc.fullscreen
43
39
 
44
40
  ```
45
41
 
46
- ### Create a self managed client/server system.
42
+ ##### Create a self managed client/server system.
47
43
  Most of the time we want a local client/server VLC media player system
48
44
 
49
45
 
50
46
  ```ruby
51
47
 
52
- vlc = VLC::System.new #A local VLC client/server system where a local VLC installation is automaticaly managed
53
- # => "#<VLC::System:0x00000001bbb1a0 @client=#<VLC::Client:0x00000001bbade0 @server=#<VLC::Server:0x00000001bbb178 @headless=false, @port=9595, @host=\"localhost\", @pid=11225>, @connection=#<VLC::Connection:0x00000001bbacc8 @port=9595, @host=\"localhost\", @socket=#<TCPSocket:fd 5>>>>"
48
+ vlc = VLC::System.new # A client/server system over a local managed VLC instance
54
49
 
55
- vlc.connected? #auto_connect
50
+ vlc.connected? # auto connect
56
51
  # => true
57
52
 
58
53
  vlc.play('http://example.org/media.mp3')
@@ -62,60 +57,53 @@ vlc.progress
62
57
  # => 1 #%
63
58
  #...
64
59
 
65
- #Technically this is the same as
60
+ # Technically this is the same as
66
61
  vlc = VLC::Client.new(VLC::Server.new('localhost', 9595, false))
67
- # => "#<VLC::Client:0x000000011de128 @server=#<VLC::Server:0x000000011de380 @headless=false, @port=9595, @host=\"localhost\", @pid=12656>, @connection=#<VLC::Connection:0x000000011de038 @port=9595, @host=\"localhost\", @socket=#<TCPSocket:fd 5>>>"
68
62
  ```
69
63
 
70
- ###Get local VLC server lifecycle management control
64
+ # Playlist management
71
65
 
72
66
  ```ruby
73
67
 
74
- vlc = VLC::System.new('127.0.0.1', 9999, auto_start: false)
75
- # => "#<VLC::System:0x00000001695f68 @client=#<VLC::Client:0x0000000169d718 @server=#<VLC::Server:0x00000001695ec8 @headless=false, @port=9999, @host=\"127.0.0.1\", @pid=VLC::NullObject>, @connection=#<VLC::Connection:0x0000000169d588 @port=9999, @host=\"127.0.0.1\", @socket=VLC::NullObject>>>"
68
+ vlc = VLC::System.new
76
69
 
77
- vlc.server.running?
78
- # => false
70
+ vlc.add_to_playlist('track1.mp3')
71
+ vlc.add_to_playlist('track2.mp3')
79
72
 
80
- vlc.server.start
81
- # => 12672
73
+ vlc.play
74
+
75
+ vlc.playlist
76
+ #=> [{:number=>1, :title=>"Track #1 title", :length=>"00:03:10", :times_played=>1}, {:number=>2, :title=>"Track #2 title", :length=>"00:03:30", :times_played=>0}]
82
77
 
83
- vlc.connect
84
- # => true
85
78
  ```
86
79
 
87
- ## Reference
80
+ ### Reference
88
81
 
89
82
  [reference](http://rdoc.info/github/mguinada/vlc-client)
90
83
 
91
- ## Notice
84
+ ### Notice
92
85
 
93
86
  vlc-client has been tested on linux but it should work on any VLC installation as long as the command line is responsive for `vlc` and `cvlc` calls. On Mac OS X these are not available by default. They can be created with:
94
87
 
95
- ```
88
+ ```bash
96
89
  echo "alias vlc='/Applications/VLC.app/Contents/MacOS/VLC'" >> ~/.bash_profile
97
90
  echo "alias cvlc='/Applications/VLC.app/Contents/MacOS/VLC'" >> ~/.bash_profile
98
91
  ```
99
92
 
100
- VLC media player 2.0.3 seems to [ship with a bug](http://www.linuxquestions.org/questions/slackware-14/problem-vlc-2-0-3-playing-youtube-videos-4175429135) that invalidates YouTube streaming.
101
- [Please use VLC 2.0.4 or later](http://www.videolan.org/). The last tested version is VLC media player 2.1.2 Rincewind
102
-
103
- ## Contributing
93
+ ### Contributing
104
94
 
105
95
  1. Fork it
106
96
  2. Create your topic branch (`git checkout -b my-topic-branch`)
107
97
  3. Add/change specs for your unimplemented feature or bug fix
108
- 4. Make sure specs fail by running `bundle exec rake spec`. If not return to step 3
109
- 5. Hack it
110
- 6. Make sure specs pass (`bundle exec rake spec`). If not return to step 5
111
- 7. Edit the documentation so it is coherent with your feature or fix. Run `bundle exec rake yard` to review
112
- 8. Commit changes (`git commit -am 'Add some feature/fix'`) and push to the branch (`git push origin my-topic-branch`)
113
- 9. Submit a pull request for your branch.
98
+ 4. Hack it
99
+ 5. Make sure specs pass (`bundle exec rake spec`)
100
+ 6. Edit the documentation so it is coherent with your feature or fix. Run `bundle exec rake yard` to review
101
+ 7. Commit changes (`git commit -am 'Add some feature/fix'`) and push to the branch (`git push origin my-topic-branch`)
102
+ 8. Submit a pull request
114
103
 
115
- ## Copyright
104
+ ### Copyright
116
105
 
117
106
  Copyright (c) 2012 Miguel Guinada
118
107
  [LICENSE][] for details.
119
108
 
120
- [license]: https://github.com/mguinada/vlc-client/blob/master/LICENSE
121
- [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/8b1a3dc0229bef37fd7746bb62d29997 "githalytics.com")](http://githalytics.com/mguinada/vlc-client)
109
+ [license]: https://github.com/mguinada/vlc-client/blob/master/LICENSE
@@ -1,5 +1,3 @@
1
- require 'retryable'
2
-
3
1
  require 'vlc-client/null_object'
4
2
  require 'vlc-client/core_ext/array'
5
3
 
@@ -72,16 +70,25 @@ module VLC
72
70
  bind_server(server, options) unless server.nil?
73
71
  end
74
72
 
75
- private
73
+ private
74
+
76
75
  def bind_server(server, options = {})
77
76
  @connection.host = server.host
78
77
  @connection.port = server.port
79
78
 
80
79
  if options.fetch(:auto_start, true)
80
+ connection_calls = 0
81
+ connection_retries = options.fetch(:conn_retries, 5)
82
+ options.fetch(:daemonize, false) ? @server.daemonize : @server.start
83
+
81
84
  begin
82
- options.fetch(:daemonize, false) ? @server.daemonize : @server.start
83
- retryable(:tries => options.fetch(:conn_retries, 5), :on => VLC::ConnectionRefused) { connect }
85
+ connect
84
86
  rescue VLC::ConnectionRefused => e
87
+ if (connection_calls += 1) < connection_retries
88
+ sleep(0.5)
89
+ retry
90
+ end
91
+
85
92
  @server.stop
86
93
  raise e
87
94
  end
@@ -96,19 +103,20 @@ module VLC
96
103
  @host = args.first.to_s
97
104
  @port = Integer(args.last)
98
105
  else
99
- @host, @port = 'localhost', 9595
106
+ @host = 'localhost'
107
+ @port = 9595
100
108
  end
101
109
  args
102
110
  end
103
111
 
104
- def media_arg(media)
112
+ def media(media)
105
113
  case media
106
114
  when File
107
115
  media.path
108
116
  when String, URI
109
117
  media
110
118
  else
111
- raise ArgumentError, "Can not play: #{media}"
119
+ raise ArgumentError, "Can not play #{media}"
112
120
  end
113
121
  end
114
122
  end
@@ -22,7 +22,7 @@ module VLC
22
22
  # vlc.play #resume playback
23
23
  #
24
24
  def play(media = nil)
25
- connection.write(media.nil? ? "play" : "add #{media_arg(media)}")
25
+ connection.write(media.nil? ? "play" : "add #{media(media)}")
26
26
  end
27
27
 
28
28
  # Pauses playback
@@ -17,7 +17,7 @@ module VLC
17
17
  # @param media [String, File, URI] the media to be played
18
18
  #
19
19
  def add_to_playlist(media)
20
- connection.write("enqueue #{media_arg(media)}")
20
+ connection.write("enqueue #{media(media)}")
21
21
  end
22
22
 
23
23
  # Lists tracks on the playlist
@@ -47,7 +47,8 @@ module VLC
47
47
  connection.write("clear")
48
48
  end
49
49
 
50
- private
50
+ private
51
+
51
52
  def parse_playlist(list)
52
53
  list.map do |item|
53
54
  match = item.match(LIST_ITEM_REGEXP)
@@ -19,8 +19,7 @@ module VLC
19
19
  # Connects to VLC RC interface on Client#host and Client#port
20
20
  def connect
21
21
  @socket = TCPSocket.new(@host, @port)
22
- #Channel cleanup: some vlc versions echo two lines of text on connect.
23
- 2.times { read(0.1) rescue nil }
22
+ 2.times { read(0.1) rescue nil } #Channel cleanup: some vlc versions echo two lines of text on connect.
24
23
  true
25
24
  rescue Errno::ECONNREFUSED => e
26
25
  raise VLC::ConnectionRefused, "Could not connect to #{@host}:#{@port}: #{e}"
@@ -31,7 +30,7 @@ module VLC
31
30
  # @return [Boolean] true is connected, false otherwise
32
31
  #
33
32
  def connected?
34
- not(@socket.nil?)
33
+ not @socket.nil?
35
34
  end
36
35
 
37
36
  # Disconnects from VLC RC interface
@@ -52,6 +51,7 @@ module VLC
52
51
  #
53
52
  def write(data, fire_and_forget = true)
54
53
  raise NotConnectedError, "no connection to server" unless connected?
54
+
55
55
  @socket.puts(data)
56
56
  @socket.flush
57
57
 
@@ -1,19 +1,8 @@
1
1
  module VLC
2
- # Root error class
3
- class Error < StandardError; end
4
-
5
- # Raised on connection refusal
6
- class ConnectionRefused < Error; end
7
-
8
- # Raised on communication errors
9
- class ProtocolError < Error; end
10
-
11
- # Raised on a write to a broken connection
12
- class BrokenConnectionError < Error; end
13
-
14
- # Raised on a write to a disconnected connection
15
- class NotConnectedError < Error; end
16
-
17
- # Raised on a read timeout
18
- class ReadTimeoutError < Error; end
2
+ Error = Class.new(StandardError) # Root error class
3
+ ConnectionRefused = Class.new(Error) # Raised on connection refusal
4
+ NotConnectedError = Class.new(Error) # Raised on a write to a disconnected connection
5
+ BrokenConnectionError = Class.new(Error) # Raised on a write to a broken connection
6
+ ProtocolError = Class.new(Error) # Raised on communication errors
7
+ ReadTimeoutError = Class.new(Error) # Raised on a read timeout
19
8
  end
@@ -23,7 +23,7 @@ module VLC
23
23
  # @return [Boolean] true is VLC is running, false otherwise
24
24
  #
25
25
  def running?
26
- not(@pid.nil?)
26
+ not @pid.nil?
27
27
  end
28
28
 
29
29
  alias :started? :running?
@@ -33,7 +33,7 @@ module VLC
33
33
  # @return [Boolean] true is VLC is stopped, false otherwise
34
34
  #
35
35
  def stopped?
36
- not(running?)
36
+ not running?
37
37
  end
38
38
 
39
39
  # Starts a VLC instance in a subprocess
@@ -47,18 +47,14 @@ module VLC
47
47
  #
48
48
  def start(detached = false)
49
49
  return @pid if running?
50
+
50
51
  detached ? @deamon = true : setup_traps
51
52
 
52
- @pid = if RUBY_VERSION >= '1.9'
53
- process_spawn(detached)
54
- else
55
- process_spawn_ruby_1_8(detached)
56
- end
53
+ @pid = RUBY_VERSION >= '1.9' ? process_spawn(detached) : process_spawn_ruby_1_8(detached)
57
54
  end
58
55
 
59
56
  # Start a VLC instance as a system deamon
60
57
  #
61
- #
62
58
  # @return [Integer] the subprocess PID or nil if the start command
63
59
  # as no effect (e.g. VLC already running)
64
60
  # @see Server#start
@@ -83,22 +79,25 @@ module VLC
83
79
  def stop
84
80
  return nil if stopped?
85
81
 
86
- Process.kill('INT', pid = @pid)
82
+ Process.kill('SIGTERM', pid = @pid)
87
83
  @pid = NullObject.new
88
84
  @deamon = false
85
+
89
86
  pid
90
87
  end
91
88
 
92
- private
89
+ private
90
+
93
91
  def process_spawn(detached)
94
- if ENV['OS'] == 'Windows_NT'
92
+ case
93
+ when ENV['OS'] == 'Windows_NT'
95
94
  # We don't have pgroup, and should write to NUL in case the env doesn't simulate /dev/null
96
95
  Process.spawn(headless? ? 'cvlc' : 'vlc',
97
- '--extraintf', 'rc', '--rc-host', "#{@host}:#{@port}",
98
- :in => 'NUL',
99
- :out => 'NUL',
100
- :err => 'NUL')
101
- elsif (/darwin/ =~ RUBY_PLATFORM) != nil
96
+ '--extraintf', 'rc', '--rc-host', "#{@host}:#{@port}",
97
+ :in => 'NUL',
98
+ :out => 'NUL',
99
+ :err => 'NUL')
100
+ when /darwin/ =~ RUBY_PLATFORM
102
101
  Process.spawn('/Applications/VLC.app/Contents/MacOS/VLC',
103
102
  '--extraintf', 'rc', '--rc-host', "#{@host}:#{@port}",
104
103
  :pgroup => detached,
@@ -118,6 +117,7 @@ module VLC
118
117
  # For ruby 1.8
119
118
  def process_spawn_ruby_1_8(detached)
120
119
  rd, wr = IO.pipe
120
+
121
121
  if Process.fork #parent
122
122
  wr.close
123
123
  pid = rd.read.to_i
@@ -158,7 +158,7 @@ module VLC
158
158
  end
159
159
 
160
160
  def detach
161
- if RUBY_VERSION < "1.9"
161
+ if RUBY_VERSION < "1.9"
162
162
  Process.setsid
163
163
  exit if Process.fork
164
164
  Dir.chdir "/"
@@ -38,6 +38,7 @@ module VLC
38
38
  server.host = args.first.to_s
39
39
  server.port = Integer(args.last)
40
40
  end
41
+
41
42
  @client = VLC::Client.new(server, opts)
42
43
  end
43
44
 
@@ -49,7 +50,8 @@ module VLC
49
50
  client.respond_to?(method, private_methods) || super(method, private_methods)
50
51
  end
51
52
 
52
- protected
53
+ protected
54
+
53
55
  # Delegate to VLC::Client
54
56
  #
55
57
  def method_missing(method, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module VLC
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -44,7 +44,7 @@ module Mocks
44
44
  Process.should_receive(:spawn).once.and_return(99)
45
45
  end
46
46
 
47
- Process.should_receive(:kill).once.with('INT', 99) if opts.fetch(:kill, true)
47
+ Process.should_receive(:kill).once.with('SIGTERM', 99) if opts.fetch(:kill, true)
48
48
  end
49
49
 
50
50
  def mock_file(filename)
@@ -34,6 +34,17 @@ describe VLC::Client do
34
34
  vlc = VLC::Client.new(VLC::Server.new('10.0.0.1', 9999), :read_timeout => 3)
35
35
  vlc.connection.read_timeout.should eq(3)
36
36
  end
37
+
38
+ it 'retries to connect on autoconnect failure' do
39
+ mock_system_calls(:kill => true)
40
+ num_retries = 3
41
+
42
+ TCPSocket.should_receive(:new).exactly(num_retries).times.and_raise(Errno::ECONNREFUSED)
43
+
44
+ expect {
45
+ VLC::Client.new(VLC::Server.new('10.0.0.1', 9898), :conn_retries => num_retries)
46
+ }.to raise_error(VLC::ConnectionRefused)
47
+ end
37
48
  end
38
49
 
39
50
  it 'may manage an embedded VLC server' do
@@ -7,7 +7,6 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{vlc-client allows to control VLC media player over TCP}
8
8
  gem.summary = %q{vlc-client is a TCP client for VLC media player}
9
9
  gem.homepage = "https://github.com/mguinada/vlc-client"
10
-
11
10
  gem.files = `git ls-files`.split($\)
12
11
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -15,6 +14,4 @@ Gem::Specification.new do |gem|
15
14
  gem.require_paths = ["lib"]
16
15
  gem.version = VLC::VERSION
17
16
  gem.date = Time.now.utc.strftime("%Y-%m-%d")
18
-
19
- gem.add_dependency 'retryable', '~> 1.3'
20
17
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vlc-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Guinada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: retryable
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.3'
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: vlc-client allows to control VLC media player over TCP
28
14
  email:
29
15
  - mguinada@gmail.com
@@ -94,4 +80,3 @@ test_files:
94
80
  - spec/vlc-client/connection_spec.rb
95
81
  - spec/vlc-client/server_spec.rb
96
82
  - spec/vlc_client_spec.rb
97
- has_rdoc: