soundyoink 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44338e66fa50ed872f5aaee2d60c482da066483d
4
- data.tar.gz: b5fe3e15da55618790d4cda49c0e07faec259ffc
3
+ metadata.gz: af141f8ba90235d457f3c120e1972a672526ab8f
4
+ data.tar.gz: 2b11d488db76fb48c5fbc42f52bfb2d122e09fff
5
5
  SHA512:
6
- metadata.gz: b49a98655467d3b23743cb57aaa576e3767fb3b41b4cd60a6f84383867fa9057417fa5c24d607aa0a767b2ac4d176c4cf13ea47cbb0f3126a3db8de0165115d8
7
- data.tar.gz: 17fea527c1af979408455e7dd8313cde3a6bae10c0e69e6256cc736923fe5a952aba316a11dfe58edbf0fde7a786bb99d753e17bd99e1141896c9f3e099d290f
6
+ metadata.gz: 827ad6d4c2a90483d817062a46e008114d0e6635a08375b0fea74cf61547b1ea991af87df0b0a6f7d31ae018091cfd19d90f55a5810c720aaf46002d74e8ae45
7
+ data.tar.gz: 113a092feb781c40fc895546efab2737b5870d41f24c9c2e36e8307f49b518a0dfba0728e653429ca3d115be6b11e864434694bc6f5a09d7eef62549bae24cc2
@@ -1,9 +1,14 @@
1
1
  module Soundyoink
2
+
3
+ # Represents an audio post; given only a link, can name the file intelligently
4
+ # and write it to disk, as well as check whether the file has already been
5
+ # downloaded.
2
6
  class Audio
7
+
8
+ # Drawing the title from the URL is a little uglier than drawing it from
9
+ # the page text itself, but lets us skip files we already have without
10
+ # having to request the page. This saves a ton of time on user profiles.
3
11
  def initialize(url)
4
- # Drawing the title from the URL is a little uglier than drawing it from
5
- # the page text itself, but lets us skip files we already have without
6
- # having to request the page. This saves a ton of time on user profiles.
7
12
  user = url.match(%r{\/u\/(.+)\/})[1]
8
13
  title = url.match(%r{\/u\/.+\/(.+)})[1]
9
14
  @filename = "#{user} - #{title}.m4a"
@@ -12,6 +17,8 @@ module Soundyoink
12
17
  end
13
18
  end
14
19
 
20
+ # Writes the file to disk (in the form _author - title.m4a_) unless
21
+ # it already exists and is over 10 KB.
15
22
  def download
16
23
  return nil if already_exists?
17
24
  puts "Downloading #{@filename}..." if $stdout.isatty
@@ -20,9 +27,10 @@ module Soundyoink
20
27
  end
21
28
  end
22
29
 
30
+ # Check that not only does the file exist, but that it is over 10 KB, so
31
+ # that we can overwrite files that were opened but never written properly.
32
+ # @return [Boolean]
23
33
  def already_exists?
24
- # We check that not only does the file exist, but that it is over 10 KB,
25
- # so that we overwrite files that were opened but never written properly.
26
34
  File.exist?(@filename) && File.size(@filename) > 10_000
27
35
  end
28
36
  end
@@ -1,14 +1,19 @@
1
1
  module Soundyoink
2
+
3
+ # Manages a queue of Audio instances to be downloaded, and knows how to
4
+ # create many Audio instances from a user profile link.
2
5
  class Downloader
6
+
7
+ # @param workers [Integer] Number of threads to use to work the download queue.
3
8
  def initialize(workers: 2)
4
- # +workers+ will be the number of threads downloading audios in parallel.
5
9
  @audios = Queue.new
6
10
  @workers = workers
7
11
  end
8
12
 
13
+ # If given a link to an audio page, adds it to the queue.
14
+ # If given a user profile link, adds each individual audio to the queue.
15
+ # @param link [String] Link to either an individual audio or a user profile.
9
16
  def add(link)
10
- # If we were given a user profile link, we'll pass it to the +add_profile+
11
- # method.
12
17
  if link =~ %r{^https://.+[.net]/u/[^/]+$}
13
18
  add_profile(link)
14
19
  else
@@ -16,15 +21,17 @@ module Soundyoink
16
21
  end
17
22
  end
18
23
 
24
+ # Find every audio link on a user's profile and add them to the queue.
25
+ # @param profile [String] Link to a user's profile page.
19
26
  def add_profile(profile)
20
- # Find every audio link on a user's profile and add them to the queue.
21
- open(profile).read.scan(%r{(https://[^.]+[.]net/u/[^"]+)}).flatten.each do |audio|
27
+ open(profile).read.scan(%r{(https://[^.]+[.]net/u/[^"]+)}).flat_map do |audio|
22
28
  @audios << Audio.new(audio)
23
29
  end
24
30
  end
25
31
 
32
+ # +@workers+ number of threads work on the +@audios+ queue in parallel.
33
+ # @see Soundyoink::Audio#download
26
34
  def download
27
- # +@workers+ number of threads work on the +@audios+ queue in parallel.
28
35
  worker_threads = []
29
36
  @workers.times do
30
37
  worker_threads << Thread.new do
@@ -33,5 +40,7 @@ module Soundyoink
33
40
  end
34
41
  worker_threads.map(&:join)
35
42
  end
43
+
36
44
  end
45
+
37
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soundyoink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Plant
@@ -34,7 +34,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - ">="
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: '2.0'
38
38
  required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="
@@ -47,3 +47,4 @@ signing_key:
47
47
  specification_version: 4
48
48
  summary: SG audio downloader.
49
49
  test_files: []
50
+ has_rdoc: