ripdiru 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ripdiru.rb +23 -24
- data/lib/ripdiru/version.rb +1 -1
- metadata +7 -9
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 41a59ce105b6d80f18daedbf8d46268b2cdf6261
|
4
|
+
data.tar.gz: 709ec447c6300970c56f76bb84edc6a9692f0a14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de54ca13ef29df076d431f71c0255ba21abadabd82150159d0a5a0a50b93cbc4079259a3a13610f37357bdd07a753d16b0e24cac51ee7422a56adfea86e8dd79
|
7
|
+
data.tar.gz: 2430770ce1b2acd5f9eb43602513d54042244f91edff2d8123650ed8cc060a202621f5543720bc3ffc57409522c0dc91e27b44325221ed47ffa7371bbd41e967
|
data/lib/ripdiru.rb
CHANGED
@@ -12,12 +12,12 @@ require 'fileutils'
|
|
12
12
|
|
13
13
|
module Ripdiru
|
14
14
|
class DownloadTask
|
15
|
-
|
15
|
+
|
16
16
|
TMPDIR = ENV['TMPDIR'] || '/tmp'
|
17
17
|
SCHEDULE_URL = "http://www2.nhk.or.jp/hensei/api/noa.cgi?c=3&wide=1&mode=json"
|
18
|
-
|
18
|
+
|
19
19
|
attr_accessor :station, :cache, :buffer, :outdir, :bitrate
|
20
|
-
|
20
|
+
|
21
21
|
def initialize(station = nil, duration = 1800, *args)
|
22
22
|
unless station
|
23
23
|
abort "Usage: ripdiru [station-id]"
|
@@ -30,7 +30,7 @@ module Ripdiru
|
|
30
30
|
@outdir = ENV['RIPDIRU_OUTDIR'] || "#{ENV['HOME']}/Music/Radiru"
|
31
31
|
@bitrate = ENV['RIPDIRU_BITRATE'] || '48k'
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def channel
|
35
35
|
case station
|
36
36
|
when "NHK1"
|
@@ -46,22 +46,21 @@ module Ripdiru
|
|
46
46
|
puts "invalid channel"
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def val(element, path)
|
51
51
|
element.get_text(path)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def parse_time(str)
|
55
55
|
DateTime.strptime("#{str}+0900", "%Y-%m-%d %H:%M:%S%Z").to_time
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def now_playing(station)
|
59
|
-
today = Date.today
|
60
59
|
now = Time.now
|
61
60
|
|
62
61
|
f = open(SCHEDULE_URL)
|
63
62
|
xml = REXML::Document.new(f)
|
64
|
-
|
63
|
+
|
65
64
|
REXML::XPath.each(xml, "//item") do |item|
|
66
65
|
if val(item, "ch") == @mms_ch && val(item, "index") == '0'
|
67
66
|
from, to = parse_time(val(item, "starttime")), parse_time(val(item, "endtime"))
|
@@ -82,20 +81,20 @@ module Ripdiru
|
|
82
81
|
def mms_url
|
83
82
|
f = open(@aspx)
|
84
83
|
doc = REXML::Document.new(f)
|
85
|
-
|
84
|
+
|
86
85
|
mms_url = REXML::XPath.first(doc, "//ENTRY/REF").attribute("HREF").to_s
|
87
86
|
mms_url.sub!("mms://", "mmsh://")
|
88
87
|
end
|
89
88
|
|
90
89
|
def run
|
91
90
|
program = now_playing(station)
|
92
|
-
|
91
|
+
|
93
92
|
duration = program.recording_duration + buffer
|
94
|
-
|
93
|
+
|
95
94
|
tempfile = "#{TMPDIR}/#{program.id}.mp3"
|
96
95
|
puts "Streaming #{program.title} ~ #{program.to.strftime("%H:%M")} (#{duration}s)"
|
97
96
|
puts "Ripping audio file to #{tempfile}"
|
98
|
-
|
97
|
+
|
99
98
|
command = %W(
|
100
99
|
ffmpeg -y -i #{mms_url} -vn
|
101
100
|
-loglevel error
|
@@ -107,23 +106,23 @@ module Ripdiru
|
|
107
106
|
-metadata year="#{program.effective_date.year}"
|
108
107
|
-acodec libmp3lame -ar 44100 -ab #{bitrate} -ac 2
|
109
108
|
-id3v2_version 3
|
110
|
-
#{
|
111
|
-
|
109
|
+
-t #{duration}
|
110
|
+
#{tempfile}
|
112
111
|
)
|
113
|
-
|
112
|
+
|
114
113
|
system command.join(" ")
|
115
|
-
|
114
|
+
|
116
115
|
FileUtils.mkpath(outdir)
|
117
116
|
File.rename tempfile, "#{outdir}/#{program.id}.mp3"
|
118
|
-
|
117
|
+
|
119
118
|
end
|
120
|
-
|
119
|
+
|
121
120
|
def abort(msg)
|
122
121
|
puts msg
|
123
122
|
exit 1
|
124
123
|
end
|
125
124
|
end
|
126
|
-
|
125
|
+
|
127
126
|
class Program
|
128
127
|
attr_accessor :id, :station, :title, :from, :to, :duration, :info
|
129
128
|
def initialize(args = {})
|
@@ -131,24 +130,24 @@ module Ripdiru
|
|
131
130
|
send "#{k}=", v
|
132
131
|
end
|
133
132
|
end
|
134
|
-
|
133
|
+
|
135
134
|
def effective_date
|
136
135
|
time = from.hour < 5 ? from - 24 * 60 * 60 : from
|
137
136
|
Date.new(time.year, time.month, time.day)
|
138
137
|
end
|
139
|
-
|
138
|
+
|
140
139
|
def recording_duration
|
141
140
|
(to - Time.now).to_i
|
142
141
|
end
|
143
142
|
end
|
144
|
-
|
143
|
+
|
145
144
|
class CacheDir
|
146
145
|
attr_accessor :dir
|
147
146
|
def initialize(dir)
|
148
147
|
@dir = dir
|
149
148
|
@paths = {}
|
150
149
|
end
|
151
|
-
|
150
|
+
|
152
151
|
def [](name)
|
153
152
|
@paths[name] ||= Pathname.new(File.join(@dir, name))
|
154
153
|
end
|
data/lib/ripdiru/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripdiru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- harupong
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Radiru*Radiru ripper
|
15
14
|
email:
|
@@ -31,26 +30,25 @@ files:
|
|
31
30
|
homepage: ''
|
32
31
|
licenses:
|
33
32
|
- MIT
|
33
|
+
metadata: {}
|
34
34
|
post_install_message:
|
35
35
|
rdoc_options: []
|
36
36
|
require_paths:
|
37
37
|
- lib
|
38
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
39
|
requirements:
|
41
|
-
- -
|
40
|
+
- - '>='
|
42
41
|
- !ruby/object:Gem::Version
|
43
42
|
version: '0'
|
44
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
44
|
requirements:
|
47
|
-
- -
|
45
|
+
- - '>='
|
48
46
|
- !ruby/object:Gem::Version
|
49
47
|
version: '0'
|
50
48
|
requirements: []
|
51
49
|
rubyforge_project:
|
52
|
-
rubygems_version: 1.
|
50
|
+
rubygems_version: 2.1.10
|
53
51
|
signing_key:
|
54
|
-
specification_version:
|
52
|
+
specification_version: 4
|
55
53
|
summary: Streams and rips NHK radio programs
|
56
54
|
test_files: []
|