my-local-putio 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4005143ce3e0837e492efd136f86a336405acea364d122d6fb098c974426d59
4
- data.tar.gz: 47f70d5c48b9a5b0cf31b03cb6059dd3f21b3870077ce2804e3e490f4fc21892
3
+ metadata.gz: 1f91c9ff297300ac8c7da30e3949fe7053e1da07ea0d7bba109000aa097a5323
4
+ data.tar.gz: bef0b5f1fca0e7bc6bb8f3b0a4efcb86285ed3d7bc60b14da685fd188c0bcd6e
5
5
  SHA512:
6
- metadata.gz: 9e795b28fe462b56e2378b2bf5f13834eaac9f6c549fc066634fe621e2994490350c81eb922da4fe8522404beb617ab07f1ed1543aea16c83e676c4a023cee23
7
- data.tar.gz: 964b90d324ea09b609ce55db1eb6f30e22f95dafadbf45b1808909ca96151abe588ddd9ba41919c1eb210fc9d010cb40377506d0a0345c1a838a0fe86847b37a
6
+ metadata.gz: 33e606fdb602ff6c1a1f8ce7bfb087d6f358cfd86ba8da42f15249d4253c05a92f0d3a8d5b21035086b826311716471c489645a166044330204e7823e3bcc6df
7
+ data.tar.gz: f1886e6ac88f4e1f7405388a6a85ead14082e2c81e47dd39b82c97f3aa70a6ba9d419ac9d36b965e2b23b9c1ebafff3eb66ad51fcea096b8ee4baba014fc8ad7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v4.2.0
2
+
3
+ - Introducing temporary destination
4
+ - By default the temporary destination for files will be your local destination + "incomplete_downloads"
5
+ - You can overwrite the temporary directory with the option --temp-destination
6
+
1
7
  # v4.1.0
2
8
 
3
9
  - Change download order from put.io:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- my-local-putio (4.1.0)
4
+ my-local-putio (4.2.0)
5
5
  socksify (= 1.7.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -38,10 +38,11 @@ To update your installed version:
38
38
 
39
39
  Usage: my-local-putio [options]
40
40
  -t, --token TOKEN Put.io access token [REQUIRED]
41
- -l, --local-destination PATH Local destination path [REQUIRED]
41
+ -l, --local-destination FULLPATH Local destination path [REQUIRED]
42
42
  -d, --delete-remote Delete remote file/folder after the download
43
43
  -s, --with-subtitles Fetch subtitles from Put.io api
44
44
  -v, --version Print my-local-putio version
45
+ --temp-destination FULLPATH Temporary destination for the incomplete downloads (Default: 'local_destination'/incomplete_downloads)
45
46
  --silent Hide all messages and progress bar
46
47
  --debug Debug mode [Developer mode]
47
48
  --socks5-proxy hostname:port SOCKS5 hostname and port for proxy. Format: 127.0.0.1:1234
@@ -68,6 +69,7 @@ With Token variable (inline or exporting):
68
69
  * **-s** or **--with-subtitles**: Download subtitles from Put.io API if available. (Remember to set your preferred subtitle language on Put.io Settings website, otherwise no subtitle will be available for download.)
69
70
  * **-h**: Print the help usage message
70
71
  * **-v** or **--version**: Print the version of the application
72
+ * **--temp-destination**: Overwrite the default path (incomplete_downloads folder) of the temporary download files. After the download the complete file is moved to the selected local destination.
71
73
  * **--silent**: Hide all messages and progress bar. Recommended for Cronjob tasks.
72
74
  * **--debug**: Developer mode: Prints everything and expose URLs with tokens for debug purposes.
73
75
  * **--socks5-proxy**: Enable the SOCKS5 proxy. If enabled, all the connections for PUT.IO API and the downloads will be performed using this proxy. If the socks connection became unavailable, the application will raise an error and will stop.
@@ -77,17 +79,19 @@ Examples:
77
79
  my-local-putio -h
78
80
  my-local-putio -t 123 -l Downloads --silent -d -s
79
81
  my-local-putio -t 123 -l Downloads --silent
82
+ my-local-putio -l Downloads -t 123 --temp-destination /tmp --with-subtitles
80
83
  my-local-putio --local-destination Downloads -t 123 --debug --with-subtitles
81
84
  my-local-putio --local-destination Downloads -t 123 --socks5-proxy 127.0.0.1:3333
82
85
 
83
86
  Verbose output example:
84
87
 
85
- my-local-putio -t 123 -l Downloads -d -s --socks5-proxy 127.0.0.1:3333
88
+ my-local-putio -t 123 -l Downloads -d -s --socks5-proxy 127.0.0.1:3333 --temp-destination /tmp
86
89
 
87
90
  Starting My Local Put.io - version 3.0.0
88
91
  https://github.com/rafaelbiriba/my-local-putio
89
92
  =============================================
90
93
  Full path of the local destination: /Users/user/Downloads
94
+ Full path of the temporary destination: /tmp
91
95
  >>> Delete remote files enabled!
92
96
  >>> With subtitles enabled!
93
97
  >>> SOCKS5 enabled with 127.0.0.1:3333
@@ -97,6 +101,7 @@ Verbose output example:
97
101
  [LOG][2019-07-18 11:11:31] Downloading: /ubuntu/ubuntu-18.04.2-desktop-amd64.iso
98
102
  ######################################################################## 100.0%
99
103
  [LOG][2019-07-18 11:11:33] Deleting remote file: /ubuntu/ubuntu-18.04.2-desktop-amd64.iso
104
+ [LOG][2019-07-18 11:11:34] Finishing the download...
100
105
 
101
106
  #### Troubleshooting
102
107
 
data/bin/my-local-putio CHANGED
@@ -4,7 +4,7 @@ require "bundler/setup"
4
4
  require "my-local-putio"
5
5
 
6
6
  unless open(__FILE__).flock(File::LOCK_EX | File::LOCK_NB)
7
- puts "Script already running..."
7
+ puts "my-local-putio is already running..."
8
8
  exit
9
9
  end
10
10
 
@@ -19,6 +19,7 @@ require "openssl"
19
19
  require "ostruct"
20
20
  require "yaml"
21
21
  require "optparse"
22
+ require "fileutils"
22
23
  require "my-local-putio/version"
23
24
  require "my-local-putio/configuration"
24
25
  require "my-local-putio/logger"
@@ -34,6 +35,7 @@ module MyLocalPutio
34
35
  puts "https://github.com/rafaelbiriba/my-local-putio"
35
36
  puts "============================================="
36
37
  puts "Full path of the local destination: #{File.realdirpath(configuration.local_destination)}"
38
+ puts "Full path of the temporary destination: #{File.realdirpath(configuration.temp_destination)}"
37
39
  puts ">>> Delete remote files enabled!" if configuration.delete_remote
38
40
  puts ">>> With subtitles enabled!" if configuration.with_subtitles
39
41
  puts ">>> SOCKS5 enabled with #{configuration.socks_host}:#{configuration.socks_port}" if configuration.socks_enabled?
@@ -1,9 +1,11 @@
1
1
  module MyLocalPutio
2
2
  class Configuration
3
- attr_reader :token, :local_destination, :silent, :debug, :socks_host, :socks_port, :delete_remote, :with_subtitles
3
+ attr_reader :token, :local_destination, :temp_destination,
4
+ :silent, :debug, :socks_host, :socks_port, :delete_remote, :with_subtitles
4
5
  def initialize
5
6
  read_args_from_envs!
6
7
  parse_args!
8
+ set_defaults!
7
9
  validate_args!
8
10
  end
9
11
 
@@ -19,7 +21,7 @@ module MyLocalPutio
19
21
  def parse_args!
20
22
  OptionParser.new do |opt|
21
23
  opt.on("-t", "--token TOKEN", "Put.io access token [REQUIRED]") { |v| @token = v }
22
- opt.on("-l", "--local-destination PATH", "Local destination path [REQUIRED]") { |v| @local_destination = v }
24
+ opt.on("-l", "--local-destination FULLPATH", "Local destination path [REQUIRED]") { |v| @local_destination = v }
23
25
  opt.on("-d", "--delete-remote", "Delete remote file/folder after the download") { |v| @delete_remote = true }
24
26
  opt.on("-s", "--with-subtitles", "Fetch subtitles from Put.io api") { |v| @with_subtitles = true }
25
27
  opt.on("-v", "--version", "Print my-local-putio version") do
@@ -27,6 +29,7 @@ module MyLocalPutio
27
29
  exit
28
30
  end
29
31
 
32
+ opt.on("--temp-destination FULLPATH", "Temporary destination for the incomplete downloads (Default: 'local_destination'/incomplete_downloads)") { |v| @temp_destination = v }
30
33
  opt.on("--silent", "Hide all messages and progress bar") { |v| @silent = true }
31
34
  opt.on("--debug", "Debug mode [Developer mode]") { |v| @debug = true }
32
35
  opt.on("--socks5-proxy hostname:port", "SOCKS5 hostname and port for proxy. Format: 127.0.0.1:1234") do |v|
@@ -35,6 +38,10 @@ module MyLocalPutio
35
38
  end.parse!
36
39
  end
37
40
 
41
+ def set_defaults!
42
+ @temp_destination ||= File.join(@local_destination, "incomplete_downloads")
43
+ end
44
+
38
45
  def validate_args!
39
46
  unless @token
40
47
  puts "Missing token"
@@ -46,7 +53,8 @@ module MyLocalPutio
46
53
  exit
47
54
  end
48
55
 
49
- destination_folder_checks!
56
+ folder_checks!(@local_destination)
57
+ folder_checks!(@temp_destination)
50
58
 
51
59
  if socks_enabled? && !port_is_open?(@socks_host, @socks_port)
52
60
  puts "Cannot connect to socks using '#{@socks_host}:#{@socks_port}'"
@@ -54,11 +62,11 @@ module MyLocalPutio
54
62
  end
55
63
  end
56
64
 
57
- def destination_folder_checks!
58
- return if File.exists?(@local_destination) && File.writable?(@local_destination)
59
- FileUtils.mkdir_p(@local_destination)
65
+ def folder_checks!(folder)
66
+ return if File.exists?(folder) && File.writable?(folder)
67
+ FileUtils.mkdir_p(folder)
60
68
  rescue Errno::EACCES
61
- puts "Cannot write on the local destination path '#{@local_destination}'"
69
+ puts "Cannot write on the local destination path '#{folder}'"
62
70
  exit
63
71
  end
64
72
 
@@ -13,15 +13,34 @@ module MyLocalPutio
13
13
  command = download_command(url, path)
14
14
  fetch_result = system(*command)
15
15
  raise "Unable to download #{path}" unless fetch_result
16
+ logger.log "Finishing the download..."
17
+ move_downloaded_file!(path)
16
18
  end
17
19
 
18
20
  private
19
21
 
22
+ def move_downloaded_file!(path)
23
+ temp_file = File.join(configuration.temp_destination, path)
24
+ local_file = File.join(configuration.local_destination, path)
25
+
26
+ # Create destination folder
27
+ FileUtils.mkdir_p(File.dirname(local_file))
28
+
29
+ logger.debug "Moving file from #{temp_file} to #{local_file}"
30
+ FileUtils.mv(temp_file, local_file)
31
+
32
+ # Delete temporary file
33
+ FileUtils.rm_rf(temp_file)
34
+
35
+ # Delete temporary folder if empty
36
+ Dir.rmdir(File.dirname(temp_file)) rescue Errno::ENOTEMPTY
37
+ end
38
+
20
39
  def download_command(url, path)
21
- destination = File.join(configuration.local_destination, path)
40
+ temp_destination = File.join(configuration.temp_destination, path)
22
41
 
23
42
  command = [
24
- "curl", "--create-dirs", "--progress-bar", "-L", "--retry", "5", "-S", "-C", "-", "-o", destination, url.to_s
43
+ "curl", "--create-dirs", "--progress-bar", "-L", "--retry", "5", "-S", "-C", "-", "-o", temp_destination, url.to_s
25
44
  ]
26
45
 
27
46
  command.push("--silent") if logger.silent?
@@ -1,3 +1,3 @@
1
1
  module MyLocalPutio
2
- VERSION = "4.1.0"
2
+ VERSION = "4.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my-local-putio
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Biriba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-23 00:00:00.000000000 Z
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler