myshazam 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/shazam2magnets +21 -0
- data/lib/myshazam.rb +49 -0
- data/lib/myshazam/version.rb +3 -0
- data/magnets.rb +80 -0
- data/myshazam.gemspec +26 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2dfb31dcca7c7c651b395360a188e6a7eb3f25da
|
4
|
+
data.tar.gz: 8333a27fc993ace688f49ccb973fb61ce711a701
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a22b364b5413a66c5cf742c7ab01e0c418130e01ba77ad72dd45d9605b1d0126d34f34ead2d9fc122bb9872f112abf3d62b144433bd7be236fffc51db0d27958
|
7
|
+
data.tar.gz: d4866d6793f63378cfa95b1379491316dad9389a27728da640749c8eddcae2daacd54ac9c81d5e80072ac50d9e986bc0763bfa18a41bbe9b868a9d71ff47b001
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
magnets.txt
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Oto Brglez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# myshazam
|
2
|
+
|
3
|
+
Tools for handling your Shazam history / dumps.
|
4
|
+
|
5
|
+
- [Oto Brglez](http://github.com/otobrglez)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install it as Ruby gem:
|
10
|
+
|
11
|
+
$ gem install myshazam
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
1. Login into your [Shazam](http://www.shazam.com/) account and click on [downlaod history](http://www.shazam.com/myshazam/download-history).
|
16
|
+
|
17
|
+
2. Convert Shazam ```myshazam-history.html``` into list of Torrent magnets with ```shazam2magnets``` command.
|
18
|
+
|
19
|
+
```
|
20
|
+
shazam2magnets ~/Downloads/myshazam-history.html &> magnets.txt
|
21
|
+
```
|
22
|
+
|
23
|
+
3. Download files with [aria2c client](http://aria2.sourceforge.net/) from magnets.txt.
|
24
|
+
|
25
|
+
```
|
26
|
+
aria2c -i magnets.txt -d ~/Download/MyShazam
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/otobrglez/myshazam/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/shazam2magnets
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'etc'
|
5
|
+
require 'pathname'
|
6
|
+
require 'nokogiri'
|
7
|
+
require 'net/http'
|
8
|
+
require 'open-uri'
|
9
|
+
require 'myshazam'
|
10
|
+
|
11
|
+
# Cry if no download_file
|
12
|
+
if ARGV[0].nil? or not File.exist?(download_file = ARGV[0].strip)
|
13
|
+
$stderr.puts "Error: Please specify path to \"myshazam-history.html\"!"
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
tracks = Myshazam::Track.list_from_file download_file
|
18
|
+
tracks.each do |track|
|
19
|
+
next if track.magnet.nil?
|
20
|
+
$stdout.puts track.magnet
|
21
|
+
end
|
data/lib/myshazam.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "myshazam/version"
|
2
|
+
|
3
|
+
module Myshazam
|
4
|
+
|
5
|
+
class Track < Struct.new(:author, :title, :shazam_id)
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def list_from_file download_file
|
9
|
+
ids = []
|
10
|
+
|
11
|
+
doc = Nokogiri::HTML(File.open(download_file, "r:utf-8"))
|
12
|
+
doc.xpath("//table/tr").map.with_index do |tr, i|
|
13
|
+
next if i == 0 # Skip header
|
14
|
+
|
15
|
+
# Find shazam id, don't parse return duplicates
|
16
|
+
link = tr.xpath("./td/a").first
|
17
|
+
shazam_id = Regexp.last_match[1].to_i if link.attributes["href"].to_s.strip =~ /t(\d+)$/
|
18
|
+
if ids.include? shazam_id; next; else ids.push(shazam_id); end
|
19
|
+
|
20
|
+
Track.new(
|
21
|
+
tr.children.first.content.to_s.strip, # Title
|
22
|
+
tr.xpath("./td[position()=2]").first.content.to_s.strip, # Author
|
23
|
+
shazam_id
|
24
|
+
)
|
25
|
+
end.compact
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
[self.author, self.title].compact.join(" ").strip
|
31
|
+
end
|
32
|
+
|
33
|
+
def magnet_from_piratebay
|
34
|
+
begin
|
35
|
+
search_url = "http://thepiratebay.se/search/%s" % URI::encode(to_s)
|
36
|
+
doc = Nokogiri::HTML open(search_url)
|
37
|
+
doc.xpath("//a[starts-with(@href,'magnet')]").first.attributes["href"].to_s
|
38
|
+
rescue
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def magnet
|
44
|
+
@magnet ||= magnet_from_piratebay
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/magnets.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'etc'
|
5
|
+
require 'pathname'
|
6
|
+
require 'nokogiri'
|
7
|
+
require 'net/http'
|
8
|
+
require 'data_mapper'
|
9
|
+
require 'open-uri'
|
10
|
+
|
11
|
+
class Track < Struct.new(:author, :title, :shazam_id)
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def list_from_file download_file
|
15
|
+
ids = []
|
16
|
+
|
17
|
+
doc = Nokogiri::HTML(File.open(download_file, "r:utf-8"))
|
18
|
+
doc.xpath("//table/tr").map.with_index do |tr, i|
|
19
|
+
next if i == 0 # Skip header
|
20
|
+
|
21
|
+
# Find shazam id, don't parse return duplicates
|
22
|
+
link = tr.xpath("./td/a").first
|
23
|
+
shazam_id = Regexp.last_match[1].to_i if link.attributes["href"].to_s.strip =~ /t(\d+)$/
|
24
|
+
if ids.include? shazam_id; next; else ids.push(shazam_id); end
|
25
|
+
|
26
|
+
Track.new(
|
27
|
+
tr.children.first.content.to_s.strip, # Title
|
28
|
+
tr.xpath("./td[position()=2]").first.content.to_s.strip, # Author
|
29
|
+
shazam_id
|
30
|
+
)
|
31
|
+
end.compact
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
[self.author, self.title].compact.join(" ").strip
|
37
|
+
end
|
38
|
+
|
39
|
+
def magnet_from_piratebay
|
40
|
+
begin
|
41
|
+
search_url = "http://thepiratebay.se/search/%s" % URI::encode(to_s)
|
42
|
+
doc = Nokogiri::HTML open(search_url)
|
43
|
+
doc.xpath("//a[starts-with(@href,'magnet')]").first.attributes["href"].to_s
|
44
|
+
rescue
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def magnet
|
50
|
+
@magnet ||= magnet_from_piratebay
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
# Cry if no download_file
|
56
|
+
unless File.exist?(download_file = ARGV[0].strip)
|
57
|
+
$stderr.puts "Error: Please specify path to \"myshazam-history.html\"!"
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
# # DataMapper
|
62
|
+
# database_path = ENV["MYSHAZAM_DB"] || "sqlite://#{Pathname.new(Etc.getpwuid.dir).join("myshazam.db")}"
|
63
|
+
# $stdout.puts "Database: #{database_path}"
|
64
|
+
# DataMapper.setup(:default, database_path)
|
65
|
+
# DataMapper.finalize
|
66
|
+
# DataMapper.auto_upgrade!
|
67
|
+
|
68
|
+
# # Destination folder
|
69
|
+
# download_folder = ARGV[1] || ENV["MYSHAZAM_MUSIC"] || Pathname.new(Etc.getpwuid.dir).join("Music", "MyShazam")
|
70
|
+
# $stdout.puts "Destination: #{download_folder}"
|
71
|
+
# unless Dir.exists? download_folder
|
72
|
+
# $stdout.puts "Error: Missing folder: #{download_folder}"
|
73
|
+
# exit 1
|
74
|
+
# end
|
75
|
+
|
76
|
+
tracks = Track.list_from_file download_file
|
77
|
+
tracks.each do |track|
|
78
|
+
next if track.magnet.nil?
|
79
|
+
$stdout.puts track.magnet
|
80
|
+
end
|
data/myshazam.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'myshazam/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "myshazam"
|
8
|
+
spec.version = Myshazam::VERSION
|
9
|
+
spec.authors = ["Oto Brglez"]
|
10
|
+
spec.email = ["otobrglez@gmail.com"]
|
11
|
+
spec.summary = %q{Tools for handling your Shazam history / dumps.}
|
12
|
+
spec.description = %q{Set of scripts and tools to work with your Shazam history / data / dumps.}
|
13
|
+
spec.homepage = "http://github.com/otobrglez/myshazam"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "nokogiri", "~> 1.6"
|
22
|
+
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: myshazam
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oto Brglez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Set of scripts and tools to work with your Shazam history / data / dumps.
|
56
|
+
email:
|
57
|
+
- otobrglez@gmail.com
|
58
|
+
executables:
|
59
|
+
- shazam2magnets
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/shazam2magnets
|
69
|
+
- lib/myshazam.rb
|
70
|
+
- lib/myshazam/version.rb
|
71
|
+
- magnets.rb
|
72
|
+
- myshazam.gemspec
|
73
|
+
homepage: http://github.com/otobrglez/myshazam
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Tools for handling your Shazam history / dumps.
|
97
|
+
test_files: []
|