hypembot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hypembot.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2012 Kirk Scheibelhut <kjs@scheibo.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person ob-
4
+ taining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without restric-
6
+ tion, including without limitation the rights to use, copy, modi-
7
+ fy, merge, publish, distribute, sublicense, and/or sell copies of
8
+ the Software, and to permit persons to whom the Software is fur-
9
+ nished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN-
17
+ FRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19
+ 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
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # hypembot
2
+
3
+ Manually downloading songs from Hypemachine too difficult? Wish you could
4
+ download that song from Soundcloud? Since the browser stores songs in its cache
5
+ in order to play them, simply start `hypembot` and it will monitor the cache,
6
+ copying mp3's into your Music directory.
7
+
8
+ ## How does it work?
9
+
10
+ The program monitors your browser cache using `kqueue` and once a 'quality' mp3
11
+ file has been stable in the cache for 5 minutes, `hypembot` copies out of the
12
+ cache for you.
13
+
14
+ ## Install
15
+
16
+ $ [sudo] gem install hypembot
17
+ $ hypembot
18
+
19
+ Works on Mac OSX Lion. Uses kqueue by default.
20
+
21
+ ## Copyright
22
+
23
+ `hypembot` is Copyright (c) 2011 [Kirk Scheibelhut](http://scheibo.com/about) and distributed under the MIT license.<br />
24
+ See the `LICENSE` file for further details regarding licensing and distribution.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/hypembot ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $:.unshift(lib) if File.directory?(lib) && !$:.include?(lib)
4
+ require 'hypembot'
5
+ require 'optparse'
6
+
7
+ opts = {}
8
+ ARGV.options do |argv|
9
+ argv.banner = "Usage: hypembot [options]"
10
+ argv.on("-s", "--source", String, "Path of the cache to watch") { |s| opts[:source] = s }
11
+ argv.on("-d", "--directory", String, "Path of the directory to copy music to") { |d| opts[:directory] = d }
12
+ argv.on("-b", "--bitrate", Integer, "Minimum bitrate of a song") { |b| opts[:bitrate] = b }
13
+ argv.on("-l", "--length", Integer, "Minimum length of a song") { |l| opts[:length] = l }
14
+ end
15
+
16
+ Process.daemon
17
+ Hypembot::Bot.new(opts).start
data/hypembot.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hypembot/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hypembot"
7
+ s.version = Hypembot::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kirk Scheibelhut"]
10
+ s.email = ["kjs@scheibo.com"]
11
+ s.homepage = "https://github.com/scheibo/hypembot"
12
+ s.summary = "Play music while browsing - have it appear in your Music folder."
13
+ s.description = s.summary
14
+
15
+ s.rubyforge_project = "hypembot"
16
+
17
+ s.add_dependency "directory_watcher"
18
+ s.add_dependency "eventmachine"
19
+ s.add_dependency "growl"
20
+ s.add_dependency "mp3info"
21
+
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "bundler", "~> 1.0.0"
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.default_executable = 'hypembot'
29
+ s.require_paths = ["lib"]
30
+ end
@@ -0,0 +1,3 @@
1
+ module Hypembot
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hypembot.rb ADDED
@@ -0,0 +1,92 @@
1
+ module Hypembot; end
2
+ require 'hypembot/version'
3
+ require 'directory_watcher'
4
+ require 'eventmachine'
5
+ require 'growl'
6
+ require 'mp3info'
7
+ require 'fileutils'
8
+
9
+ class Hypembot::Bot
10
+ def initialize(opts)
11
+ @source = opts[:source] || "#{ENV['HOME']}/Library/Caches/Google/Chrome/Default/Cache/"
12
+ @dir = opts[:directory] || "#{ENV["HOME"]}/Music"
13
+ @min_bitrate = opts[:bitrate] || 125
14
+ @min_length = opts[:length] || 60
15
+
16
+ @dw = DirectoryWatcher.new(@source,
17
+ :scanner => :em,
18
+ :pre_load => true,
19
+ :glob => 'f_*',
20
+ :stable => 30,
21
+ :interval => 10)
22
+ end
23
+
24
+ def start
25
+ setup
26
+ # make sure to set ulimit -n 4096 or something similarily high
27
+ EM.kqueue
28
+ @dw.start
29
+
30
+ loop { sleep 1000 }
31
+ end
32
+
33
+ private
34
+
35
+ def setup
36
+ @dw.add_observer do |*args|
37
+ args.each do |event|
38
+ verify_mp3(event.path) if event.type == :stable
39
+ end
40
+ end
41
+ end
42
+
43
+ def verify_mp3(file)
44
+ Mp3Info.open(file) do |mp3|
45
+ if mp3.length >= @min_length and mp3.bitrate >= @min_bitrate
46
+ process(file, mp3)
47
+ end
48
+ end
49
+ rescue
50
+ nil
51
+ end
52
+
53
+ def process(file, mp3)
54
+ info = {}
55
+ info[:title] = mp3.tag.title.strip.empty? ? "Untitled" : mp3.tag.title.strip
56
+ info[:artist] = mp3.tag.artist.strip
57
+ info[:album] = mp3.tag.album.strip
58
+ info[:length] = format_time(mp3.length)
59
+ info[:bitrate] = "#{mp3.bitrate} kbps" + (mp3.vbr ? "" : " (VBR)")
60
+
61
+ growl(info)
62
+ FileUtils.cp(file, filename(info))
63
+ end
64
+
65
+ def growl(info)
66
+ message = ""
67
+ if !info[:artist].empty? and !info[:album].empty?
68
+ message << "#{info[:artist]}\n#{info[:album]}\n"
69
+ elsif info[:album].empty?
70
+ message << "#{info[:artist]}\n"
71
+ # if we have album but no artist, don't show anything
72
+ end
73
+ message << "(#{info[:length]}) - #{info[:bitrate]}"
74
+
75
+ Growl.notify do |n|
76
+ n.title = info[:title]
77
+ n.message = message
78
+ end
79
+ end
80
+
81
+ def format_time(s)
82
+ mins = s.to_i / 60
83
+ secs = s.to_i % 60
84
+ secs < 10 ? "#{mins}:0#{secs}" : "#{mins}:#{secs}"
85
+ end
86
+
87
+ def filename(info)
88
+ title = info[:title].split.join("_")
89
+ artist = info[:artist].split.join("_")
90
+ File.expand_path("#{title}-#{artist}.mp3", @dir)
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hypembot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kirk Scheibelhut
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: directory_watcher
16
+ requirement: &70255151078220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70255151078220
25
+ - !ruby/object:Gem::Dependency
26
+ name: eventmachine
27
+ requirement: &70255151077800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70255151077800
36
+ - !ruby/object:Gem::Dependency
37
+ name: growl
38
+ requirement: &70255151077380 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70255151077380
47
+ - !ruby/object:Gem::Dependency
48
+ name: mp3info
49
+ requirement: &70255151076960 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70255151076960
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: &70255151076540 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70255151076540
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &70255151076040 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70255151076040
80
+ description: Play music while browsing - have it appear in your Music folder.
81
+ email:
82
+ - kjs@scheibo.com
83
+ executables:
84
+ - hypembot
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - .gitignore
89
+ - Gemfile
90
+ - LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - bin/hypembot
94
+ - hypembot.gemspec
95
+ - lib/hypembot.rb
96
+ - lib/hypembot/version.rb
97
+ homepage: https://github.com/scheibo/hypembot
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project: hypembot
117
+ rubygems_version: 1.8.6
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Play music while browsing - have it appear in your Music folder.
121
+ test_files: []