rget 3.2.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1629be674db949cb4fc135e09f2fb0333b93afd
4
- data.tar.gz: 2d31880ccb2cd7e51f54698ff352331a51907fc5
3
+ metadata.gz: 28ed24cb1351d9eb22625a2f8cfbed704895040c
4
+ data.tar.gz: 4460fcfd5d9b9dd8198b4c7203f3d637d5ed714f
5
5
  SHA512:
6
- metadata.gz: 6927b79d9651ef8d5d18f0e03bb7c15b55779bc9942172b2ea30a0aeab738d26ec9337f7c668b4e4cebb6f1275d0f97c1094262749ec2e18d93850fb78fb4230
7
- data.tar.gz: 9f10d8a3da090ece4ae60d16e85083c1c421da16c003c4373d17631e1441a8a1e02e6467f18f1e404f5ec052c18e6a05c07184b66d65cbd9759743acde70c5a1
6
+ metadata.gz: 16049b9c31ab2f9ad6131131475e5cab1a43689f757ffc5fb6c6449d5d20d1372b4fec620033813d0eb5f02b475951ba8416e07b6282b48b994a253e1decba32
7
+ data.tar.gz: 41ce5d9d60d95c31b0b49c6734a1a5a4efd96e94f6356967597a58ffd3442adfdaa9602c8e6fcd2b65c527fdaf3d4f987d96873a72cee38458d0ab8b9b6c881f
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in get-webradio2.gemspec
3
+ # Specify your gem's dependencies in rget.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -3,15 +3,18 @@
3
3
  Downloading newest radio programs on the web. Supported radio stations are:
4
4
 
5
5
  * hibiki
6
- * animate
7
6
  * onsen
8
- * seaside communications
9
7
  * niconico
10
8
  * freshlive.tv
11
9
 
12
10
  If you want to save files as MP3, needs `ffmpeg` command.
13
11
 
14
- For customize radio programs, copy `rget.yaml` to `~/.rget` or current work directory and edit it.
12
+ For customize radio programs, copy `rget.yaml` to `~/.rget` or current work directory and edit it. config file search paths are:
13
+
14
+ * RGET\_CONFIG environment variable
15
+ * ./rget.yaml
16
+ * ~/.rget
17
+ * <command path>/../rget.yaml (for gem)
15
18
 
16
19
  ## Installation
17
20
 
data/bin/add_mp3info ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'mp3info'
3
+ require 'open-uri'
4
+
5
+ mp3 = ARGV.shift
6
+ cover = ARGV.shift
7
+ m = Mp3Info.new(mp3)
8
+ m.tag.title = File.basename(mp3, '.mp3')
9
+ m.tag2.add_picture(open(cover, 'r:ASCII-8BIT').read) if cover
10
+ m.close
data/bin/rget CHANGED
@@ -13,11 +13,12 @@ class GetWebRadio < Thor
13
13
 
14
14
  config_file = nil
15
15
  [
16
+ ENV['RGET_CONFIG'],
16
17
  './rget.yaml',
17
18
  '~/.rget',
18
19
  "#{Pathname(__dir__)}/../rget.yaml",
19
20
  ].each do |file|
20
- path = Pathname(file).expand_path
21
+ path = Pathname(file).expand_path rescue next
21
22
  if path.exist?
22
23
  config_file = path.to_s
23
24
  break
@@ -32,13 +33,12 @@ class GetWebRadio < Thor
32
33
  config['programs'].each do |command, params|
33
34
  desc command, params['desc']
34
35
  define_method(command) do
35
- url = params['url']
36
36
  opts = OpenStruct.new(config['options'].merge(options))
37
37
  begin
38
38
  if params['podcast']
39
- Podcast.new(url, opts){|media|media.download(params['label'])}
39
+ Podcast.new(params, opts){|media|media.download}
40
40
  else
41
- WebRadio(url, opts){|media|media.download(params['label'])}
41
+ WebRadio(params, opts){|media|media.download}
42
42
  end
43
43
  rescue WebRadio::NotFoundError => e
44
44
  $stderr.puts e.message
data/lib/freshlive.rb CHANGED
@@ -9,12 +9,12 @@ class FreshLive < WebRadio
9
9
  @doc = Nokogiri(open(@archive).read).root
10
10
  end
11
11
 
12
- def download(name)
12
+ def download
13
13
  offset = 0
14
14
  begin
15
15
  meta = program_meta(program_id(offset))
16
16
  serial = meta['data']['title'].scan(/\d+$/).first.to_i
17
- open("#{name}##{'%02d' % serial}.ts", 'wb') do |w|
17
+ open("#{@label}##{'%02d' % serial}.ts", 'wb') do |w|
18
18
  ts_list(meta['data']['archiveStreamUrl']).each do |u|
19
19
  w.write(open(u, 'rb').read)
20
20
  end
data/lib/hibiki.rb CHANGED
@@ -12,8 +12,8 @@ class Hibiki < WebRadio
12
12
  @url = @url.sub(%r|/detail\Z|, '')
13
13
  end
14
14
 
15
- def download(name)
16
- hibiki_download(name, Pathname(@url).basename.to_s)
15
+ def download
16
+ hibiki_download(@label, Pathname(@url).basename.to_s)
17
17
  end
18
18
 
19
19
  def dump
@@ -37,13 +37,19 @@ private
37
37
 
38
38
  def hibiki_media_info(agent, program_id)
39
39
  agent.request_headers = header
40
- JSON.parse(agent.get("https://vcms-api.hibiki-radio.jp/api/v1/programs/#{program_id}").body,{:symbolize_names => true})
40
+ json = agent.get("https://vcms-api.hibiki-radio.jp/api/v1/programs/#{program_id}").body
41
+ JSON.parse(json, symbolize_names: true)
42
+ end
43
+
44
+ def find_cover(media_info)
45
+ media_info[:episode][:episode_parts].map{|s|s[:pc_image_url]}.reject(&:empty?)[0]
41
46
  end
42
47
 
43
48
  def hibiki_download(name, program_id)
44
49
  begin
45
50
  agent = Mechanize.new
46
51
  media_info = hibiki_media_info(agent, program_id)
52
+ @cover = find_cover(media_info) unless @cover
47
53
  serial = media_info[:episode][:name].scan(/([\d\.]+)/).flatten.first
48
54
  video_id = media_info[:episode][:video][:id]
49
55
 
data/lib/nicovideo.rb CHANGED
@@ -6,7 +6,7 @@ require 'open-uri'
6
6
  require 'rss'
7
7
 
8
8
  class Nicovideo < WebRadio
9
- def initialize(url, options)
9
+ def initialize(params, options)
10
10
  account = Pit::get('nicovideo', :require => {
11
11
  :id => 'your nicovideo id',
12
12
  :pass => 'your nicovideo password'
@@ -16,20 +16,21 @@ class Nicovideo < WebRadio
16
16
  super
17
17
  end
18
18
 
19
- def download(name)
19
+ def download
20
20
  begin
21
21
  player_url = get_player_url(@url)
22
22
  rescue NoMethodError
23
23
  raise DownloadError.new('video not found')
24
24
  end
25
-
26
25
  video_id = Pathname(URI(player_url).path).basename.to_s
26
+ @cover = thumbinfo(video_id, 'thumbnail_url') unless @cover
27
+
27
28
  video = @nico.video(video_id)
28
- title = video.title || alt_title(video_id)
29
+ title = video.title || thumbinfo(video_id, 'title') || video_id
29
30
  title.tr!('0-9', '0-9')
30
31
  serial = title.scan(/(?:[#第]|[  ]EP|track-)(\d+)|/).flatten.compact[0].to_i
31
32
  appendix = title =~ /おまけ|アフタートーク/ ? 'a' : ''
32
- @file = "#{name}##{'%02d' % serial}#{appendix}.#{video.type}"
33
+ @file = "#{@label}##{'%02d' % serial}#{appendix}.#{video.type}"
33
34
  @mp3_file = @file.sub(/\....$/, '.mp3')
34
35
  mp3nize(@file, @mp3_file) do
35
36
  open(@file, 'wb:ASCII-8BIT') do |o|
@@ -76,8 +77,12 @@ private
76
77
  end
77
78
  end
78
79
 
79
- def alt_title(video_id)
80
+ def thumbinfo(video_id, elem = nil)
80
81
  xml = open("http://ext.nicovideo.jp/api/getthumbinfo/#{video_id}").read
81
- xml.scan(%r|<title>(.*)</title>|m).flatten.first || video_id
82
+ if elem
83
+ return xml.scan(%r|<#{elem}>(.*)</#{elem}>|m).flatten.first
84
+ else
85
+ return xml
86
+ end
82
87
  end
83
88
  end
data/lib/onsen.rb CHANGED
@@ -4,8 +4,13 @@ require 'webradio'
4
4
  require 'nokogiri'
5
5
 
6
6
  class Onsen < WebRadio
7
- def download(name)
8
- onsen_download(name, @url.scan(%r|/([^/]*)/$|).flatten.first)
7
+ def initialize(params, options)
8
+ super
9
+ @cover = "//*[@id='newProgramWrap']//img[1]/@src" unless @cover
10
+ end
11
+
12
+ def download
13
+ onsen_download(@label, @url.scan(%r|/([^/]*)/$|).flatten.first)
9
14
  end
10
15
 
11
16
  def dump
data/lib/podcast.rb CHANGED
@@ -9,9 +9,9 @@ class Podcast
9
9
  yield self if block_given?
10
10
  end
11
11
 
12
- def download(name = nil)
12
+ def download
13
13
  rss = RSS::Parser.parse(@url)
14
- name = rss.channel.title unless name
14
+ label = @label || rss.channel.title
15
15
  episode = rss.items.first
16
16
  serial = episode.link.scan(%r|\d+[^/\.]*|).flatten.first
17
17
  if serial.to_i > 2000 # may be year
@@ -22,7 +22,7 @@ class Podcast
22
22
  return
23
23
  end
24
24
 
25
- file = "#{name}##{serial}.mp3"
25
+ file = "#{label}##{serial}.mp3"
26
26
  if File.exist? file
27
27
  puts "'#{file}' is existent. skipped."
28
28
  return
data/lib/webradio.rb CHANGED
@@ -2,39 +2,36 @@
2
2
 
3
3
  require 'open-uri'
4
4
  require 'open3'
5
+ require 'mp3info'
5
6
 
6
7
  class WebRadio
7
8
  class NotFoundError < StandardError; end
8
9
  class DownloadError < StandardError; end
9
10
 
10
- def self.instance(url, options)
11
- case url
11
+ def self.instance(params, options)
12
+ case params['url']
12
13
  when %r[^http://hibiki-radio\.jp/]
13
14
  require 'hibiki'
14
- Hibiki.new(url, options)
15
- when %r[^http://sp\.animate\.tv/]
16
- require 'animate'
17
- Animate.new(url)
15
+ Hibiki.new(params, options)
18
16
  when %r[^http://(www\.)?onsen\.ag/program/]
19
17
  require 'onsen'
20
- Onsen.new(url, options)
21
- when %r[^http://seaside-c\.jp/program/], %r[http://nakamuland\.net/]
22
- require 'seaside-c'
23
- SeasideCommnunications.new(url, options)
18
+ Onsen.new(params, options)
24
19
  when %r[nicovideo\.jp]
25
20
  require 'nicovideo'
26
- Nicovideo.new(url, options)
21
+ Nicovideo.new(params, options)
27
22
  when %r[^https://freshlive\.tv/]
28
23
  require 'freshlive'
29
- FreshLive.new(url, options)
24
+ FreshLive.new(params, options)
30
25
  else
31
- raise 'unsupported url.'
26
+ raise "unsupported url: #{params['url']}"
32
27
  end
33
28
  end
34
29
 
35
- def initialize(url, options)
30
+ def initialize(params, options)
36
31
  raise 'do not instanciate directly, use WebRadio method.' if self.class == WebRadio
37
- @url = url
32
+ @url = params['url']
33
+ @label = params['label']
34
+ @cover = params['cover']
38
35
  @options = options
39
36
  if !@options.dump && @options.path =~ %r|^dropbox://|
40
37
  require 'dropbox'
@@ -42,7 +39,7 @@ class WebRadio
42
39
  end
43
40
  end
44
41
 
45
- def download(name)
42
+ def download
46
43
  raise 'not implemented.'
47
44
  end
48
45
 
@@ -79,6 +76,7 @@ private
79
76
  end
80
77
  end
81
78
  if !@options.mp3 || src == dst
79
+ add_cover(dst)
82
80
  move(src) if @options.path
83
81
  return
84
82
  end
@@ -96,6 +94,7 @@ private
96
94
  result = Open3.capture3(ffmpeg)
97
95
  if result[2].to_i == 0
98
96
  File.delete(src) if delete_src
97
+ add_cover(dst)
99
98
  puts "done."
100
99
  else
101
100
  File.delete(dst) if File.exist?(dst)
@@ -106,6 +105,35 @@ private
106
105
  move(dst) if @options.path
107
106
  end
108
107
 
108
+ def add_cover(dst)
109
+ begin
110
+ mp3 = Mp3Info.new(dst)
111
+ mp3.tag.title = File.basename(dst, '.mp3')
112
+ mp3.tag2.add_picture(cover_image) if @cover
113
+ mp3.close
114
+ rescue
115
+ $stderr.puts "add mp3 info failed (#$!)"
116
+ end
117
+ end
118
+
119
+ def cover_image
120
+ if @cover =~ /^https?:/
121
+ cover_image_as_url()
122
+ else # XPath
123
+ cover_image_as_xpath()
124
+ end
125
+ end
126
+
127
+ def cover_image_as_url
128
+ open(@cover, 'rb', &:read)
129
+ end
130
+
131
+ def cover_image_as_xpath
132
+ html = Nokogiri(open(@url, &:read))
133
+ image_url = (URI(@url) + (html.xpath(@cover).text)).to_s
134
+ open(image_url, 'r:ASCII-8BIT', &:read)
135
+ end
136
+
109
137
  def exist?(dst)
110
138
  if @dropbox
111
139
  begin
data/rget.gemspec CHANGED
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rget"
7
- spec.version = "3.2.3"
7
+ spec.version = "4.0.0"
8
8
  spec.authors = ["TADA Tadashi"]
9
9
  spec.email = ["t@tdtds.jp"]
10
- spec.description = %q{Downloading newest radio programs on the web. Supported radio stations are hibiki, animate, onsen, seaside communications and niconico.}
10
+ spec.description = %q{Downloading newest radio programs on the web. Supported radio stations are hibiki, onsen, niconico and freshlive.}
11
11
  spec.summary = %q{Downloading newest radio programs on the web.}
12
12
  spec.homepage = "https://bitbucket.org/tdtds/rget"
13
13
  spec.license = "GPL"
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency "niconico", ">= 1.8.0"
23
23
  spec.add_runtime_dependency "pit"
24
24
  spec.add_runtime_dependency "dropbox-api", ">= 0.4.6"
25
+ spec.add_runtime_dependency "mp3info"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.3"
27
28
  spec.add_development_dependency "rake"
data/rget.yaml CHANGED
@@ -1,5 +1,5 @@
1
1
  options:
2
- mp3nize: ffmpeg -i '$1' -ab 64k '$2'
2
+ mp3nize: ffmpeg -i '$1' -vn -acodec copy '$2' || ffmpeg -i '$1' -vn -y -ab 64k '$2'
3
3
  programs:
4
4
  imas_cg:
5
5
  desc: デレラジ☆
@@ -42,12 +42,11 @@ programs:
42
42
  desc: アイドルマスターWebラジオ~バンプレストスペシャル~ラジオは……遊びでは、ないんですから
43
43
  url: http://ch.nicovideo.jp/search/%E3%82%A2%E3%82%A4%E3%83%89%E3%83%AB%E3%83%9E%E3%82%B9%E3%82%BF%E3%83%BC?channel_id=ch346&mode=s&sort=f&order=d&type=video
44
44
  label: バンプレスト
45
- amina1422:
46
- desc: 佐藤亜美菜のこの世に小文字はいりません!
47
- url: http://feeds.feedburner.com/amina1422
48
- label: よにこも
49
- podcast: true
50
45
  takamori:
51
46
  desc: 高森重戦舎 (声優バラエティ専門「声フレ」チャンネル内)
52
47
  url: https://freshlive.tv/seifre
53
48
  label: 高森重戦舎
49
+ matsui:
50
+ desc: ラジオ「松井恵理子のにじらじっ!」
51
+ url: http://www.onsen.ag/program/matsui/
52
+ label: 松井恵理子のにじらじ
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rget
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.3
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TADA Tadashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-14 00:00:00.000000000 Z
11
+ date: 2017-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.4.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: mp3info
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -123,10 +137,11 @@ dependencies:
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  description: Downloading newest radio programs on the web. Supported radio stations
126
- are hibiki, animate, onsen, seaside communications and niconico.
140
+ are hibiki, onsen, niconico and freshlive.
127
141
  email:
128
142
  - t@tdtds.jp
129
143
  executables:
144
+ - add_mp3info
130
145
  - nicodl
131
146
  - rget
132
147
  extensions: []
@@ -137,16 +152,15 @@ files:
137
152
  - LICENSE.txt
138
153
  - README.md
139
154
  - Rakefile
155
+ - bin/add_mp3info
140
156
  - bin/nicodl
141
157
  - bin/rget
142
- - lib/animate.rb
143
158
  - lib/dropbox.rb
144
159
  - lib/freshlive.rb
145
160
  - lib/hibiki.rb
146
161
  - lib/nicovideo.rb
147
162
  - lib/onsen.rb
148
163
  - lib/podcast.rb
149
- - lib/seaside-c.rb
150
164
  - lib/uliza.rb
151
165
  - lib/webradio.rb
152
166
  - rget.gemspec
@@ -171,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
185
  version: '0'
172
186
  requirements: []
173
187
  rubyforge_project:
174
- rubygems_version: 2.6.11
188
+ rubygems_version: 2.6.13
175
189
  signing_key:
176
190
  specification_version: 4
177
191
  summary: Downloading newest radio programs on the web.
data/lib/animate.rb DELETED
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'uliza'
4
-
5
- class Animate < Uliza
6
- def download(name)
7
- uliza_download(name, open(@url, 'User-Agent' => 'iPhone', &:read), /(?:活動|第)(\d+)(?:週目『|回 「)/, %r|src="(http://www2.uliza.jp/IF/iphone/iPhonePlaylist.m3u8.*?)"|)
8
- end
9
- end
10
-
data/lib/seaside-c.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'webradio'
2
-
3
- class SeasideCommnunications < WebRadio
4
- def download(name)
5
- html = open(@url, &:read)
6
- playlist_url, serial = html.scan(%r[(http:.*?\_(\d+).wax)]).flatten
7
- unless playlist_url
8
- raise WebRadio::DownloadError.new("recent radio program not found.")
9
- end
10
- serial = serial.to_i
11
-
12
- playlist = open(playlist_url, &:read)
13
- wma_url, = playlist.scan(%r[http://.*?\.wma])
14
-
15
- @wma_file = "#{name}##{serial}.wma"
16
- @mp3_file = @wma_file.sub(/\.wma$/, '.mp3')
17
- mp3nize(@wma_file, @mp3_file) do
18
- open(@wma_file, 'wb:ASCII-8BIT') do |wma|
19
- wma.write(open(wma_url, &:read))
20
- end
21
- end
22
- end
23
- end
24
-