rubytube 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,152 +1,152 @@
1
- module RubyTube
2
- class StreamFormat
3
- PROGRESSIVE_VIDEO = {
4
- 5 => ["240p", "64kbps"],
5
- 6 => ["270p", "64kbps"],
6
- 13 => ["144p", nil],
7
- 17 => ["144p", "24kbps"],
8
- 18 => ["360p", "96kbps"],
9
- 22 => ["720p", "192kbps"],
10
- 34 => ["360p", "128kbps"],
11
- 35 => ["480p", "128kbps"],
12
- 36 => ["240p", nil],
13
- 37 => ["1080p", "192kbps"],
14
- 38 => ["3072p", "192kbps"],
15
- 43 => ["360p", "128kbps"],
16
- 44 => ["480p", "128kbps"],
17
- 45 => ["720p", "192kbps"],
18
- 46 => ["1080p", "192kbps"],
19
- 59 => ["480p", "128kbps"],
20
- 78 => ["480p", "128kbps"],
21
- 82 => ["360p", "128kbps"],
22
- 83 => ["480p", "128kbps"],
23
- 84 => ["720p", "192kbps"],
24
- 85 => ["1080p", "192kbps"],
25
- 91 => ["144p", "48kbps"],
26
- 92 => ["240p", "48kbps"],
27
- 93 => ["360p", "128kbps"],
28
- 94 => ["480p", "128kbps"],
29
- 95 => ["720p", "256kbps"],
30
- 96 => ["1080p", "256kbps"],
31
- 100 => ["360p", "128kbps"],
32
- 101 => ["480p", "192kbps"],
33
- 102 => ["720p", "192kbps"],
34
- 132 => ["240p", "48kbps"],
35
- 151 => ["720p", "24kbps"],
36
- 300 => ["720p", "128kbps"],
37
- 301 => ["1080p", "128kbps"],
38
- }
39
-
40
- DASH_VIDEO = {
41
- 133 => ["240p", nil],
42
- 134 => ["360p", nil],
43
- 135 => ["480p", nil],
44
- 136 => ["720p", nil],
45
- 137 => ["1080p", nil],
46
- 138 => ["2160p", nil],
47
- 160 => ["144p", nil],
48
- 167 => ["360p", nil],
49
- 168 => ["480p", nil],
50
- 169 => ["720p", nil],
51
- 170 => ["1080p", nil],
52
- 212 => ["480p", nil],
53
- 218 => ["480p", nil],
54
- 219 => ["480p", nil],
55
- 242 => ["240p", nil],
56
- 243 => ["360p", nil],
57
- 244 => ["480p", nil],
58
- 245 => ["480p", nil],
59
- 246 => ["480p", nil],
60
- 247 => ["720p", nil],
61
- 248 => ["1080p", nil],
62
- 264 => ["1440p", nil],
63
- 266 => ["2160p", nil],
64
- 271 => ["1440p", nil],
65
- 272 => ["4320p", nil],
66
- 278 => ["144p", nil],
67
- 298 => ["720p", nil],
68
- 299 => ["1080p", nil],
69
- 302 => ["720p", nil],
70
- 303 => ["1080p", nil],
71
- 308 => ["1440p", nil],
72
- 313 => ["2160p", nil],
73
- 315 => ["2160p", nil],
74
- 330 => ["144p", nil],
75
- 331 => ["240p", nil],
76
- 332 => ["360p", nil],
77
- 333 => ["480p", nil],
78
- 334 => ["720p", nil],
79
- 335 => ["1080p", nil],
80
- 336 => ["1440p", nil],
81
- 337 => ["2160p", nil],
82
- 394 => ["144p", nil],
83
- 395 => ["240p", nil],
84
- 396 => ["360p", nil],
85
- 397 => ["480p", nil],
86
- 398 => ["720p", nil],
87
- 399 => ["1080p", nil],
88
- 400 => ["1440p", nil],
89
- 401 => ["2160p", nil],
90
- 402 => ["4320p", nil],
91
- 571 => ["4320p", nil],
92
- 694 => ["144p", nil],
93
- 695 => ["240p", nil],
94
- 696 => ["360p", nil],
95
- 697 => ["480p", nil],
96
- 698 => ["720p", nil],
97
- 699 => ["1080p", nil],
98
- 700 => ["1440p", nil],
99
- 701 => ["2160p", nil],
100
- 702 => ["4320p", nil]
101
- }
102
-
103
- DASH_AUDIO = {
104
- 139 => [nil, "48kbps"],
105
- 140 => [nil, "128kbps"],
106
- 141 => [nil, "256kbps"],
107
- 171 => [nil, "128kbps"],
108
- 172 => [nil, "256kbps"],
109
- 249 => [nil, "50kbps"],
110
- 250 => [nil, "70kbps"],
111
- 251 => [nil, "160kbps"],
112
- 256 => [nil, "192kbps"],
113
- 258 => [nil, "384kbps"],
114
- 325 => [nil, nil],
115
- 328 => [nil, nil],
116
- }
117
-
118
- ITAGS = {
119
- **PROGRESSIVE_VIDEO,
120
- **DASH_VIDEO,
121
- **DASH_AUDIO
122
- }
123
-
124
- HDR = [330, 331, 332, 333, 334, 335, 336, 337]
125
- FORMAT_3D = [82, 83, 84, 85, 100, 101, 102]
126
- LIVE = [91, 92, 93, 94, 95, 96, 132, 151]
127
-
128
- attr_reader :itag, :resolution, :abr
129
-
130
- def initialize(_itag)
131
- @itag = _itag
132
-
133
- @resolution, @abr = ITAGS.fetch(itag)
134
- end
135
-
136
- def is_live?
137
- !!LIVE[itag]
138
- end
139
-
140
- def is_3d?
141
- !!FORMAT_3D[itag]
142
- end
143
-
144
- def is_hdr?
145
- !!HDR[itag]
146
- end
147
-
148
- def is_dash?
149
- !!DASH_AUDIO[itag] || !!DASH_VIDEO[itag]
150
- end
151
- end
152
- end
1
+ module RubyTube
2
+ class StreamFormat
3
+ PROGRESSIVE_VIDEO = {
4
+ 5 => ["240p", "64kbps"],
5
+ 6 => ["270p", "64kbps"],
6
+ 13 => ["144p", nil],
7
+ 17 => ["144p", "24kbps"],
8
+ 18 => ["360p", "96kbps"],
9
+ 22 => ["720p", "192kbps"],
10
+ 34 => ["360p", "128kbps"],
11
+ 35 => ["480p", "128kbps"],
12
+ 36 => ["240p", nil],
13
+ 37 => ["1080p", "192kbps"],
14
+ 38 => ["3072p", "192kbps"],
15
+ 43 => ["360p", "128kbps"],
16
+ 44 => ["480p", "128kbps"],
17
+ 45 => ["720p", "192kbps"],
18
+ 46 => ["1080p", "192kbps"],
19
+ 59 => ["480p", "128kbps"],
20
+ 78 => ["480p", "128kbps"],
21
+ 82 => ["360p", "128kbps"],
22
+ 83 => ["480p", "128kbps"],
23
+ 84 => ["720p", "192kbps"],
24
+ 85 => ["1080p", "192kbps"],
25
+ 91 => ["144p", "48kbps"],
26
+ 92 => ["240p", "48kbps"],
27
+ 93 => ["360p", "128kbps"],
28
+ 94 => ["480p", "128kbps"],
29
+ 95 => ["720p", "256kbps"],
30
+ 96 => ["1080p", "256kbps"],
31
+ 100 => ["360p", "128kbps"],
32
+ 101 => ["480p", "192kbps"],
33
+ 102 => ["720p", "192kbps"],
34
+ 132 => ["240p", "48kbps"],
35
+ 151 => ["720p", "24kbps"],
36
+ 300 => ["720p", "128kbps"],
37
+ 301 => ["1080p", "128kbps"],
38
+ }
39
+
40
+ DASH_VIDEO = {
41
+ 133 => ["240p", nil],
42
+ 134 => ["360p", nil],
43
+ 135 => ["480p", nil],
44
+ 136 => ["720p", nil],
45
+ 137 => ["1080p", nil],
46
+ 138 => ["2160p", nil],
47
+ 160 => ["144p", nil],
48
+ 167 => ["360p", nil],
49
+ 168 => ["480p", nil],
50
+ 169 => ["720p", nil],
51
+ 170 => ["1080p", nil],
52
+ 212 => ["480p", nil],
53
+ 218 => ["480p", nil],
54
+ 219 => ["480p", nil],
55
+ 242 => ["240p", nil],
56
+ 243 => ["360p", nil],
57
+ 244 => ["480p", nil],
58
+ 245 => ["480p", nil],
59
+ 246 => ["480p", nil],
60
+ 247 => ["720p", nil],
61
+ 248 => ["1080p", nil],
62
+ 264 => ["1440p", nil],
63
+ 266 => ["2160p", nil],
64
+ 271 => ["1440p", nil],
65
+ 272 => ["4320p", nil],
66
+ 278 => ["144p", nil],
67
+ 298 => ["720p", nil],
68
+ 299 => ["1080p", nil],
69
+ 302 => ["720p", nil],
70
+ 303 => ["1080p", nil],
71
+ 308 => ["1440p", nil],
72
+ 313 => ["2160p", nil],
73
+ 315 => ["2160p", nil],
74
+ 330 => ["144p", nil],
75
+ 331 => ["240p", nil],
76
+ 332 => ["360p", nil],
77
+ 333 => ["480p", nil],
78
+ 334 => ["720p", nil],
79
+ 335 => ["1080p", nil],
80
+ 336 => ["1440p", nil],
81
+ 337 => ["2160p", nil],
82
+ 394 => ["144p", nil],
83
+ 395 => ["240p", nil],
84
+ 396 => ["360p", nil],
85
+ 397 => ["480p", nil],
86
+ 398 => ["720p", nil],
87
+ 399 => ["1080p", nil],
88
+ 400 => ["1440p", nil],
89
+ 401 => ["2160p", nil],
90
+ 402 => ["4320p", nil],
91
+ 571 => ["4320p", nil],
92
+ 694 => ["144p", nil],
93
+ 695 => ["240p", nil],
94
+ 696 => ["360p", nil],
95
+ 697 => ["480p", nil],
96
+ 698 => ["720p", nil],
97
+ 699 => ["1080p", nil],
98
+ 700 => ["1440p", nil],
99
+ 701 => ["2160p", nil],
100
+ 702 => ["4320p", nil]
101
+ }
102
+
103
+ DASH_AUDIO = {
104
+ 139 => [nil, "48kbps"],
105
+ 140 => [nil, "128kbps"],
106
+ 141 => [nil, "256kbps"],
107
+ 171 => [nil, "128kbps"],
108
+ 172 => [nil, "256kbps"],
109
+ 249 => [nil, "50kbps"],
110
+ 250 => [nil, "70kbps"],
111
+ 251 => [nil, "160kbps"],
112
+ 256 => [nil, "192kbps"],
113
+ 258 => [nil, "384kbps"],
114
+ 325 => [nil, nil],
115
+ 328 => [nil, nil],
116
+ }
117
+
118
+ ITAGS = {
119
+ **PROGRESSIVE_VIDEO,
120
+ **DASH_VIDEO,
121
+ **DASH_AUDIO
122
+ }
123
+
124
+ HDR = [330, 331, 332, 333, 334, 335, 336, 337]
125
+ FORMAT_3D = [82, 83, 84, 85, 100, 101, 102]
126
+ LIVE = [91, 92, 93, 94, 95, 96, 132, 151]
127
+
128
+ attr_reader :itag, :resolution, :abr
129
+
130
+ def initialize(_itag)
131
+ @itag = _itag
132
+
133
+ @resolution, @abr = ITAGS.fetch(itag)
134
+ end
135
+
136
+ def is_live?
137
+ !!LIVE[itag]
138
+ end
139
+
140
+ def is_3d?
141
+ !!FORMAT_3D[itag]
142
+ end
143
+
144
+ def is_hdr?
145
+ !!HDR[itag]
146
+ end
147
+
148
+ def is_dash?
149
+ !!DASH_AUDIO[itag] || !!DASH_VIDEO[itag]
150
+ end
151
+ end
152
+ end
@@ -1,38 +1,36 @@
1
- module RubyTube
2
- class StreamQuery < Array
3
- attr_reader :streams
4
-
5
- def initialize(fmt_streams)
6
- super
7
- @streams = fmt_streams
8
- end
9
-
10
- def filter(file_extension: nil, only_audio: false, only_video: false, resolution: nil)
11
- filters = []
12
-
13
- filters << ->(stream) { stream.subtype == file_extension } if file_extension
14
- filters << ->(stream) { stream.is_audio? } if only_audio
15
- filters << ->(stream) { stream.is_video? } if only_video
16
- filters << ->(stream) { stream.resolution == resolution } if resolution
17
-
18
- r = streams
19
- filters.each do |f|
20
- r = r.select(&f)
21
- end
22
-
23
- r
24
- end
25
-
26
- def first
27
- streams.first
28
- end
29
-
30
- def get_by_itag(itag)
31
- streams.find { |s| s.itag == itag }
32
- end
33
-
34
- def get_by_resolution(resolution)
35
- streams.find { |s| s.resolution == resolution }
36
- end
37
- end
38
- end
1
+ module RubyTube
2
+ class StreamQuery < Array
3
+ attr_reader :streams
4
+
5
+ def initialize(fmt_streams)
6
+ super
7
+ @streams = fmt_streams
8
+ end
9
+
10
+ def filter(file_extension: nil, only_audio: false, only_video: false, resolution: nil, progressive: false, adaptive: false)
11
+ filters = []
12
+
13
+ filters << ->(stream) { stream.subtype == file_extension } if file_extension
14
+ filters << ->(stream) { stream.is_audio? } if only_audio
15
+ filters << ->(stream) { stream.is_video? } if only_video
16
+ filters << ->(stream) { stream.resolution == resolution } if resolution
17
+ filters << ->(stream) { stream.is_progressive? } if progressive
18
+ filters << ->(stream) { stream.is_adaptive? } if adaptive
19
+
20
+ r = streams
21
+ filters.each do |f|
22
+ r = r.select(&f)
23
+ end
24
+
25
+ StreamQuery.new(r)
26
+ end
27
+
28
+ def get_by_itag(itag)
29
+ streams.find { |s| s.itag == itag }
30
+ end
31
+
32
+ def get_by_resolution(resolution)
33
+ streams.find { |s| s.resolution == resolution }
34
+ end
35
+ end
36
+ end
@@ -1,24 +1,24 @@
1
- module RubyTube
2
- module Utils
3
- module_function
4
-
5
- def regex_search(pattern, string, group)
6
- match = string.match(pattern)
7
- if match
8
- return match[group]
9
- end
10
- nil
11
- end
12
-
13
- def target_directory(output_path = nil)
14
- if output_path
15
- result = File.join(Dir.pwd, output_path) unless File.absolute_path?(output_path)
16
- else
17
- result = Dir.pwd
18
- end
19
-
20
- FileUtils.mkdir_p(result) unless Dir.exist?(result)
21
- result
22
- end
23
- end
24
- end
1
+ module RubyTube
2
+ module Utils
3
+ module_function
4
+
5
+ def regex_search(pattern, string, group)
6
+ match = string.match(pattern)
7
+ if match
8
+ return match[group]
9
+ end
10
+ nil
11
+ end
12
+
13
+ def target_directory(output_path = nil)
14
+ if output_path
15
+ result = File.join(Dir.pwd, output_path) unless File.absolute_path?(output_path)
16
+ else
17
+ result = Dir.pwd
18
+ end
19
+
20
+ FileUtils.mkdir_p(result) unless Dir.exist?(result)
21
+ result
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyTube
4
- VERSION = "0.2.0"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RubyTube
4
+ VERSION = "0.3.0"
5
+ end
data/lib/rubytube.rb CHANGED
@@ -1,68 +1,68 @@
1
- # frozen_string_literal: true
2
-
3
- require 'faraday'
4
- require 'faraday/follow_redirects'
5
-
6
- require_relative 'rubytube/version'
7
-
8
- require_relative 'rubytube/cipher'
9
- require_relative 'rubytube/client'
10
- require_relative 'rubytube/extractor'
11
- require_relative 'rubytube/innertube'
12
- require_relative 'rubytube/monostate'
13
- require_relative 'rubytube/parser'
14
- require_relative 'rubytube/request'
15
- require_relative 'rubytube/stream_format'
16
- require_relative 'rubytube/stream_query'
17
- require_relative 'rubytube/stream'
18
- require_relative 'rubytube/utils'
19
-
20
- module RubyTube
21
- class Error < StandardError; end
22
- class HTMLParseError < StandardError; end
23
- class ExtractError < StandardError; end
24
- class MaxRetriesExceeded < StandardError; end
25
- class VideoUnavailable < StandardError; end
26
-
27
- class RegexMatchError < StandardError
28
- def initialize(caller, pattern)
29
- super("Regex match error in #{caller} for pattern #{pattern}")
30
- end
31
- end
32
-
33
- class MembersOnly < StandardError
34
- def initialize(video_id)
35
- super("Members only video: #{video_id}")
36
- end
37
- end
38
-
39
- class RecordingUnavailable < StandardError
40
- def initialize(video_id)
41
- super("Recording unavailable: #{video_id}")
42
- end
43
- end
44
-
45
- class VideoUnavailable < StandardError
46
- def initialize(video_id)
47
- super("Video unavailable: #{video_id}")
48
- end
49
- end
50
-
51
- class VideoPrivate < StandardError
52
- def initialize(video_id)
53
- super("Video is private: #{video_id}")
54
- end
55
- end
56
-
57
- class LiveStreamError < StandardError
58
- def initialize(video_id)
59
- super("Video is a live stream: #{video_id}")
60
- end
61
- end
62
-
63
- class << self
64
- def new(url)
65
- Client.new(url)
66
- end
67
- end
68
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday/follow_redirects'
5
+
6
+ require_relative 'rubytube/version'
7
+
8
+ require_relative 'rubytube/cipher'
9
+ require_relative 'rubytube/client'
10
+ require_relative 'rubytube/extractor'
11
+ require_relative 'rubytube/innertube'
12
+ require_relative 'rubytube/monostate'
13
+ require_relative 'rubytube/parser'
14
+ require_relative 'rubytube/request'
15
+ require_relative 'rubytube/stream_format'
16
+ require_relative 'rubytube/stream_query'
17
+ require_relative 'rubytube/stream'
18
+ require_relative 'rubytube/utils'
19
+
20
+ module RubyTube
21
+ class Error < StandardError; end
22
+ class HTMLParseError < StandardError; end
23
+ class ExtractError < StandardError; end
24
+ class MaxRetriesExceeded < StandardError; end
25
+ class VideoUnavailable < StandardError; end
26
+
27
+ class RegexMatchError < StandardError
28
+ def initialize(caller, pattern)
29
+ super("Regex match error in #{caller} for pattern #{pattern}")
30
+ end
31
+ end
32
+
33
+ class MembersOnly < StandardError
34
+ def initialize(video_id)
35
+ super("Members only video: #{video_id}")
36
+ end
37
+ end
38
+
39
+ class RecordingUnavailable < StandardError
40
+ def initialize(video_id)
41
+ super("Recording unavailable: #{video_id}")
42
+ end
43
+ end
44
+
45
+ class VideoUnavailable < StandardError
46
+ def initialize(video_id)
47
+ super("Video unavailable: #{video_id}")
48
+ end
49
+ end
50
+
51
+ class VideoPrivate < StandardError
52
+ def initialize(video_id)
53
+ super("Video is private: #{video_id}")
54
+ end
55
+ end
56
+
57
+ class LiveStreamError < StandardError
58
+ def initialize(video_id)
59
+ super("Video is a live stream: #{video_id}")
60
+ end
61
+ end
62
+
63
+ class << self
64
+ def new(url)
65
+ Client.new(url)
66
+ end
67
+ end
68
+ end
data/sig/rubytube.rbs CHANGED
@@ -1,4 +1,4 @@
1
- module RubyTube
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end
1
+ module RubyTube
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nightswinger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-25 00:00:00.000000000 Z
11
+ date: 2023-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Write a longer description or delete this line.
41
+ description:
42
42
  email:
43
43
  - stardustkids83@gmail.com
44
44
  executables: []
@@ -74,7 +74,7 @@ metadata:
74
74
  homepage_uri: https://github.com/nightswinger/rubytube
75
75
  source_code_uri: https://github.com/nightswinger/rubytube
76
76
  changelog_uri: https://github.com/nightswinger/rubytube
77
- post_install_message:
77
+ post_install_message:
78
78
  rdoc_options: []
79
79
  require_paths:
80
80
  - lib
@@ -90,7 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubygems_version: 3.4.10
93
- signing_key:
93
+ signing_key:
94
94
  specification_version: 4
95
- summary: Write a short summary, because RubyGems requires one.
95
+ summary: RubyTube is a Ruby adaptation of pytube, enabling simplified downloading
96
+ and streaming of YouTube videos in a Ruby-friendly manner.
96
97
  test_files: []