soundyoink 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44338e66fa50ed872f5aaee2d60c482da066483d
4
+ data.tar.gz: b5fe3e15da55618790d4cda49c0e07faec259ffc
5
+ SHA512:
6
+ metadata.gz: b49a98655467d3b23743cb57aaa576e3767fb3b41b4cd60a6f84383867fa9057417fa5c24d607aa0a767b2ac4d176c4cf13ea47cbb0f3126a3db8de0165115d8
7
+ data.tar.gz: 17fea527c1af979408455e7dd8313cde3a6bae10c0e69e6256cc736923fe5a952aba316a11dfe58edbf0fde7a786bb99d753e17bd99e1141896c9f3e099d290f
data/bin/soundyoink ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'soundyoink'
3
+
4
+ downloader = Soundyoink::Downloader.new
5
+ ARGV.each { |link| downloader.add(link) }
6
+ downloader.download
@@ -0,0 +1,29 @@
1
+ module Soundyoink
2
+ class Audio
3
+ 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
+ user = url.match(%r{\/u\/(.+)\/})[1]
8
+ title = url.match(%r{\/u\/.+\/(.+)})[1]
9
+ @filename = "#{user} - #{title}.m4a"
10
+ unless already_exists?
11
+ @file_url = open(url).read.match(%r{(https://.+net/sounds/.+[.]m4a)})[1]
12
+ end
13
+ end
14
+
15
+ def download
16
+ return nil if already_exists?
17
+ puts "Downloading #{@filename}..." if $stdout.isatty
18
+ File.open(@filename, 'wb') do |f|
19
+ f.print open(@file_url).read
20
+ end
21
+ end
22
+
23
+ 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
+ File.exist?(@filename) && File.size(@filename) > 10_000
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ module Soundyoink
2
+ class Downloader
3
+ def initialize(workers: 2)
4
+ # +workers+ will be the number of threads downloading audios in parallel.
5
+ @audios = Queue.new
6
+ @workers = workers
7
+ end
8
+
9
+ def add(link)
10
+ # If we were given a user profile link, we'll pass it to the +add_profile+
11
+ # method.
12
+ if link =~ %r{^https://.+[.net]/u/[^/]+$}
13
+ add_profile(link)
14
+ else
15
+ @audios << Audio.new(link)
16
+ end
17
+ end
18
+
19
+ 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|
22
+ @audios << Audio.new(audio)
23
+ end
24
+ end
25
+
26
+ def download
27
+ # +@workers+ number of threads work on the +@audios+ queue in parallel.
28
+ worker_threads = []
29
+ @workers.times do
30
+ worker_threads << Thread.new do
31
+ @audios.pop.download until @audios.empty?
32
+ end
33
+ end
34
+ worker_threads.map(&:join)
35
+ end
36
+ end
37
+ end
data/lib/soundyoink.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'open-uri'
2
+ require_relative './soundyoink/audio'
3
+ require_relative './soundyoink/downloader'
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soundyoink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Plant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Command-line utility for downloading SG material, either specific titles
14
+ or entire user histories.
15
+ email: ryan@ryanplant.net
16
+ executables:
17
+ - soundyoink
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/soundyoink
22
+ - lib/soundyoink.rb
23
+ - lib/soundyoink/audio.rb
24
+ - lib/soundyoink/downloader.rb
25
+ homepage: https://github.com/ryanplant-au/soundyoink
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: SG audio downloader.
49
+ test_files: []