rget 4.10.0 → 4.11.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
  SHA256:
3
- metadata.gz: 002a0d55ff230dabdb3c046e67cf09a56f28aae9bbbb44c3bd7de3a4490cc770
4
- data.tar.gz: 33f86195c750fb5cad0f133fe199fc8a94fe65f6a5bae2b0eb372eb7a34aed6f
3
+ metadata.gz: 399f9407dcfa7a2c99884c4c7c1cac60fabaae386622bac006896d877e2f1c71
4
+ data.tar.gz: 5ba2047c907946753452437b51ecf3a55f3e7fa97e247c6ffab04f10badda4fc
5
5
  SHA512:
6
- metadata.gz: f144e5b3623c29342f278b22de551b3e535f8ce1a699d6454116718a4653bc4425b49ce3f4e8062cc98ca08e4940e6ce77462456161a99144008e9c5a36a7972
7
- data.tar.gz: cf9a018da02a9651e554cff2237bebbe744aff02073799b10f02806fd55079e051fc123f2c79802694efc030682126b52eb2f128041d553468a8cdc6564a0e0b
6
+ metadata.gz: f0d57aff2683b09e53fbd663a11db02e862430d51ed97588c317e1432aa0b5d13625fc6747a8c83b210b1b394a726c48662af5c2b22ba24bbd08d8ddebf08487
7
+ data.tar.gz: de34fca3119bbb1a78704131e0a825fe3f2d0b77d1426dbe08bb0cf94eed751f6961b1c34e37a55f2907dfafed803877f692aeafffe780f9513b1b239270ba03
data/README.md CHANGED
@@ -8,9 +8,10 @@ Downloading newest radio programs on the web. Supported radio stations are:
8
8
  * himalaya.fm
9
9
  * Asobi Store
10
10
  * stand.fm
11
+ * YouTube (playlist only)
11
12
 
12
13
  If you want to save files as MP3, needs `ffmpeg` command.
13
- To download niconico video, also needs latest `youtube-dl` command (you can get it from `https://yt-dl.org/`), then specify niconico user ID and password to `~/.netrc` as:
14
+ To download niconico video or YouTube, also needs latest `youtube-dl` command (you can get it from `https://yt-dl.org/`), then specify user ID and password to `~/.netrc` for niconico as:
14
15
 
15
16
  ```
16
17
  machine niconico
@@ -32,6 +32,9 @@ class WebRadio
32
32
  when %r[^https://stand\.fm/channels/]
33
33
  require 'standfm'
34
34
  StandFm.new(params, options)
35
+ when %r[^https://www\.youtube\.com/playlist]
36
+ require 'youtube'
37
+ Youtube.new(params, options)
35
38
  else
36
39
  raise UnsupportError, "unsupported url: #{params['url']}"
37
40
  end
@@ -0,0 +1,40 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+
4
+ class Youtube < WebRadio
5
+ def initialize(params, options)
6
+ super
7
+ @offset = 0
8
+ end
9
+
10
+ def download
11
+ html = URI.open(@url).read
12
+ json_str = html.scan(/ytInitialData = (.*);<\/script>/).flatten.first
13
+ json = JSON.parse(json_str)
14
+ title = json["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][0]["tabRenderer"]["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"]["contents"][0]["playlistVideoListRenderer"]["contents"][0]["playlistVideoRenderer"]["title"]["runs"][0]["text"]
15
+ @cover = json["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][0]["tabRenderer"]["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"]["contents"][0]["playlistVideoListRenderer"]["contents"][0]["playlistVideoRenderer"]["thumbnail"]["thumbnails"].last["url"]
16
+ mp4_url = "https://www.youtube.com#{json["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][0]["tabRenderer"]["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"]["contents"][0]["playlistVideoListRenderer"]["contents"][0]["playlistVideoRenderer"]["navigationEndpoint"]["commandMetadata"]["webCommandMetadata"]["url"]}"
17
+ serial = title.scan(/[0-9]+/).first
18
+
19
+ mp4_file = "#{@label}##{serial}.mp4"
20
+ mp3_file = "#{@label}##{serial}.mp3"
21
+ begin
22
+ mp3nize(mp4_file, mp3_file) do
23
+ loop do
24
+ print '.'
25
+ _, err, status = Open3.capture3("youtube-dl -f mp4 -o #{mp4_file} --netrc '#{mp4_url}'")
26
+ break if status == 0
27
+ next if err =~ /403: Forbidden/
28
+ raise ForbiddenError.new("Could not access to #{mp4_url}") if err =~ /TypeError|AssertionError/
29
+ raise DownloadError.new(err)
30
+ end
31
+ end
32
+ rescue ForbiddenError
33
+ puts "#{$!.message}, try next."
34
+ @offset += 1
35
+ retry
36
+ rescue NotFoundError
37
+ raise DownloadError.new('video not found')
38
+ end
39
+ end
40
+ end
@@ -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 = "4.10.0"
7
+ spec.version = "4.11.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, onsen, niconico, himalaya, asobi store and stand.fm.}
10
+ spec.description = %q{Downloading newest radio programs on the web. Supported radio stations are hibiki, onsen, niconico, himalaya, asobi store, stand.fm and youtube playlist.}
11
11
  spec.summary = %q{Downloading newest radio programs on the web.}
12
12
  spec.homepage = "https://github.com/wasamas/rget"
13
13
  spec.license = "GPL"
data/rget.yaml CHANGED
@@ -27,3 +27,7 @@ programs:
27
27
  desc: らなちゃのひとりごと
28
28
  url: https://stand.fm/channels/5f7d9011f04555115d2170ef
29
29
  label: らなちゃのひとりごと
30
+ active:
31
+ desc: 愛美とはるかの2年A組青春アクティ部!
32
+ url: https://www.youtube.com/playlist?list=PLI5zma0g_n8_y5Xk5eFwX8osz4Q2a3cqU
33
+ 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: 4.10.0
4
+ version: 4.11.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: 2020-12-13 00:00:00.000000000 Z
11
+ date: 2021-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  description: Downloading newest radio programs on the web. Supported radio stations
154
- are hibiki, onsen, niconico, himalaya, asobi store and stand.fm.
154
+ are hibiki, onsen, niconico, himalaya, asobi store, stand.fm and youtube playlist.
155
155
  email:
156
156
  - t@tdtds.jp
157
157
  executables:
@@ -183,6 +183,7 @@ files:
183
183
  - lib/podcast.rb
184
184
  - lib/standfm.rb
185
185
  - lib/webradio.rb
186
+ - lib/youtube.rb
186
187
  - rget.gemspec
187
188
  - rget.yaml
188
189
  homepage: https://github.com/wasamas/rget