vlsync 0.1.2
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 +7 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/VlSync.gemspec +30 -0
- data/bin/vlsync +2 -0
- data/lib/VlSync.rb +61 -0
- data/lib/VlSync/client.rb +29 -0
- data/lib/VlSync/handlers.rb +36 -0
- data/lib/VlSync/server.rb +62 -0
- data/lib/VlSync/version.rb +3 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb0dc5fd7faa1b4807d045e212fa85d25e2ad727
|
4
|
+
data.tar.gz: dbda0f738e2d196595b4d7229a7658703416c46e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96b13d51c6edc1d4e7eccb7b51e2b36e046aed754d953704d04a138f12074be44bdc017bc739168cd165671ba0c9990413ee07474ae75df13183a73c66a9051e
|
7
|
+
data.tar.gz: 898dfe01feee276a41de2f51ec1ca2677843f4af49a470473d2df74ba9b8a740c1cefc945b90d18a75423087031c5998abb16de3b2603cfd36981149fb287076
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/VlSync.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'VlSync/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vlsync"
|
8
|
+
spec.version = VlSync::VERSION
|
9
|
+
spec.authors = ["Jaci R"]
|
10
|
+
spec.email = ["jaci.brunning@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Sync VLC playback across multiple computers}
|
13
|
+
spec.homepage = "http://www.github.com/JacisNonsense/VlSync"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
# if spec.respond_to?(:metadata)
|
18
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
19
|
+
# else
|
20
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
# end
|
22
|
+
|
23
|
+
spec.bindir = "bin"
|
24
|
+
spec.files = Dir.glob("lib/**/*") + ['Rakefile', 'VlSync.gemspec', 'Gemfile', 'Rakefile']
|
25
|
+
spec.executables = ["vlsync"]
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
end
|
data/bin/vlsync
ADDED
data/lib/VlSync.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "optparse"
|
2
|
+
require "socket"
|
3
|
+
require_relative "VlSync/version"
|
4
|
+
require_relative "VlSync/server"
|
5
|
+
require_relative "VlSync/client"
|
6
|
+
require_relative "VlSync/handlers"
|
7
|
+
|
8
|
+
module VlSync
|
9
|
+
|
10
|
+
trap("INT") {exit;}
|
11
|
+
|
12
|
+
VLC_PATHS = { :win_64 => "C:/Program Files (x86)/VideoLAN/VLC/vlc.exe",
|
13
|
+
:win_32 => "C:/Program Files/VideoLAN/VLC/vlc.exe",
|
14
|
+
:mac => "/Applications/VLC.app/Contents/MacOS/VLC",
|
15
|
+
:linux => "vlc" }
|
16
|
+
|
17
|
+
@opts = { :mode => :client, :hostname => Socket::getaddrinfo(Socket.gethostname,"echo",Socket::AF_INET)[0][3], :port => 5957, :bind => "0.0.0.0" }
|
18
|
+
OptionParser.new do |o|
|
19
|
+
o.on("-v VLC", "--vlc", "Set the VLC executable location") { |v| @opts[:vlc] = v }
|
20
|
+
o.on("-c", "--client", "Set this instance as a client (DEFAULT)") { @opts[:mode] = :client }
|
21
|
+
o.on("-s", "--server", "Set this instance as a server") { @opts[:mode] = :server }
|
22
|
+
o.on("-h HOSTNAME", "--host", "Set the hostname of the client") { |h| @opts[:hostname] = h }
|
23
|
+
o.on("-p PORT", "--port", "Set the port of the client(s)") { |port| @opts[:port] = port.to_i }
|
24
|
+
o.on("-b BIND", "--bind", "Set the bind address of the client multicast") { |addr| @opts[:bind] = addr }
|
25
|
+
end.parse!
|
26
|
+
|
27
|
+
def self.opts
|
28
|
+
@opts
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.os
|
32
|
+
if (/Windows/ =~ ENV['OS']) != nil
|
33
|
+
return :windows
|
34
|
+
elsif (/darwin/ =~ RUBY_PLATFORM) != nil
|
35
|
+
return :darwin
|
36
|
+
else
|
37
|
+
return :linux
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.vlc
|
42
|
+
return @opts[:vlc] if @opts.include? :vlc
|
43
|
+
op_s = os
|
44
|
+
return (File.exist?(VLC_PATHS[:win_64]) ? VLC_PATHS[:win_64] : VLC_PATHS[:win_32]) if op_s == :windows
|
45
|
+
return VLC_PATHS[:mac] if op_s == :darwin
|
46
|
+
return VLC_PATHS[:linux] if op_s == :linux
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.launch
|
50
|
+
if @opts[:mode] == :server
|
51
|
+
puts "Starting in Server mode..."
|
52
|
+
@instance = VlSync::Server.new
|
53
|
+
else
|
54
|
+
puts "Starting in Client mode..."
|
55
|
+
@instance = VlSync::Client.new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
launch
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module VlSync
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@args = ['--extraintf', 'rc', '--rc-host', "#{VlSync.opts[:hostname]}:#{VlSync.opts[:port]}"]
|
6
|
+
puts "Client started at #{VlSync.opts[:hostname]} on port #{VlSync.opts[:port]}"
|
7
|
+
@vlc = VlSync.vlc
|
8
|
+
@pid = Process.spawn @vlc, *@args
|
9
|
+
listener
|
10
|
+
end
|
11
|
+
|
12
|
+
def listener
|
13
|
+
BasicSocket.do_not_reverse_lookup = true
|
14
|
+
addr = [VlSync.opts[:bind], VlSync.opts[:port]+1]
|
15
|
+
puts "Starting multicast at bind: #{addr[0]} on port #{addr[1]}"
|
16
|
+
s = UDPSocket.new
|
17
|
+
s.bind(addr[0], addr[1])
|
18
|
+
loop do
|
19
|
+
message, addr = s.recvfrom(255)
|
20
|
+
if message =~ /DISCOVER_VLSYNC/
|
21
|
+
sock = UDPSocket.new(addr[0])
|
22
|
+
puts "Host Found: #{addr[2]}"
|
23
|
+
sock.send("PONG_VLSYNC", 0, addr[2], VlSync.opts[:port])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module VlSync
|
2
|
+
class Handlers
|
3
|
+
@handlers = {}
|
4
|
+
|
5
|
+
def self.register handle, &block
|
6
|
+
@handlers[handle] = block
|
7
|
+
end
|
8
|
+
def self.handlers; @handlers; end
|
9
|
+
|
10
|
+
def self.get str
|
11
|
+
@handlers.select { |key, val| (key =~ str) != nil }.first[1]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.has str
|
15
|
+
@handlers.select { |key, val| (key =~ str) != nil }.size > 0
|
16
|
+
end
|
17
|
+
|
18
|
+
register /^re((scan)|(fresh))$/ do |server, handle, *args|
|
19
|
+
server.refresh
|
20
|
+
end
|
21
|
+
|
22
|
+
register /^play$/ do |server, handle, *args|
|
23
|
+
server.write "add #{args[0]}" if args.length > 0
|
24
|
+
end
|
25
|
+
|
26
|
+
register /^sync$/ do |server, handle, *args|
|
27
|
+
server.write "seek 0"
|
28
|
+
server.write "pause"
|
29
|
+
end
|
30
|
+
|
31
|
+
register /^clients$/ do |server, handle, *args|
|
32
|
+
puts "Server Connections: #{server.sockets.inspect}"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module VlSync
|
2
|
+
class Server
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
puts "Server Started on port #{VlSync.opts[:port]}"
|
6
|
+
@discovery = Thread.new {
|
7
|
+
s = UDPSocket.new
|
8
|
+
s.bind(VlSync.opts[:bind], VlSync.opts[:port])
|
9
|
+
loop do
|
10
|
+
message, addr = s.recvfrom(255)
|
11
|
+
if message =~ /PONG_VLSYNC/
|
12
|
+
puts "Client Found: #{addr[2]}"
|
13
|
+
@clients << addr
|
14
|
+
|
15
|
+
tcp = TCPSocket.new addr[2], VlSync.opts[:port]
|
16
|
+
@client_socks << tcp
|
17
|
+
end
|
18
|
+
end
|
19
|
+
}
|
20
|
+
@multisocket = UDPSocket.new
|
21
|
+
@multisocket.setsockopt Socket::SOL_SOCKET, Socket::SO_BROADCAST, true
|
22
|
+
|
23
|
+
refresh
|
24
|
+
input
|
25
|
+
end
|
26
|
+
|
27
|
+
def sockets
|
28
|
+
@client_socks
|
29
|
+
end
|
30
|
+
|
31
|
+
def input
|
32
|
+
loop do
|
33
|
+
line = gets.chop!
|
34
|
+
match = line.match /(\w*)\s*(.*)/
|
35
|
+
name = match[1].downcase
|
36
|
+
args = match[2].split /\s+/
|
37
|
+
|
38
|
+
if VlSync::Handlers.has name
|
39
|
+
VlSync::Handlers.get(name).call(self, name, *args)
|
40
|
+
else
|
41
|
+
write line
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def refresh
|
47
|
+
puts "Refreshing list of Clients..."
|
48
|
+
@client_socks.each {|sock| begin; sock.close; rescue; end} if defined? @client_socks
|
49
|
+
@client_socks = []
|
50
|
+
@clients = []
|
51
|
+
@multisocket.send("DISCOVER_VLSYNC", 0, "<broadcast>", VlSync.opts[:port]+1)
|
52
|
+
end
|
53
|
+
|
54
|
+
def write message
|
55
|
+
@client_socks.each {|sock| begin;
|
56
|
+
sock.puts message
|
57
|
+
sock.flush
|
58
|
+
rescue; end}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vlsync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jaci R
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- jaci.brunning@gmail.com
|
44
|
+
executables:
|
45
|
+
- vlsync
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- Gemfile
|
50
|
+
- Rakefile
|
51
|
+
- VlSync.gemspec
|
52
|
+
- bin/vlsync
|
53
|
+
- lib/VlSync.rb
|
54
|
+
- lib/VlSync/client.rb
|
55
|
+
- lib/VlSync/handlers.rb
|
56
|
+
- lib/VlSync/server.rb
|
57
|
+
- lib/VlSync/version.rb
|
58
|
+
homepage: http://www.github.com/JacisNonsense/VlSync
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Sync VLC playback across multiple computers
|
81
|
+
test_files: []
|