Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cocaine gem with terrapin #66 #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/youtube-dl.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cocaine'
require 'terrapin'
require 'json'
require 'ostruct'

Expand Down Expand Up @@ -32,20 +32,20 @@ def download(urls, options = {})
#
# @return [Array] list of extractors
def extractors
@extractors ||= cocaine_line('--list-extractors').run.split("\n")
@extractors ||= terrapin_line('--list-extractors').run.split("\n")
end

# Returns youtube-dl's version
#
# @return [String] youtube-dl version
def binary_version
@binary_version ||= cocaine_line('--version').run.strip
@binary_version ||= terrapin_line('--version').run.strip
end

# Returns user agent
#
# @return [String] user agent
def user_agent
@user_agent ||= cocaine_line('--dump-user-agent').run.strip
@user_agent ||= terrapin_line('--dump-user-agent').run.strip
end
end
2 changes: 1 addition & 1 deletion lib/youtube-dl/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def sanitize_keys!
# Symbolize
manipulate_keys! { |key_name| key_name.is_a?(Symbol) ? key_name : key_name.to_sym }

# Underscoreize (because Cocaine doesn't like hyphens)
# Underscoreize (because Terrapin doesn't like hyphens)
manipulate_keys! { |key_name| key_name.to_s.tr('-', '_').to_sym }
end

Expand Down
22 changes: 11 additions & 11 deletions lib/youtube-dl/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,34 @@ def executable_path
@executable_path ||= usable_executable_path_for(@executable)
end

# Returns Cocaine's runner engine
# Returns Terrapin's runner engine
#
# @return [CommandLineRunner] backend runner class
def backend_runner
Cocaine::CommandLine.runner
Terrapin::CommandLine.runner
end

# Sets Cocaine's runner engine
# Sets Terrapin's runner engine
#
# @param cocaine_runner [CommandLineRunner] backend runner class
# @return [Object] whatever Cocaine::CommandLine.runner= returns.
def backend_runner=(cocaine_runner)
Cocaine::CommandLine.runner = cocaine_runner
# @param terrapin_runner [CommandLineRunner] backend runner class
# @return [Object] whatever Terrapin::CommandLine.runner= returns.
def backend_runner=(terrapin_runner)
Terrapin::CommandLine.runner = terrapin_runner
end

# Returns the command string without running anything
#
# @return [String] command line string
def to_command
cocaine_line(options_to_commands).command(@options.store)
terrapin_line(options_to_commands).command(@options.store)
end
alias_method :command, :to_command

# Runs the command
#
# @return [String] the output of youtube-dl
def run
cocaine_line(options_to_commands).run(@options.store)
terrapin_line(options_to_commands).run(@options.store)
end
alias_method :download, :run

Expand All @@ -75,9 +75,9 @@ def configure(*a, &b)

private

# Parses options and converts them to Cocaine's syntax
# Parses options and converts them to Terrapin's syntax
#
# @return [String] commands ready to do cocaine
# @return [String] commands ready to do terrapin
def options_to_commands
commands = []
@options.sanitize_keys.each_paramized_key do |key, paramized_key|
Expand Down
8 changes: 4 additions & 4 deletions lib/youtube-dl/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def usable_executable_path_for(exe)

alias_method :executable_path_for, :usable_executable_path_for

# Helper for doing lines of cocaine (initializing, auto executable stuff, etc)
# Helper for doing lines of terrapin (initializing, auto executable stuff, etc)
#
# @param command [String] command switches to run
# @param executable_path [String] executable to run. Defaults to usable youtube-dl.
# @return [Cocaine::CommandLine] initialized Cocaine instance
def cocaine_line(command, executable_path = nil)
# @return [Terrapin::CommandLine] initialized Terrapin instance
def terrapin_line(command, executable_path = nil)
executable_path = executable_path_for('youtube-dl') if executable_path.nil?
Cocaine::CommandLine.new(executable_path, command)
Terrapin::CommandLine.new(executable_path, command)
end

# Helper to add quotes to beginning and end of a URL or whatever you want....
Expand Down
10 changes: 5 additions & 5 deletions test/youtube-dl/runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
end

describe '#backend_runner=, #backend_runner' do
it 'should set cocaine runner' do
@runner.backend_runner = Cocaine::CommandLine::BackticksRunner.new
assert_instance_of Cocaine::CommandLine::BackticksRunner, @runner.backend_runner
it 'should set terrapin runner' do
@runner.backend_runner = Terrapin::CommandLine::BackticksRunner.new
assert_instance_of Terrapin::CommandLine::BackticksRunner, @runner.backend_runner

@runner.backend_runner = Cocaine::CommandLine::PopenRunner.new
assert_instance_of Cocaine::CommandLine::PopenRunner, @runner.backend_runner
@runner.backend_runner = Terrapin::CommandLine::PopenRunner.new
assert_instance_of Terrapin::CommandLine::PopenRunner, @runner.backend_runner
end
end

Expand Down
10 changes: 5 additions & 5 deletions test/youtube-dl/support_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ def executable_path
end
end

describe '#cocaine_line' do
it 'should return a Cocaine::CommandLine instance' do
assert_instance_of Cocaine::CommandLine, @klass.cocaine_line('')
describe '#terrapin_line' do
it 'should return a Terrapin::CommandLine instance' do
assert_instance_of Terrapin::CommandLine, @klass.terrapin_line('')
end

it 'should be able to override the executable' do
line = @klass.cocaine_line('hello', 'echo')
line = @klass.terrapin_line('hello', 'echo')
assert_equal "echo hello", line.command
end

it 'should default to youtube-dl' do
line = @klass.cocaine_line(@klass.quoted(TEST_URL))
line = @klass.terrapin_line(@klass.quoted(TEST_URL))
assert_includes line.command, "youtube-dl \"#{TEST_URL}\""
end
end
Expand Down
2 changes: 1 addition & 1 deletion youtube-dl.rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'cocaine', '>=0.5.4'
spec.add_dependency 'terrapin', '>=0.6.0'

spec.add_development_dependency 'bundler', '>= 1.6'
spec.add_development_dependency 'rake', '~> 10.0'
Expand Down