lyricit 0.0.1

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: afcb5bdba7847f1506392f43ba012d7cc38e3644
4
+ data.tar.gz: c56ae771cf1040a9b6dc8bd61f7f5d8ba673f275
5
+ SHA512:
6
+ metadata.gz: 6554014202e6ca60991bdb58cc85172d239e55830f3ccd42ce9b399b704bcdac8b52d83d2769a2ca5910c269f846c4bc2e667ed6bbe8f23ee9fc543449470427
7
+ data.tar.gz: 3f6cb0fbc185d368cb811ff419ca0731c5432e4c5f2b8aef82b4dbd18eeb0332590e5720478d6f6d04be1003388edff2c5857775b3addbe560e6bffc490cb431
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
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
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lyricit.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Ankit Goyal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ankit Goyal
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,65 @@
1
+ # Lyricit
2
+
3
+ Add lyrics to your itunes songs through command line.
4
+
5
+ ## Installation
6
+
7
+ $ gem install lyricit
8
+
9
+ ## Usage
10
+
11
+ To update the lyrics for current song.
12
+
13
+ $ lyricit -c
14
+
15
+ To update the lyrics for a particular song
16
+
17
+ $ lyricit -s somebody
18
+
19
+ Above command will give you the list of songs matching the `somebody`
20
+
21
+ ```
22
+ 1 results found
23
+ |-----------------------------------------|
24
+ |Id | Name |
25
+
26
+ |-----------------------------------------|
27
+ |179 | Somebody That I Used To Know |
28
+ |-----------------------------------------|
29
+ Enter the Id for which you want the lyrics:
30
+
31
+ ```
32
+
33
+ Enter the Id for the song you want to update. `179` in above example.
34
+
35
+ Now the lyrics will be displayed on the terminal.
36
+
37
+ ```
38
+
39
+ "'Gotye:"'
40
+ Now and then I think of when we were together
41
+ Like when you said you felt so happy you could die
42
+ Told myself that you were right for me
43
+ But felt so lonely in your company
44
+ But that was love and it's an ache I still remember
45
+ ...
46
+
47
+ Update on iTunes? [Y/n]:
48
+
49
+ ```
50
+
51
+ Answer Y to the above question, if lyrics are what you expect.
52
+
53
+ ## TODO
54
+
55
+ 1. Add support for more APIs to fetch the song lyrics if first API fails.
56
+ 2. Add search by artist name. Provide more options.
57
+
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/lyricit ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lyricit'
4
+ require 'optparse'
5
+
6
+ class UploadLyrics
7
+
8
+ def initialize
9
+ @itunes = Lyricit::Itunes.new
10
+ @write_lyrics = false
11
+ @song_name = ""
12
+ end
13
+
14
+ def ask_for_song_name
15
+ print "** type: lyricit -h to see all options **\n"
16
+ print "Enter song name: "
17
+ @song_name = STDIN.gets.chomp
18
+ end
19
+
20
+ def find_by_name
21
+ results = @itunes.find_by_name @song_name
22
+ abort if results.nil?
23
+ end
24
+
25
+ def ask_for_db_id
26
+ print "Enter the Id for which you want the lyrics: "
27
+ @db_id = STDIN.gets.chomp
28
+ end
29
+
30
+ def get_lyrics
31
+ if $current
32
+ artist, name = @itunes.song_and_artist_by_current_track
33
+ if artist.strip == "" && name.strip == ""
34
+ print "Seems like you are not playing anything."
35
+ abort
36
+ end
37
+ @db_id = @itunes.db_id_of_current_track
38
+ else
39
+ artist, name = @itunes.song_and_artist_by_id @db_id
40
+ end
41
+ lyrics_api = Lyricit::LyricsApi.new artist, name
42
+ @lyrics = lyrics_api.get_lyrics
43
+ abort unless @lyrics
44
+ end
45
+
46
+ def confirm_lyrics
47
+ print @lyrics
48
+ print "Update on iTunes? [Y/n]: "
49
+ update = STDIN.gets.chomp
50
+ @write_lyrics = update.downcase == 'y' ? true : false
51
+ abort unless @write_lyrics
52
+ end
53
+
54
+ def write_lyrics
55
+ if @write_lyrics
56
+ @itunes.set_lyrics_by_id @db_id, @lyrics
57
+ print "Updated on iTunes!"
58
+ end
59
+ end
60
+
61
+ def run
62
+ unless $current
63
+ if $songname
64
+ @song_name = $songname
65
+ else
66
+ ask_for_song_name
67
+ end
68
+ find_by_name
69
+ ask_for_db_id
70
+ end
71
+ get_lyrics
72
+ confirm_lyrics
73
+ write_lyrics
74
+ end
75
+ end
76
+
77
+ OptionParser.new do |o|
78
+ o.on('-c', '--current','add lyrics for current song') { |b| $current = b }
79
+ o.on('-s SONGNAME', 'song name for which you want to add the lyrics') { |songname| $songname = songname }
80
+ o.on('-h') { puts o; exit }
81
+ o.parse!
82
+ end
83
+
84
+ upload_lyrics = UploadLyrics.new
85
+ upload_lyrics.run
data/commands.txt ADDED
@@ -0,0 +1 @@
1
+ db_ids = `osascript -e "tell application \\"iTunes\\" to (get database ID of every track in current playlist)"`
@@ -0,0 +1,66 @@
1
+ module Lyricit
2
+ class Itunes
3
+ def song_and_artist_by_current_track
4
+ artist=%x(osascript -e 'tell application "iTunes" to artist of current track as string');
5
+ name=%x(osascript -e 'tell application "iTunes" to name of current track as string');
6
+ [artist, name]
7
+ end
8
+
9
+ def song_and_artist_by_id db_id
10
+ return nil if db_id.strip == ""
11
+ artist = %x(osascript -e "tell application \\"iTunes\\" to get artist of (every track where database ID is #{db_id.strip})")
12
+ name = %x(osascript -e "tell application \\"iTunes\\" to get name of (every track where database ID is #{db_id.strip})")
13
+ [artist, name]
14
+ end
15
+
16
+ def db_id_of_current_track
17
+ %x(osascript -e 'tell application "iTunes" to database id of current track as string')
18
+ end
19
+
20
+ def add_lyrics lyrics, track
21
+ %x(osascript -e "tell application \\"iTunes\\" to set lyrics of current track to \\"#{lyrics}\\" ")
22
+ end
23
+
24
+ def set_lyrics_by_id db_id, lyrics
25
+ %x(osascript -e "tell application \\"iTunes\\" to set lyrics of (every track where database ID is #{db_id.strip}) to \\"#{lyrics}\\" ")
26
+ end
27
+
28
+ def find_by_name input
29
+
30
+ dirty_track_names = %x(osascript -e "tell application \\"iTunes\\" to name of tracks of library playlist 1")
31
+ track_names = dirty_track_names.split(',').map(&:strip)
32
+
33
+ matching_names = track_names.select{|v| v.downcase.match(/#{input.downcase}/)}
34
+ name_id = {}
35
+ matching_names.each do |name|
36
+ temp = %x(osascript -e "tell application \\"iTunes\\" to database id of (some track of library playlist 1 whose name is \\"#{name}\\")")
37
+ name_id[name] = temp.strip
38
+ end
39
+
40
+ print_matching_results name_id
41
+ end
42
+
43
+ def print_matching_results name_id_hash
44
+ if name_id_hash.empty?
45
+ print "No results found. Please try again."
46
+ return
47
+ end
48
+ maxk = 0
49
+ maxv = 0
50
+ name_id_hash.map {|k,v| maxk = k.length if k.length > maxk; maxv = v.length if v.length > maxv}
51
+ maxv += 4; maxk += 4
52
+
53
+ print "\n#{name_id_hash.count} results found\n"
54
+ print "|#{'-'* (maxk + maxv + 2)}|\n"
55
+ print "|Id#{' '*(maxv - 2)}| Name#{' '*(maxk -4)}|\n\n"
56
+ print "|#{'-'* (maxk + maxv + 2)}|\n"
57
+
58
+ name_id_hash.each do |name, id|
59
+ print "|#{id}#{' ' * (maxv - id.length)}| #{name}#{' '* (maxk - name.length)}|\n"
60
+ end
61
+
62
+ print "|#{'-'* (maxk + maxv + 2)}|\n"
63
+ return 0
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,31 @@
1
+ module Lyricit
2
+ class LyricsApi
3
+
4
+ def initialize song_artist, song_name
5
+ @song = song_name
6
+ @artist = song_artist
7
+ end
8
+
9
+ def get_lyrics
10
+ try_make_it_personal_api
11
+ end
12
+
13
+ def try_make_it_personal_api
14
+ lyrics = Lyricit::MakeItPersonal.get_lyrics @song, @artist
15
+
16
+ case lyrics
17
+ when nil
18
+ puts "Something seems to be wrong with the API. Try after some time."
19
+ return nil
20
+ when :not_found
21
+ puts "Sorry could not find the lyrics for the requested song."
22
+ return nil
23
+ when :incomplete_info
24
+ puts "Either Artist or Song Title seems to be incorrect!"
25
+ return nil
26
+ else
27
+ return lyrics
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ module Lyricit
2
+ module MakeItPersonal
3
+ def self.get_lyrics name, artist
4
+ print "Getting Lyrics for:\nSong: #{name.strip}\nArtist: #{artist}"
5
+ return :incomplete_info if name.strip == "" || artist.strip == ""
6
+ res = Faraday.get("http://makeitpersonal.co/lyrics?artist=#{artist.strip}&title=#{name.strip}")
7
+
8
+ return nil if res.status.to_i != 200
9
+
10
+ return :not_found if res.body.include?("Sorry")
11
+
12
+ return res.body
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Lyricit
2
+ VERSION = "0.0.1"
3
+ end
data/lib/lyricit.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "lyricit/version"
2
+ require 'lyricit/itunes'
3
+ require 'lyricit/lyrics_api'
4
+ require 'lyricit/make_it_personal'
5
+ require 'faraday'
6
+ module Lyricit
7
+ # Nothing Fancy here
8
+ end
data/lyricit.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lyricit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lyricit"
8
+ spec.version = Lyricit::VERSION
9
+ spec.authors = ["Ankit Goyal"]
10
+ spec.email = ["ankit3goyal@gmail.com"]
11
+ spec.description = %q{Update lyrics on iTunes from command line.}
12
+ spec.summary = %q{Update lyrics on iTunes by simply giving the song name from command line.}
13
+ spec.homepage = "http://goyalankit.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "faraday"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lyricit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ankit Goyal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
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: Update lyrics on iTunes from command line.
56
+ email:
57
+ - ankit3goyal@gmail.com
58
+ executables:
59
+ - lyricit
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/lyricit
70
+ - commands.txt
71
+ - lib/lyricit.rb
72
+ - lib/lyricit/itunes.rb
73
+ - lib/lyricit/lyrics_api.rb
74
+ - lib/lyricit/make_it_personal.rb
75
+ - lib/lyricit/version.rb
76
+ - lyricit.gemspec
77
+ homepage: http://goyalankit.com
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.1.10
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Update lyrics on iTunes by simply giving the song name from command line.
101
+ test_files: []