last-dup 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in last-dup.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Stefan Otto
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.
@@ -0,0 +1,30 @@
1
+ # LastDup
2
+
3
+ ## Installation
4
+
5
+ $ gem install last-dup
6
+
7
+ ## Usage
8
+
9
+ last-dup [...--param=val...] dir
10
+
11
+ Params:
12
+ --api_key=String Your Lastfm API key [Required]
13
+ --api_secret=String Your Lastfm API key secret [Required]
14
+ -u, --username=String The Lastfm account to check against [Required]
15
+
16
+ You can get your Last.fm API key from http://www.last.fm/api/account/create.
17
+
18
+ On first run, a blank config file will be created in your home directory for you to provide those.
19
+
20
+ Commandline arguments will always have precedence.
21
+
22
+ The given directory will be scanned recursively by default.
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it ( http://github.com/<my-github-username>/smart_dup/fork )
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require 'last-dup/cli'
2
+ LastDup::CLI.run
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'last-dup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "last-dup"
8
+ spec.version = LastDup::VERSION
9
+ spec.authors = ["Stefan Otto"]
10
+ spec.email = ["sotto.de@gmail.com"]
11
+ spec.summary = %q{Checks a given directory for music you already listened to using your last.fm handle}
12
+ #spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = "https://github.com/stefanotto/last-dup"
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
+ spec.bindir = 'bin'
21
+ spec.executables = ['last-dup']
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_dependency "lastfm", "~> 1.23.0"
26
+ spec.add_dependency "mp3info", "~> 0.6.18"
27
+ spec.add_dependency "configliere", "~> 0.4.18"
28
+ end
@@ -0,0 +1,9 @@
1
+ require "last-dup/version"
2
+ require "last-dup/helper"
3
+ require "last-dup/lastfm_enquirer"
4
+ require "last-dup/album"
5
+ require "last-dup/settings"
6
+
7
+ module LastDup
8
+ include Helper
9
+ end
@@ -0,0 +1,38 @@
1
+ require 'mp3info'
2
+
3
+ module LastDup
4
+
5
+ class Album
6
+
7
+ attr_reader :metadata, :folder_name
8
+
9
+ def initialize(folder_name)
10
+ @folder_name = folder_name
11
+ @album_proxy_file = Dir.glob("#{folder_name}/*.mp3")[0]
12
+ grab_metadata!
13
+ end
14
+
15
+
16
+ def grab_metadata!()
17
+ @metadata = {}
18
+ Mp3Info.open(@album_proxy_file) do |proxy_file|
19
+ break unless proxy_file.hastag?
20
+ artist = proxy_file.tag.artist
21
+ @metadata[:artist] = artist unless artist.nil?
22
+ album_title = proxy_file.tag.album
23
+ @metadata[:album_title] = album_title unless album_title.nil?
24
+ end
25
+ @metadata
26
+ end
27
+
28
+ def tags_are_present?(*tags)
29
+ tags.each do |tag|
30
+ return false unless @metadata.has_key? tag
31
+ end
32
+ return true
33
+ end
34
+
35
+ protected :grab_metadata!
36
+
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require "last-dup"
2
+ require "singleton"
3
+
4
+ module LastDup
5
+ class Cli
6
+ include Singleton
7
+ include Helper
8
+
9
+ def run
10
+
11
+ if Settings.rest.empty?
12
+ input_folder = "."
13
+ else
14
+ input_folder = Settings.rest[0]
15
+ end
16
+
17
+ input_folder = File.expand_path(input_folder)
18
+
19
+ unless File.directory?(input_folder)
20
+ puts "#{input_folder} is not a valid folder!"
21
+ end
22
+
23
+ music_folders = gather_music_folders(input_folder)
24
+ lastfm = LastfmEnquirer.instance
25
+
26
+ music_folders.each do |folder_name|
27
+ album = Album.new(folder_name)
28
+ next unless album.tags_are_present?(:artist, :album_title)
29
+ if lastfm.i_have_heart_this?(album)
30
+ puts "#{album.metadata[:artist]} - #{album.metadata[:album_title]}"
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ CLI = Cli.instance
38
+ end
@@ -0,0 +1,13 @@
1
+ module LastDup
2
+ module Helper
3
+ def gather_music_folders(root_folder)
4
+ music_folders = []
5
+ Dir.glob("#{root_folder}/**/*") do |file|
6
+ if (File.directory? file) && Dir.glob("#{file}/*.mp3").size != 0
7
+ music_folders << file
8
+ end
9
+ end
10
+ return music_folders
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ require 'lastfm'
2
+ require 'singleton'
3
+
4
+ module LastDup
5
+ class LastfmEnquirer
6
+ include Singleton
7
+
8
+ def initialize(user='pppr')
9
+ @api_key = Settings[:api_key]
10
+ @api_secret = Settings[:api_secret]
11
+ @connection = Lastfm.new(@api_key, @api_secret)
12
+ @username = Settings[:username]
13
+ end
14
+
15
+ def i_have_heart_this?(album)
16
+ query = {
17
+ 'artist' => album.metadata[:artist],
18
+ 'album' => album.metadata[:album_title],
19
+ 'username' => @username
20
+ }
21
+ result = @connection.album.get_info(query)
22
+ return result.has_key? 'userplaycount'
23
+ rescue Lastfm::ApiError
24
+ # album not found
25
+ return false
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'configliere'
2
+
3
+ Settings.use :commandline
4
+
5
+ Settings.define :api_key, required: true, description: "Your Lastfm API key"
6
+ Settings.define :api_secret, required: true, description: "Your Lastfm API key secret"
7
+ Settings.define :username, required: true, flag: "u", description: "The Lastfm account to check against"
8
+
9
+ CONFIG_FILE_LOCATION = File.join(Dir.home, '.last-dup/')
10
+ CONFIG_FILE = File.join(CONFIG_FILE_LOCATION, 'lastfm.yaml')
11
+
12
+ unless File.exists?(CONFIG_FILE)
13
+ File.open(CONFIG_FILE, 'w') do |file|
14
+ file.puts ':api_key: '
15
+ file.puts ':api_secret: '
16
+ file.puts ':username: '
17
+ end
18
+ end
19
+
20
+ Settings.read CONFIG_FILE
21
+
22
+ begin
23
+ Settings.resolve!
24
+ rescue => message
25
+ puts message
26
+ end
@@ -0,0 +1,3 @@
1
+ module LastDup
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: last-dup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stefan Otto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: lastfm
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.23.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.23.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: mp3info
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.6.18
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.6.18
78
+ - !ruby/object:Gem::Dependency
79
+ name: configliere
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.4.18
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.4.18
94
+ description:
95
+ email:
96
+ - sotto.de@gmail.com
97
+ executables:
98
+ - last-dup
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/last-dup
108
+ - last-dup.gemspec
109
+ - lib/last-dup.rb
110
+ - lib/last-dup/album.rb
111
+ - lib/last-dup/cli.rb
112
+ - lib/last-dup/helper.rb
113
+ - lib/last-dup/lastfm_enquirer.rb
114
+ - lib/last-dup/settings.rb
115
+ - lib/last-dup/version.rb
116
+ homepage: https://github.com/stefanotto/last-dup
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.28
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Checks a given directory for music you already listened to using your last.fm
141
+ handle
142
+ test_files: []