flickvimeo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ gemspec
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ flickvimeo (0.0)
5
+ yajl-ruby
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ rake (0.8.7)
11
+ yajl-ruby (0.7.8)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ flickvimeo!
18
+ rake
19
+ yajl-ruby
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Eric Lindvall
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ FlickVimeo
2
+ =======
3
+
4
+ # Description
5
+
6
+ Ever wanted a simple way to send [Vimeo][] links to your Apple TV? This is
7
+ a simple command line tool that leverages [AirFlick][] to send the URL of
8
+ an Apple TV compatable (h.264 encoded) video in the highest resolution
9
+ available to the currently-selected Apple TV in AirFlick.
10
+
11
+ # Installation
12
+
13
+ The best way to install FlickVimeo is with RubyGems:
14
+
15
+ $ [sudo] gem install flickvimeo
16
+
17
+
18
+ # Usage
19
+
20
+ Run `flickvimeo` on the command line and pass it a Vimeo URL or ID:
21
+
22
+ $ flickvimeo <vimeo-url>
23
+
24
+ For example:
25
+
26
+ $ flickvimeo http://vimeo.com/18017106
27
+
28
+
29
+ # Warnings
30
+
31
+ * This is just a solution to a personal problem I've had — it may
32
+ completely not work for you
33
+ * This is OS X-specific — it uses [AirFlick][], so if you don't have that
34
+ installed and running, you're out of luck
35
+ * This may go against all sorts of [Vimeo][] rules and may break any time they
36
+ decide to change the format of the Javascript they use on their site
37
+
38
+
39
+ # Contributing
40
+
41
+ Once you've made your great commits:
42
+
43
+ 1. [Fork][fk] Mustache
44
+ 2. Create a topic branch - `git checkout -b my_branch`
45
+ 3. Push to your branch - `git push origin my_branch`
46
+ 4. Create a Pull Request or an [Issue][is] with a link to your branch
47
+ 5. That's it!
48
+
49
+ You might want to checkout Resque's [Contributing][cb] wiki page for information
50
+ on coding standards, new features, etc.
51
+
52
+
53
+ # License
54
+
55
+ Copyright (c) 2010-2011 Eric Lindvall. See LICENSE for details.
56
+
57
+
58
+ [Vimeo]: http://vimeo.com/
59
+ [AirFlick]: http://ericasadun.com/ftp/AirPlay/
60
+ [cb]: http://wiki.github.com/defunkt/resque/contributing
61
+ [fk]: http://help.github.com/forking/
62
+ [is]: http://github.com/eric/flickvimeo/issues
@@ -0,0 +1,150 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Generate RCov test coverage and open in your browser"
56
+ task :coverage do
57
+ require 'rcov'
58
+ sh "rm -fr coverage"
59
+ sh "rcov test/test_*.rb"
60
+ sh "open coverage/index.html"
61
+ end
62
+
63
+ require 'rake/rdoctask'
64
+ Rake::RDocTask.new do |rdoc|
65
+ rdoc.rdoc_dir = 'rdoc'
66
+ rdoc.title = "#{name} #{version}"
67
+ rdoc.rdoc_files.include('README*')
68
+ rdoc.rdoc_files.include('lib/**/*.rb')
69
+ end
70
+
71
+ desc "Open an irb session preloaded with this library"
72
+ task :console do
73
+ sh "irb -rubygems -r ./lib/#{name}.rb"
74
+ end
75
+
76
+ #############################################################################
77
+ #
78
+ # Custom tasks (add your own tasks here)
79
+ #
80
+ #############################################################################
81
+
82
+
83
+
84
+ #############################################################################
85
+ #
86
+ # Packaging tasks
87
+ #
88
+ #############################################################################
89
+
90
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
91
+ task :release => :build do
92
+ unless `git branch` =~ /^\* master$/
93
+ puts "You must be on the master branch to release!"
94
+ exit!
95
+ end
96
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
97
+ sh "git tag v#{version}"
98
+ sh "git push origin master"
99
+ sh "git push origin v#{version}"
100
+ sh "gem push pkg/#{name}-#{version}.gem"
101
+ end
102
+
103
+ desc "Build #{gem_file} into the pkg directory"
104
+ task :build => :gemspec do
105
+ sh "mkdir -p pkg"
106
+ sh "gem build #{gemspec_file}"
107
+ sh "mv #{gem_file} pkg"
108
+ end
109
+
110
+ desc "Generate #{gemspec_file}"
111
+ task :gemspec => :validate do
112
+ # read spec file and split out manifest section
113
+ spec = File.read(gemspec_file)
114
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
+
116
+ # replace name version and date
117
+ replace_header(head, :name)
118
+ replace_header(head, :version)
119
+ replace_header(head, :date)
120
+ #comment this out if your rubyforge_project has a different name
121
+ replace_header(head, :rubyforge_project)
122
+
123
+ # determine file list from git ls-files
124
+ files = `git ls-files`.
125
+ split("\n").
126
+ sort.
127
+ reject { |file| file =~ /^\./ }.
128
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
129
+ map { |file| " #{file}" }.
130
+ join("\n")
131
+
132
+ # piece file back together and write
133
+ manifest = " s.files = %w[\n#{files}\n ]\n"
134
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
136
+ puts "Updated #{gemspec_file}"
137
+ end
138
+
139
+ desc "Validate #{gemspec_file}"
140
+ task :validate do
141
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
142
+ unless libfiles.empty?
143
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
144
+ exit!
145
+ end
146
+ unless Dir['VERSION*'].empty?
147
+ puts "A `VERSION` file at root level violates Gem best practices."
148
+ exit!
149
+ end
150
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'flickvimeo'
4
+
5
+ unless ARGV[0]
6
+ puts "Usage: #{File.basename($0)} <vimeo-id-or-url>"
7
+ exit(1)
8
+ end
9
+
10
+ v = FlickVimeo::Video.new(ARGV[0])
11
+
12
+ puts "Video file for #{ARGV[0]}: #{v.video_file_url}"
13
+
14
+ require 'osx/cocoa'
15
+
16
+ request = {
17
+ 'RequestType' => 'play-media',
18
+ 'MediaLocation' => v.video_file_url
19
+ }
20
+
21
+ notification_center = OSX::NSDistributedNotificationCenter.defaultCenter
22
+ notification_center.postNotificationName_object_userInfo_deliverImmediately("com.sadun.airflick", nil, request, true)
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env macruby
2
+
3
+ unless ARGV[0]
4
+ puts "Usage: #{File.basename($0)} <media-url>"
5
+ exit(1)
6
+ end
7
+
8
+ puts "Requesting: #{ARGV[0]}"
9
+
10
+ request = {
11
+ 'RequestType' => 'play-media',
12
+ 'MediaLocation' => ARGV[0]
13
+ }
14
+
15
+ NSDistributedNotificationCenter.defaultCenter.postNotificationName("com.sadun.airflick", object:nil, userInfo:request, deliverImmediately:true)
16
+
@@ -0,0 +1,77 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'flickvimeo'
16
+ s.version = '1.0.0'
17
+ s.date = '2011-01-02'
18
+ # s.rubyforge_project = 'flickvimeo'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "A simple tool to use AirFlick to send Vimeo videos to your AppleTV"
23
+ s.description = "A simple tool to use AirFlick to send Vimeo videos to your AppleTV"
24
+
25
+ ## List the primary authors. If there are a bunch of authors, it's probably
26
+ ## better to set the email to an email list or something. If you don't have
27
+ ## a custom homepage, consider using your GitHub URL or the like.
28
+ s.authors = ["Eric Lindvall"]
29
+ s.email = 'eric@5stops.com'
30
+ s.homepage = 'http://github.com/eric/flickvimeo'
31
+
32
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
+ s.require_paths = %w[lib]
35
+
36
+ ## If your gem includes any executables, list them here.
37
+ s.executables = ["flickvimeo"]
38
+ s.default_executable = 'flickvimeo'
39
+
40
+ ## Specify any RDoc options here. You'll want to add your README and
41
+ ## LICENSE files to the extra_rdoc_files list.
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.extra_rdoc_files = %w[README.md LICENSE]
44
+
45
+ ## List your runtime dependencies here. Runtime dependencies are those
46
+ ## that are needed for an end user to actually USE your code.
47
+ s.add_dependency('yajl-ruby', '~> 0.7.8')
48
+
49
+ ## List your development dependencies here. Development dependencies are
50
+ ## those that are only needed during development
51
+ # s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
52
+
53
+ ## Leave this section as-is. It will be automatically generated from the
54
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
55
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
56
+ # = MANIFEST =
57
+ s.files = %w[
58
+ Gemfile
59
+ Gemfile.lock
60
+ LICENSE
61
+ README.md
62
+ Rakefile
63
+ bin/flickvimeo
64
+ bin/submitairplay
65
+ flickvimeo.gemspec
66
+ lib/flickvimeo.rb
67
+ lib/flickvimeo/video.rb
68
+ test/helper.rb
69
+ test/test_basic.rb
70
+ test/test_video.rb
71
+ ]
72
+ # = MANIFEST =
73
+
74
+ ## Test files will be grabbed from the file list. Make sure the path glob
75
+ ## matches what you actually use.
76
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
77
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require 'flickvimeo/video'
3
+
4
+ module FlickVimeo
5
+ VERSION = '1.0.0'
6
+ end
@@ -0,0 +1,75 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require 'yajl'
4
+
5
+ module FlickVimeo
6
+ class Video
7
+ def initialize(id)
8
+ @id = id
9
+ @url = vimeo_url(id)
10
+ @codec = 'h264'
11
+ end
12
+
13
+ def video_redirect_url
14
+ "http://player.vimeo.com/play_redirect?quality=#{best_quality}&codecs=#{@codec}&clip_id=#{clip_id}&time=#{timestamp}&sig=#{signature}&type=html5_desktop_local"
15
+ end
16
+
17
+ def video_file_url
18
+ @video_file_url ||= begin
19
+ response = http_request(video_redirect_url)
20
+ response['Location']
21
+ end
22
+ end
23
+
24
+ def timestamp
25
+ config['config']['request']['timestamp']
26
+ end
27
+
28
+ def signature
29
+ config['config']['request']['signature']
30
+ end
31
+
32
+ def clip_id
33
+ config['config']['video']['id']
34
+ end
35
+
36
+ def best_quality
37
+ config['config']['video']['files'][@codec].first
38
+ end
39
+
40
+ def config
41
+ @config ||= begin
42
+ response = http_request(@url)
43
+
44
+ if m = response.body.match(/clip\d+_\d+ = (.*)?;Player.checkRatio/)
45
+ # Cleanup javascript to be valid JSON
46
+ json = m[1].gsub(/([\{\[,]\s*)([a-zA-Z_]+):/) { %{#{$1}"#{$2}":} }
47
+ json = json.gsub(/(:\s*)'(.*?)'/, '\1"\2"')
48
+
49
+ Yajl::Parser.parse(json)
50
+ end
51
+ end
52
+ end
53
+
54
+ def vimeo_url(id)
55
+ case id.to_s
56
+ when %r{^http://.*vimeo.com.*[#/](\d+)}
57
+ "http://player.vimeo.com/video/#{$1}"
58
+ when /^\d+$/
59
+ "http://player.vimeo.com/video/#{id}"
60
+ else
61
+ raise "Unknown id format: #{id}"
62
+ end
63
+ end
64
+
65
+ def http_request(url)
66
+ uri = URI.parse(url)
67
+ http = Net::HTTP.new(uri.host, uri.port)
68
+
69
+ request = Net::HTTP::Get.new(uri.request_uri)
70
+ request["User-Agent"] = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4"
71
+
72
+ response = http.request(request)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ dir = File.dirname(File.expand_path(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(dir, '..', 'lib'))
5
+ $LOAD_PATH.unshift(dir)
6
+
7
+ require 'flickvimeo'
@@ -0,0 +1,4 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestBasic < Test::Unit::TestCase
4
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+ require 'pp'
3
+
4
+ class TestBasic < Test::Unit::TestCase
5
+ def setup
6
+ @video = FlickVimeo::Video.new(18017106)
7
+ end
8
+
9
+ def test_format
10
+ assert_equal 'hd', @video.best_quality
11
+ end
12
+
13
+ def test_clip_id
14
+ assert_equal 18017106, @video.clip_id
15
+ end
16
+
17
+ def test_video_file_url
18
+ pp @video.config
19
+ puts @video.video_file_url
20
+ assert_not_nil @video.video_file_url
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flickvimeo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Eric Lindvall
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-02 00:00:00 -08:00
19
+ default_executable: flickvimeo
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: yajl-ruby
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 0
32
+ - 7
33
+ - 8
34
+ version: 0.7.8
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: A simple tool to use AirFlick to send Vimeo videos to your AppleTV
38
+ email: eric@5stops.com
39
+ executables:
40
+ - flickvimeo
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - README.md
45
+ - LICENSE
46
+ files:
47
+ - Gemfile
48
+ - Gemfile.lock
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - bin/flickvimeo
53
+ - bin/submitairplay
54
+ - flickvimeo.gemspec
55
+ - lib/flickvimeo.rb
56
+ - lib/flickvimeo/video.rb
57
+ - test/helper.rb
58
+ - test/test_basic.rb
59
+ - test/test_video.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/eric/flickvimeo
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: A simple tool to use AirFlick to send Vimeo videos to your AppleTV
94
+ test_files:
95
+ - test/test_basic.rb
96
+ - test/test_video.rb