emusic-downloader 0.5
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.
- data/Manifest +5 -0
- data/Rakefile +16 -0
- data/bin/emusic +62 -0
- data/emusic-downloader.gemspec +33 -0
- data/lib/emusic.rb +70 -0
- metadata +63 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
require 'hpricot'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
Echoe.new('emusic-downloader', '0.5') do |p|
|
9
|
+
p.description = "Download eMusic .emz files"
|
10
|
+
p.url = "http://nickrowe.info"
|
11
|
+
p.author = "Nicholas Rowe"
|
12
|
+
p.email = "nixterrimus@gmail.com"
|
13
|
+
p.ignore_pattern = ["tmp/*", "script/*", "README.textile"]
|
14
|
+
p.development_dependencies = []
|
15
|
+
end
|
16
|
+
|
data/bin/emusic
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# emusic takes the name of an XML file containing URLs for
|
4
|
+
# emusic music and downloads them. There are some neat options
|
5
|
+
# for choosing where your files are stored.
|
6
|
+
#
|
7
|
+
# Author:: Nicholas Rowe (mailto:nixterrimus@gmail.com)
|
8
|
+
# Copyright:: Written by Nicholas Rowe in early 2009
|
9
|
+
# License:: Not Currently assigned
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
require 'optparse'
|
13
|
+
require 'emusic.rb'
|
14
|
+
|
15
|
+
class EMusic
|
16
|
+
VERSION = '0.5'
|
17
|
+
|
18
|
+
def initialize(arguments, stdin)
|
19
|
+
|
20
|
+
# Process the arguments, starting with pulling the filename off the front
|
21
|
+
if arguments.size>0
|
22
|
+
file = arguments[0]
|
23
|
+
options = {}
|
24
|
+
OptionParser.new do |opts|
|
25
|
+
opts.banner = "Usage: emusic filename [options]"
|
26
|
+
opts.on("--version"){output_version; exit 0}
|
27
|
+
opts.on("-d directory", "--directory directory", "Save to a specified directory") do |directory|
|
28
|
+
options[:directory] = directory
|
29
|
+
end
|
30
|
+
opts.on("-c directory", "--create directory", "Creates directory and saves to it") do |directory|
|
31
|
+
options[:directory] = directory
|
32
|
+
options[:force_create] = true
|
33
|
+
end
|
34
|
+
opts.on("-r", "--remove", "Removes the source file from eMusic after donwloading"){options[:remove] = true}
|
35
|
+
opts.on("-v", "--verbose", "Outputs, verbosely"){options[:verbose] = true}
|
36
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
37
|
+
puts opts
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end.parse! rescue error
|
41
|
+
EMusicUtility.download_media(file, options)
|
42
|
+
else
|
43
|
+
puts "emusic: Missing source file, use -h switch to see all options"
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def output_version()
|
49
|
+
puts "emusic: version #{VERSION} written by Nicholas Rowe"
|
50
|
+
end
|
51
|
+
|
52
|
+
def error
|
53
|
+
puts "emusic: Invalid option(s), use -h switch to see all options"
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
app = EMusic.new(ARGV, STDIN)
|
61
|
+
|
62
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{emusic-downloader}
|
5
|
+
s.version = "0.5"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Nicholas Rowe"]
|
9
|
+
s.date = %q{2010-03-30}
|
10
|
+
s.default_executable = %q{emusic}
|
11
|
+
s.description = %q{Download eMusic .emz files}
|
12
|
+
s.email = %q{nixterrimus@gmail.com}
|
13
|
+
s.executables = ["emusic"]
|
14
|
+
s.extra_rdoc_files = ["bin/emusic", "lib/emusic.rb"]
|
15
|
+
s.files = ["Manifest", "Rakefile", "bin/emusic", "emusic-downloader.gemspec", "lib/emusic.rb"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://nickrowe.info}
|
18
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Emusic-downloader", "--main", "README.rdoc"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = %q{emusic-downloader}
|
21
|
+
s.rubygems_version = %q{1.3.1}
|
22
|
+
s.summary = %q{Download eMusic .emz files}
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 2
|
27
|
+
|
28
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
29
|
+
else
|
30
|
+
end
|
31
|
+
else
|
32
|
+
end
|
33
|
+
end
|
data/lib/emusic.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hpricot'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
class EMusicUtility
|
6
|
+
|
7
|
+
def EMusicUtility.download_media(filename, options = {})
|
8
|
+
# The method that does all of the downloading
|
9
|
+
|
10
|
+
# First, check if the file that we want to download from exists, if it does process it
|
11
|
+
if File.exists? filename
|
12
|
+
doc = Hpricot.XML(open(filename))
|
13
|
+
|
14
|
+
# If the directory flag isn't set, save the album as ARIST - ALBUM
|
15
|
+
if !options[:directory]
|
16
|
+
directory = "#{(doc.at("ARTIST")).inner_html} - #{(doc.at("ALBUM")).inner_html}"
|
17
|
+
if !File.directory? directory
|
18
|
+
FileUtils.mkdir directory
|
19
|
+
end
|
20
|
+
|
21
|
+
# If the directory flag is set
|
22
|
+
else
|
23
|
+
directory = options[:directory]
|
24
|
+
if ((options[:force_create] == true) && (!File.directory? directory))
|
25
|
+
FileUtils.mkdir directory
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if !File.directory? directory
|
30
|
+
puts "emusic: Directory #{directory} not found, use the -D switch to force the creation of it"
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
if (options[:verbose] == true)
|
35
|
+
puts "emusic: Downloading to: " + directory + "/"
|
36
|
+
end
|
37
|
+
|
38
|
+
# download the tracks
|
39
|
+
tracks = (doc/:TRACK)
|
40
|
+
|
41
|
+
if tracks.size>0
|
42
|
+
tracks.each do |track|
|
43
|
+
title = (track/:TITLE).inner_html
|
44
|
+
title = title.gsub(/\//, '\\')
|
45
|
+
title = title.gsub(/'/, "'")
|
46
|
+
if (options[:verbose] == true)
|
47
|
+
puts "emusic: Downloading #{title}"
|
48
|
+
end
|
49
|
+
open(directory + "/" + title + ".mp3","w").write(open((track/:TRACKURL).inner_html).read)
|
50
|
+
end
|
51
|
+
if (options[:verbose] == true)
|
52
|
+
puts "emusic: Download complete!"
|
53
|
+
end
|
54
|
+
else
|
55
|
+
puts "emusic: No downloads found in file: #{filename}"
|
56
|
+
end
|
57
|
+
|
58
|
+
if options[:remove] == true
|
59
|
+
File.delete(filename)
|
60
|
+
if (options[:verbose] == true)
|
61
|
+
puts "emusic: Removed File #{filename}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
else
|
65
|
+
puts "emusic: File #{filename} not found"
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: emusic-downloader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.5"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicholas Rowe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-30 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Download eMusic .emz files
|
17
|
+
email: nixterrimus@gmail.com
|
18
|
+
executables:
|
19
|
+
- emusic
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- bin/emusic
|
24
|
+
- lib/emusic.rb
|
25
|
+
files:
|
26
|
+
- Manifest
|
27
|
+
- Rakefile
|
28
|
+
- bin/emusic
|
29
|
+
- emusic-downloader.gemspec
|
30
|
+
- lib/emusic.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://nickrowe.info
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --line-numbers
|
36
|
+
- --inline-source
|
37
|
+
- --title
|
38
|
+
- Emusic-downloader
|
39
|
+
- --main
|
40
|
+
- README.rdoc
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "1.2"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: emusic-downloader
|
58
|
+
rubygems_version: 1.3.1
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: Download eMusic .emz files
|
62
|
+
test_files: []
|
63
|
+
|