lib/download_tv/downloader.rb in download_tv-2.2.0 vs lib/download_tv/downloader.rb in download_tv-2.2.1
- old
+ new
@@ -3,13 +3,10 @@
class Downloader
attr_reader :offset, :config
def initialize(offset=0, config={})
- # Change to installation directory
- Dir.chdir(__dir__)
-
@offset = offset.abs
@config = Configuration.new(config).content # Load configuration
@filters = [
->(n){ n.include?("2160p") },
@@ -171,12 +168,26 @@
##
# Spawns a silent process to download a given magnet link
# Uses xdg-open (not portable)
def download(link)
- exec = "xdg-open \"#{link}\""
+ @cmd ||= detect_os
+ exec = "#{@cmd} \"#{link}\""
+
Process.detach(Process.spawn(exec, [:out, :err]=>"/dev/null"))
+ end
+
+ def detect_os
+ case RbConfig::CONFIG['host_os']
+ when /linux/
+ "xdg-open"
+ when /darwin/
+ "open"
+ else
+ warn "You're using an unsupported platform."
+ exit 1
+ end
end
end
end