radikocopy 0.2.0

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: 7403095016e0db5737b4c43b33d3ea8d54743101
4
+ data.tar.gz: bf8beaa481ba9b01bdae5de5901a07c1545fe3ec
5
+ SHA512:
6
+ metadata.gz: 55da42d6939ed1986c4baf1509b7ed23d96ab3e8b7093134e6ed1c9c6c65552b7fc93aa71ba0d121782012c3b4ff1e32effbdaedf6a2982df771049d423017e4
7
+ data.tar.gz: d761c1c8df7dec9187a1affc988609366321d1b0658333d24fd77748ec99924d9f5dd7f7192b862ad07433a982cdeec4c505dd714a41721a728990da43ed5614
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at src@srcw.net. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in radikocopy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 src
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Radikocopy
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/radikocopy`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'radikocopy'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install radikocopy
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/radikocopy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "radikocopy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ remote:
2
+ host: bronze
3
+ dir: /Users/sora/Music/Audio Hijack
4
+
5
+ local:
6
+ dir: /Users/sora/Music/Audio Hijack
data/exe/radikocopy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "radikocopy"
4
+ Radikocopy::Command.run(ARGV)
5
+
@@ -0,0 +1,3 @@
1
+ module Radikocopy
2
+ VERSION = "0.2.0"
3
+ end
data/lib/radikocopy.rb ADDED
@@ -0,0 +1,139 @@
1
+ # coding: utf-8
2
+ require "radikocopy/version"
3
+ require 'yaml'
4
+ require "optparse"
5
+
6
+ module Radikocopy
7
+ class Config
8
+ def initialize(config)
9
+ @config = config
10
+ @remote_host = config_value("remote", "host", false)
11
+ @remote_dir = config_value("remote", "dir", false)
12
+ @local_dir = config_value("local", "dir", true)
13
+ unless FileTest.directory?(@local_dir)
14
+ raise RuntimeError, "local_dir does not exists: #{@local_dir}"
15
+ end
16
+ dir = File.dirname(File.expand_path(__FILE__))
17
+ @import_scpt = File.join(dir, "radikoimport.scpt")
18
+ end
19
+
20
+ attr_reader :remote_host, :remote_dir, :local_dir, :import_scpt
21
+
22
+ def to_s
23
+ str = ''
24
+ str << "remote_host: #{remote_host}\n"
25
+ str << "remote_dir: #{remote_dir}\n"
26
+ str << "local_dir: #{local_dir}\n"
27
+ str << "import_scpt: #{import_scpt}\n"
28
+ end
29
+
30
+ def local_only?
31
+ @remote_host.nil? || @remote_dir.nil?
32
+ end
33
+
34
+ private
35
+ def config_value(section, key, require)
36
+ value = @config[section][key]
37
+ if require && (value.nil? || value.empty?)
38
+ raise RuntimeError, "#{section}:#{key}: is empty"
39
+ end
40
+ value
41
+ end
42
+ end
43
+
44
+ class Command
45
+ def self.run(argv)
46
+ STDOUT.sync = true
47
+ opts = {}
48
+ opt = OptionParser.new(argv)
49
+ opt.banner = "Usage: #{opt.program_name} [-h|--help] [config.yml]"
50
+ opt.separator('')
51
+ opt.separator "Options:"
52
+ opt.on_head('-h', '--help', 'Show this message') do |v|
53
+ puts opt.help
54
+ exit
55
+ end
56
+ opt.on('-v', '--verbose', 'Verbose message') {|v| opts[:v] = v}
57
+ opt.on('-n', '--dry-run', 'Message only') {|v| opts[:n] = v}
58
+ opt.on('-f', '--force-import', 'Force import') {|v| opts[:f] = v}
59
+ opt.parse!(argv)
60
+
61
+ # 最後の引数は設定ファイルのパス
62
+ config_file = argv.empty? ? "~/.radikocopyrc" : argv[0]
63
+ config_file = File.expand_path(config_file)
64
+ unless FileTest.file?(config_file)
65
+ puts opt.help
66
+ exit
67
+ end
68
+ config = Config.new(YAML.load_file(config_file))
69
+ puts config
70
+ radikocopy = Command.new(opts, config)
71
+ radikocopy.run
72
+ end
73
+
74
+ def initialize(opts, config)
75
+ @opts = opts
76
+ @config = config
77
+ end
78
+
79
+ def run
80
+ puts "##### start radikocopy #####"
81
+ filenames = []
82
+ if @opts[:f] || @config.local_only?
83
+ filenames = Dir.glob("#{@config.local_dir}/*.{mp3,m4a}")
84
+ else
85
+ filenames = copy_files
86
+ end
87
+ import_files(filenames)
88
+ puts "##### end radikocopy #####"
89
+ end
90
+
91
+ def copy_files
92
+ # リモートホスト内の録音ファイルをローカルにコピー
93
+ list_command = "ssh #{@config.remote_host} 'find \"#{@config.remote_dir}\"'"
94
+ puts list_command
95
+ result = `#{list_command}`
96
+ files = []
97
+ result.each_line do |line|
98
+ line.chomp!
99
+ if line =~ /mp3$/ || line =~ /m4a$/
100
+ if copy_file(line)
101
+ basename = File.basename(line)
102
+ local_file = File.join(@config.local_dir, basename)
103
+ puts "local_file: #{local_file}"
104
+ files << local_file
105
+ end
106
+ end
107
+ end
108
+ files
109
+ end
110
+
111
+ def copy_file(filename)
112
+ basename = File.basename(filename)
113
+ local_file = File.join(@config.local_dir, basename)
114
+ if FileTest.file?(local_file)
115
+ puts "exists local_file #{local_file}"
116
+ return false
117
+ end
118
+ copy_command = "scp #{@config.remote_host}:\"'#{filename}'\" \"#{@config.local_dir}\""
119
+ runcmd(copy_command)
120
+ true
121
+ end
122
+
123
+ def import_files(files)
124
+ files.each do |file|
125
+ cmd = "osascript #{@config.import_scpt} \"#{file}\""
126
+ runcmd(cmd)
127
+ end
128
+ end
129
+
130
+ def runcmd(cmd)
131
+ puts cmd
132
+ unless system(cmd)
133
+ puts "system error"
134
+ exit(1)
135
+ end
136
+ end
137
+ end
138
+
139
+ end
@@ -0,0 +1,9 @@
1
+ on run argv
2
+ set a to item 1 of argv
3
+ set theFile to (a as POSIX file) as alias
4
+
5
+ tell application "iTunes"
6
+ set aTrack to (add theFile)
7
+ set bookmarkable of aTrack to true
8
+ end tell
9
+ end run
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'radikocopy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "radikocopy"
8
+ spec.version = Radikocopy::VERSION
9
+ spec.authors = ["src"]
10
+ spec.email = ["src@srcw.net"]
11
+
12
+ spec.summary = %q{Radiko copy tool}
13
+ spec.description = %q{Radiko copy tool}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ end
data/radikocopy.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec ruby exe/radikocopy "$@"
4
+ #bundle exec ruby exe/radikocopy
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radikocopy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - src
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-21 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Radiko copy tool
56
+ email:
57
+ - src@srcw.net
58
+ executables:
59
+ - radikocopy
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - config/radikocopyrc
73
+ - exe/radikocopy
74
+ - lib/radikocopy.rb
75
+ - lib/radikocopy/version.rb
76
+ - lib/radikoimport.scpt
77
+ - radikocopy.gemspec
78
+ - radikocopy.sh
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Radiko copy tool
103
+ test_files: []