viera_play 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/bin/viera_play +8 -0
- data/lib/viera_play.rb +4 -0
- data/lib/viera_play/player.rb +30 -0
- data/lib/viera_play/single_file_server.rb +60 -0
- data/lib/viera_play/soapy.rb +42 -0
- data/lib/viera_play/tv.rb +36 -0
- data/viera_play.gemspec +20 -0
- metadata +57 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pip Taylor
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Viera Play
|
2
|
+
|
3
|
+
Viera Play uses DLNA to play video files on Panasonic Viera TVs from the
|
4
|
+
command line.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Install it from Rubygems:
|
9
|
+
|
10
|
+
$ gem install viera_play
|
11
|
+
|
12
|
+
Set your TV's control URL as the `TV_CONTROL_URL` environment variable
|
13
|
+
(using the IP of your TV):
|
14
|
+
|
15
|
+
$ export TV_CONTROL_URL='http://192.168.0.2:55000/dmr/control_2'
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Run `viera_play` from the command line, giving it the path of a video
|
20
|
+
file to play:
|
21
|
+
|
22
|
+
$ viera_play ~/my-video-file.mp4
|
23
|
+
|
24
|
+
`Control-C` will stop playback and shutdown the web server. The TV
|
25
|
+
remote can be used to pause/rewind/fast-foward the video as well.
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/bin/viera_play
ADDED
data/lib/viera_play.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module VieraPlay
|
2
|
+
class Player
|
3
|
+
def initialize(opts)
|
4
|
+
@tv = TV.new(opts.fetch(:tv_control_url))
|
5
|
+
@file_path = opts.fetch(:file_path)
|
6
|
+
@server = SingleFileServer.new(file_path, opts.fetch(:additional_mime_types, {}))
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
trap_interrupt
|
11
|
+
play_and_wait
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
attr_reader :tv, :file_path, :server
|
16
|
+
|
17
|
+
def trap_interrupt
|
18
|
+
trap 'INT' do
|
19
|
+
tv.stop
|
20
|
+
server.shutdown
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def play_and_wait
|
25
|
+
http_server_thread = Thread.new { server.start }
|
26
|
+
tv.play_uri(server.url)
|
27
|
+
http_server_thread.join
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "webrick"
|
2
|
+
require "socket"
|
3
|
+
|
4
|
+
module VieraPlay
|
5
|
+
class SingleFileServer
|
6
|
+
def initialize(file_path, additional_mime_types={})
|
7
|
+
@file_path = file_path
|
8
|
+
@additional_mime_types = FORMATS.merge(additional_mime_types)
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
server.start
|
13
|
+
end
|
14
|
+
|
15
|
+
def shutdown
|
16
|
+
server.shutdown
|
17
|
+
end
|
18
|
+
|
19
|
+
def url
|
20
|
+
"http://#{local_ip}:#{port}/"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
attr_reader :file_path, :additional_mime_types
|
25
|
+
|
26
|
+
FORMATS = {
|
27
|
+
["mkv", "mp4", "wmv", "avi", "mov"] => "video/x-msvideo",
|
28
|
+
["mp3"] => "audio/mpeg"
|
29
|
+
}
|
30
|
+
|
31
|
+
def mime_types
|
32
|
+
mime_types = WEBrick::HTTPUtils::DefaultMimeTypes
|
33
|
+
additional_mime_types.each do |file_types, mime_type|
|
34
|
+
file_types.each do |file_type|
|
35
|
+
mime_types.store file_type, mime_type
|
36
|
+
end
|
37
|
+
end
|
38
|
+
mime_types
|
39
|
+
end
|
40
|
+
|
41
|
+
def server
|
42
|
+
@server ||= WEBrick::HTTPServer.new(
|
43
|
+
:Port => port,
|
44
|
+
:MimeTypes => mime_types,
|
45
|
+
:DocumentRoot => file_path
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def port
|
50
|
+
8888
|
51
|
+
end
|
52
|
+
|
53
|
+
def local_ip
|
54
|
+
@local_ip ||= UDPSocket.open do |s|
|
55
|
+
s.connect '8.8.8.8', 1
|
56
|
+
s.addr.last
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module VieraPlay
|
5
|
+
class Soapy
|
6
|
+
def initialize(opts={})
|
7
|
+
@endpoint = URI.parse(opts.fetch(:endpoint))
|
8
|
+
@namespace = opts.fetch(:namespace)
|
9
|
+
@default_request_args = opts.fetch(:default_request_args, {})
|
10
|
+
end
|
11
|
+
|
12
|
+
def send_command(command, args={})
|
13
|
+
post(
|
14
|
+
{
|
15
|
+
"SOAPACTION" => %Q{"#{namespace}##{command}"},
|
16
|
+
"Content-type" => "text/xml"
|
17
|
+
},
|
18
|
+
soap_body(command, default_request_args.merge(args))
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
attr_reader :endpoint, :namespace, :default_request_args
|
24
|
+
|
25
|
+
def post(headers, data)
|
26
|
+
Net::HTTP.new(endpoint.host, endpoint.port).post(endpoint.path, data, headers)
|
27
|
+
end
|
28
|
+
|
29
|
+
def soap_body(command, args)
|
30
|
+
xml_args = args.map{ |key, value| "<#{key}>#{value}</#{key}>" }.join
|
31
|
+
%Q{<?xml version="1.0"?>
|
32
|
+
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
|
33
|
+
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
34
|
+
<s:Body>
|
35
|
+
<u:#{command} xmlns:u="#{namespace}">
|
36
|
+
#{xml_args}
|
37
|
+
</u:#{command}>
|
38
|
+
</s:Body>
|
39
|
+
</s:Envelope>}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module VieraPlay
|
2
|
+
class TV
|
3
|
+
def initialize(control_url)
|
4
|
+
@soap_client = Soapy.new(
|
5
|
+
:endpoint => control_url,
|
6
|
+
:namespace => "urn:schemas-upnp-org:service:AVTransport:1",
|
7
|
+
:default_request_args => {"InstanceID" => "0"}
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def stop
|
12
|
+
send_command("Stop")
|
13
|
+
end
|
14
|
+
|
15
|
+
def play
|
16
|
+
send_command("Play", "Speed" => "1")
|
17
|
+
end
|
18
|
+
|
19
|
+
def play_uri(uri)
|
20
|
+
stop
|
21
|
+
set_media_uri(uri)
|
22
|
+
play
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
attr_reader :soap_client
|
27
|
+
|
28
|
+
def set_media_uri(uri)
|
29
|
+
send_command("SetAVTransportURI", "CurrentURI" => uri)
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_command(command, args={})
|
33
|
+
soap_client.send_command(command, args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/viera_play.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "viera_play"
|
7
|
+
gem.version = "1.0"
|
8
|
+
gem.authors = ["Pip Taylor"]
|
9
|
+
gem.email = ["pip@evilgeek.co.uk"]
|
10
|
+
gem.description = %q{Uses DLNA to play video files on Panasonic Viera
|
11
|
+
TVs from the command line}
|
12
|
+
gem.summary = %q{Play videos on Viera TVs from the command line}
|
13
|
+
gem.homepage = "https://github.com/pipt/viera_play"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.executables << "viera_play"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: viera_play
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pip Taylor
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! "Uses DLNA to play video files on Panasonic Viera\n TVs
|
15
|
+
from the command line"
|
16
|
+
email:
|
17
|
+
- pip@evilgeek.co.uk
|
18
|
+
executables:
|
19
|
+
- viera_play
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- bin/viera_play
|
26
|
+
- lib/viera_play.rb
|
27
|
+
- lib/viera_play/player.rb
|
28
|
+
- lib/viera_play/single_file_server.rb
|
29
|
+
- lib/viera_play/soapy.rb
|
30
|
+
- lib/viera_play/tv.rb
|
31
|
+
- viera_play.gemspec
|
32
|
+
homepage: https://github.com/pipt/viera_play
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.23
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Play videos on Viera TVs from the command line
|
56
|
+
test_files: []
|
57
|
+
has_rdoc:
|