soundyoink 0.0.4 → 1.0.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
  SHA1:
3
- metadata.gz: 6bad03133506824e715c20d272509f002c46d285
4
- data.tar.gz: 99f41cb63400b8cf004fa0f8b8e299d76a17b52d
3
+ metadata.gz: eec0cd3b652fda1750336c78d610dfe14bddf26e
4
+ data.tar.gz: 6c246193603c0f2aa4bcb574a465ea4632dacd6e
5
5
  SHA512:
6
- metadata.gz: f88d22cb3f0df2f2801f34ef1c63233aa04094cda76792fa749a708545bccb7c79c282b8c508ea6ed0008e03d11d526b439386c3488bd39a4526cbe878996df4
7
- data.tar.gz: 89c575746f0a51e1cbcc0e1087814f55426a26c2992229b0e6cb8367b8c1f73acce8e4c11240ce80ecd1d4dd6ae74d5007c2977bb81c50245d33ce3b41cffb57
6
+ metadata.gz: bc595f9a7118ad868f90529152fb65a135ce7e2b11be197449ac854d09171e9a42c5a59630ccdc652a83198358bc300d6b4eaf64a682d621b012236bcc84319c
7
+ data.tar.gz: b35137528abfad76258a7cc331f1b4baab3da96617e44f17ed85bebe3346fe93538b1b3b19fffd6ad70def1866cb38e9d7077720edb3fc0502be6a77e0e34567
@@ -1,10 +1,8 @@
1
1
  module Soundyoink
2
-
3
2
  # Represents an audio post; given only a link, can name the file intelligently
4
3
  # and write it to disk, as well as check whether the file has already been
5
4
  # downloaded.
6
5
  class Audio
7
-
8
6
  # Drawing the title from the URL is a little uglier than drawing it from
9
7
  # the page text itself, but lets us skip files we already have without
10
8
  # having to request the page. This saves a ton of time on user profiles.
@@ -22,10 +20,23 @@ module Soundyoink
22
20
  # it already exists and is over 10 KB.
23
21
  def download
24
22
  return nil if already_exists?
25
- puts "Downloading #{@filename}..." if $stdout.isatty
23
+ bar = ProgressBar.create(title: 'Downloading',
24
+ length: 70,
25
+ format: '%t |%B| %p%')
26
+ filesize = nil
27
+ puts @filename
28
+ target = open(@file_url, 'rb',
29
+ content_length_proc: -> (size) { filesize = size },
30
+ progress_proc: lambda do |accumulated|
31
+ bar.progress = (accumulated.to_f / filesize * 100).to_i
32
+ end
33
+ )
26
34
  File.open(@filename, 'wb') do |f|
27
- f.print open(@file_url).read
35
+ while chunk = target.read(1000)
36
+ f.write(chunk)
37
+ end
28
38
  end
39
+ puts "\n"
29
40
  end
30
41
 
31
42
  # Check that not only does the file exist, but that it is over 10 KB, so
@@ -3,7 +3,7 @@ module Soundyoink
3
3
  # create many Audio instances from a user profile link.
4
4
  class Downloader
5
5
  # @param workers [Integer] Number of download threads to run in parallel.
6
- def initialize(workers: 2)
6
+ def initialize(workers: 1)
7
7
  @audios = Queue.new
8
8
  @workers = workers
9
9
  end
@@ -23,10 +23,8 @@ module Soundyoink
23
23
  # @param profile [String] Link to a user's profile page.
24
24
  def add_profile(profile)
25
25
  open(profile).read
26
- .scan(%r{(https://[^.]+[.]net/u/[^"]+)})
27
- .flatten.map do |a|
28
- @audios << Audio.new(a)
29
- end
26
+ .scan(%r{(https://[^.]+[.]net/u/[^"]+)})
27
+ .flatten.map { |a| @audios << Audio.new(a) }
30
28
  end
31
29
 
32
30
  # +@workers+ number of threads work on the +@audios+ queue in parallel.
data/lib/soundyoink.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'open-uri'
2
+ require 'ruby-progressbar'
2
3
  require_relative './soundyoink/audio'
3
4
  require_relative './soundyoink/downloader'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soundyoink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Plant
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-23 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Command-line utility for downloading SG material, either specific titles
14
14
  or entire user histories.