rubytube 0.5.0 → 1.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 +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +91 -28
- data/lib/rubytube/channel.rb +82 -0
- data/lib/rubytube/innertube.rb +83 -105
- data/lib/rubytube/playlist.rb +111 -0
- data/lib/rubytube/stream.rb +126 -95
- data/lib/rubytube/stream_query.rb +56 -61
- data/lib/rubytube/video_item.rb +28 -0
- data/lib/rubytube/youtube.rb +95 -0
- data/lib/rubytube.rb +25 -27
- metadata +12 -58
- data/.rspec +0 -3
- data/.standard.yml +0 -3
- data/CHANGELOG.md +0 -5
- data/CODE_OF_CONDUCT.md +0 -84
- data/Gemfile +0 -12
- data/Rakefile +0 -10
- data/lib/rubytube/cipher.rb +0 -370
- data/lib/rubytube/client.rb +0 -173
- data/lib/rubytube/error.rb +0 -49
- data/lib/rubytube/extractor.rb +0 -171
- data/lib/rubytube/monostate.rb +0 -5
- data/lib/rubytube/parser.rb +0 -159
- data/lib/rubytube/request.rb +0 -73
- data/lib/rubytube/stream_format.rb +0 -152
- data/lib/rubytube/utils.rb +0 -24
- data/lib/rubytube/version.rb +0 -5
- data/sig/rubytube.rbs +0 -4
data/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
6
|
-
|
|
7
|
-
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
|
8
|
-
|
|
9
|
-
## Our Standards
|
|
10
|
-
|
|
11
|
-
Examples of behavior that contributes to a positive environment for our community include:
|
|
12
|
-
|
|
13
|
-
* Demonstrating empathy and kindness toward other people
|
|
14
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
|
15
|
-
* Giving and gracefully accepting constructive feedback
|
|
16
|
-
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
|
17
|
-
* Focusing on what is best not just for us as individuals, but for the overall community
|
|
18
|
-
|
|
19
|
-
Examples of unacceptable behavior include:
|
|
20
|
-
|
|
21
|
-
* The use of sexualized language or imagery, and sexual attention or
|
|
22
|
-
advances of any kind
|
|
23
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
24
|
-
* Public or private harassment
|
|
25
|
-
* Publishing others' private information, such as a physical or email
|
|
26
|
-
address, without their explicit permission
|
|
27
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
28
|
-
professional setting
|
|
29
|
-
|
|
30
|
-
## Enforcement Responsibilities
|
|
31
|
-
|
|
32
|
-
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
|
33
|
-
|
|
34
|
-
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
|
35
|
-
|
|
36
|
-
## Scope
|
|
37
|
-
|
|
38
|
-
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
39
|
-
|
|
40
|
-
## Enforcement
|
|
41
|
-
|
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at stardustkids83@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
|
43
|
-
|
|
44
|
-
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
|
45
|
-
|
|
46
|
-
## Enforcement Guidelines
|
|
47
|
-
|
|
48
|
-
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
|
49
|
-
|
|
50
|
-
### 1. Correction
|
|
51
|
-
|
|
52
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
|
53
|
-
|
|
54
|
-
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
|
55
|
-
|
|
56
|
-
### 2. Warning
|
|
57
|
-
|
|
58
|
-
**Community Impact**: A violation through a single incident or series of actions.
|
|
59
|
-
|
|
60
|
-
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
|
61
|
-
|
|
62
|
-
### 3. Temporary Ban
|
|
63
|
-
|
|
64
|
-
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
|
65
|
-
|
|
66
|
-
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
|
67
|
-
|
|
68
|
-
### 4. Permanent Ban
|
|
69
|
-
|
|
70
|
-
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
|
71
|
-
|
|
72
|
-
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
|
73
|
-
|
|
74
|
-
## Attribution
|
|
75
|
-
|
|
76
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
|
77
|
-
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
78
|
-
|
|
79
|
-
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
|
80
|
-
|
|
81
|
-
[homepage]: https://www.contributor-covenant.org
|
|
82
|
-
|
|
83
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
|
84
|
-
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/lib/rubytube/cipher.rb
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
module RubyTube
|
|
2
|
-
class Cipher
|
|
3
|
-
attr_accessor :transform_plan, :transform_map, :js_func_patterns, :throttling_plan, :throttling_array, :calculation_plan, :calculation_n
|
|
4
|
-
|
|
5
|
-
def initialize(js)
|
|
6
|
-
self.transform_plan = get_transform_plan(js)
|
|
7
|
-
|
|
8
|
-
var_regex = %r{^\$*\w+\W}
|
|
9
|
-
var_match = @transform_plan[0].match(var_regex)
|
|
10
|
-
|
|
11
|
-
if var_match.nil?
|
|
12
|
-
raise "RegexMatchError, caller: __init__, pattern: #{var_regex.source}"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
var = var_match[0][0..-2]
|
|
16
|
-
|
|
17
|
-
self.transform_map = get_transform_map(js, var)
|
|
18
|
-
|
|
19
|
-
self.js_func_patterns = [
|
|
20
|
-
%r{\w+\.(\w+)\(\w,(\d+)\)},
|
|
21
|
-
%r{\w+\[("\w+")\]\(\w,(\d+)\)}
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
self.throttling_array = get_throttling_function_array(js)
|
|
25
|
-
self.throttling_plan = get_throttling_plan(js)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def calculate_n(initial_n)
|
|
29
|
-
throttling_array.map! do |item|
|
|
30
|
-
(item == "b") ? initial_n : item
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
throttling_plan.each do |step|
|
|
34
|
-
curr_func = throttling_array[step[0].to_i]
|
|
35
|
-
|
|
36
|
-
unless curr_func.respond_to?(:call)
|
|
37
|
-
raise ExtractError.new("calculate_n", "curr_func")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
first_arg = throttling_array[step[1].to_i]
|
|
41
|
-
|
|
42
|
-
case step.length
|
|
43
|
-
when 2
|
|
44
|
-
curr_func.call(first_arg)
|
|
45
|
-
when 3
|
|
46
|
-
second_arg = throttling_array[step[2].to_i]
|
|
47
|
-
curr_func.call(first_arg, second_arg)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
initial_n.join
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def get_signature(ciphered_signature)
|
|
55
|
-
signature = ciphered_signature.chars
|
|
56
|
-
|
|
57
|
-
transform_plan.each do |js_func|
|
|
58
|
-
name, argument = parse_function(js_func)
|
|
59
|
-
signature = transform_map[name].call(signature, argument)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
signature.join("")
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
private
|
|
66
|
-
|
|
67
|
-
def parse_function(js_func)
|
|
68
|
-
js_func_patterns.each do |pattern|
|
|
69
|
-
regex = Regexp.new(pattern)
|
|
70
|
-
parse_match = js_func.match(regex)
|
|
71
|
-
|
|
72
|
-
if parse_match
|
|
73
|
-
fn_name = parse_match[1]
|
|
74
|
-
fn_arg = parse_match[2]
|
|
75
|
-
|
|
76
|
-
return [fn_name, fn_arg]
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
raise RegexMatchError.new("parse_function", "js_func_patterns")
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def get_initial_function_name(js)
|
|
84
|
-
function_patterns = [
|
|
85
|
-
%r{\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?<sig>[a-zA-Z0-9$]+)\(}, # noqa: E501
|
|
86
|
-
%r{\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?<sig>[a-zA-Z0-9$]+)\(}, # noqa: E501
|
|
87
|
-
%r'(?:\b|[^a-zA-Z0-9$])(?<sig>[a-zA-Z0-9$]{2})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)', # noqa: E501
|
|
88
|
-
%r'(?<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)', # noqa: E501
|
|
89
|
-
%r{(?<quote>["\'])signature\k<quote>\s*,\s*(?<sig>[a-zA-Z0-9$]+)\(},
|
|
90
|
-
%r{\.sig\|\|(?<sig>[a-zA-Z0-9$]+)\(},
|
|
91
|
-
%r{yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?\s*(?<sig>[a-zA-Z0-9$]+)\(}, # noqa: E501
|
|
92
|
-
%r{\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?<sig>[a-zA-Z0-9$]+)\(}, # noqa: E501
|
|
93
|
-
%r{\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*(?<sig>[a-zA-Z0-9$]+)\(}, # noqa: E501
|
|
94
|
-
%r{\bc\s*&&\s*a\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?<sig>[a-zA-Z0-9$]+)\(}, # noqa: E501
|
|
95
|
-
%r{\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?<sig>[a-zA-Z0-9$]+)\(}, # noqa: E501
|
|
96
|
-
%r{\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?<sig>[a-zA-Z0-9$]+)\(} # noqa: E501
|
|
97
|
-
]
|
|
98
|
-
|
|
99
|
-
function_patterns.each do |pattern|
|
|
100
|
-
regex = Regexp.new(pattern)
|
|
101
|
-
function_match = js.match(regex)
|
|
102
|
-
if function_match
|
|
103
|
-
return function_match[:sig]
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
raise RegexMatchError.new("get_initial_function_name", "multiple")
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def get_transform_plan(js)
|
|
111
|
-
name = Regexp.escape(get_initial_function_name(js))
|
|
112
|
-
pattern = "#{name}=function\\(\\w\\)\\{[a-z=\\.(\"\\)]*;(.*);(?:.+)\\}"
|
|
113
|
-
|
|
114
|
-
Utils.regex_search(pattern, js, 1).split(";")
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def get_transform_object(js, var)
|
|
118
|
-
escaped_var = Regexp.escape(var)
|
|
119
|
-
pattern = "var #{escaped_var}={(.*?)};"
|
|
120
|
-
regex = Regexp.new(pattern, Regexp::MULTILINE)
|
|
121
|
-
transform_match = regex.match(js)
|
|
122
|
-
|
|
123
|
-
if transform_match.nil?
|
|
124
|
-
raise RegexMatchError.new("get_transform_object", pattern)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
transform_match[1].tr("\n", " ").split(", ")
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def get_transform_map(js, var)
|
|
131
|
-
transform_obejct = get_transform_object(js, var)
|
|
132
|
-
mapper = {}
|
|
133
|
-
|
|
134
|
-
transform_obejct.each do |obj|
|
|
135
|
-
name, function = obj.split(":")
|
|
136
|
-
fn = map_functions(function)
|
|
137
|
-
mapper[name] = fn
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
mapper
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def reverse(arr, _ = nil)
|
|
144
|
-
# Ruby equivalent of JavaScript's Array.reverse()
|
|
145
|
-
arr.reverse!
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def splice(arr, index)
|
|
149
|
-
# Ruby equivalent of JavaScript's Array.splice(0, index)
|
|
150
|
-
arr.shift(index.to_i)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def swap(arr, index)
|
|
154
|
-
# Ruby equivalent of the JavaScript swapping function
|
|
155
|
-
temp = arr[0]
|
|
156
|
-
arr[0] = arr[index.to_i % arr.length]
|
|
157
|
-
arr[index.to_i % arr.length] = temp
|
|
158
|
-
arr
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def push(arr, val)
|
|
162
|
-
arr.push(val)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def throttling_mod_func(d, e)
|
|
166
|
-
(e % d.length + d.length) % d.length
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def throttling_unshift(d, e)
|
|
170
|
-
e = throttling_mod_func(d, e)
|
|
171
|
-
new_arr = d[-e..-1] + d[0...-e]
|
|
172
|
-
d.clear
|
|
173
|
-
new_arr.each { |el| d << el }
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def throttling_cipher_function(d, e)
|
|
177
|
-
h = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".chars
|
|
178
|
-
f = 96
|
|
179
|
-
self_arr = e.chars
|
|
180
|
-
|
|
181
|
-
copied_array = d.clone
|
|
182
|
-
|
|
183
|
-
copied_array.each_with_index do |l, m|
|
|
184
|
-
bracket_val = (h.index(l) - h.index(self_arr[m]) + m - 32 + f) % h.length
|
|
185
|
-
self_arr << h[bracket_val]
|
|
186
|
-
d[m] = h[bracket_val]
|
|
187
|
-
f -= 1
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def throttling_nested_splice(d, e)
|
|
192
|
-
e = throttling_mod_func(d, e)
|
|
193
|
-
inner_splice = js_splice(d, e, 1, d[0])
|
|
194
|
-
js_splice(d, 0, 1, inner_splice[0])
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def throttling_prepend(d, e)
|
|
198
|
-
start_len = d.length
|
|
199
|
-
|
|
200
|
-
e = throttling_mod_func(d, e)
|
|
201
|
-
|
|
202
|
-
new_arr = d[-e..-1] + d[0...-e]
|
|
203
|
-
|
|
204
|
-
d.clear.concat(new_arr)
|
|
205
|
-
|
|
206
|
-
end_len = d.length
|
|
207
|
-
raise "Length mismatch" unless start_len == end_len
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def js_splice(arr, start, delete_count = nil, *items)
|
|
211
|
-
if start.is_a? Integer
|
|
212
|
-
start = arr.length if start > arr.length
|
|
213
|
-
start += arr.length if start < 0
|
|
214
|
-
else
|
|
215
|
-
start = 0
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
delete_count = arr.length - start if delete_count.nil? || delete_count >= arr.length - start
|
|
219
|
-
deleted_elements = arr[start, delete_count]
|
|
220
|
-
|
|
221
|
-
new_arr = arr[0...start] + items + arr[(start + delete_count)..-1]
|
|
222
|
-
|
|
223
|
-
arr.clear.concat(new_arr)
|
|
224
|
-
|
|
225
|
-
deleted_elements
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
def map_functions(function)
|
|
229
|
-
mapper = [
|
|
230
|
-
# function(a){a.reverse()}
|
|
231
|
-
[%r"{\w\.reverse\(\)}", method(:reverse)],
|
|
232
|
-
# function(a,b){a.splice(0,b)}
|
|
233
|
-
[%r"{\w\.splice\(0,\w\)}", method(:splice)],
|
|
234
|
-
# function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c}
|
|
235
|
-
[%r"{var\s\w=\w\[0\];\w\[0\]=\w\[\w%\w.length\];\w\[\w\]=\w}", method(:swap)],
|
|
236
|
-
# function(a,b){var c=a[0];a[0]=a[b%a.length];a[b%a.length]=c}
|
|
237
|
-
[%r"{var\s\w=\w\[0\];\w\[0\]=\w\[\w%\w.length\];\w\[\w%\w.length\]=\w}", method(:swap)]
|
|
238
|
-
]
|
|
239
|
-
|
|
240
|
-
mapper.each do |pattern, fn|
|
|
241
|
-
return fn if Regexp.new(pattern).match?(function)
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
raise RegexMatchError.new("map_functions", "multiple")
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
def get_throttling_function_name(js)
|
|
248
|
-
function_patterns = [
|
|
249
|
-
%r{a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&.*?\|\|\s*([a-z]+)},
|
|
250
|
-
%r{\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])\([a-z]\)}
|
|
251
|
-
]
|
|
252
|
-
|
|
253
|
-
function_patterns.each do |pattern|
|
|
254
|
-
regex = Regexp.new(pattern)
|
|
255
|
-
function_match = js.match(regex)
|
|
256
|
-
next unless function_match
|
|
257
|
-
|
|
258
|
-
if function_match.captures.length == 1
|
|
259
|
-
return function_match[1]
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
idx = function_match[2]
|
|
263
|
-
if idx
|
|
264
|
-
idx = idx.tr("[]", "")
|
|
265
|
-
array_match = js.match(/var #{Regexp.escape(function_match[1])}\s*=\s*(\[.+?\])/)
|
|
266
|
-
if array_match
|
|
267
|
-
array = array_match[1].tr("[]", "").split(",")
|
|
268
|
-
array = array.map(&:strip)
|
|
269
|
-
return array[idx.to_i]
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
raise RegexMatchError.new("get_throttling_function_name", "multiple")
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
def get_throttling_function_code(js)
|
|
278
|
-
name = Regexp.escape(get_throttling_function_name(js))
|
|
279
|
-
|
|
280
|
-
pattern_start = %r{#{name}=function\(\w\)}
|
|
281
|
-
regex = Regexp.new(pattern_start)
|
|
282
|
-
match = js.match(regex)
|
|
283
|
-
|
|
284
|
-
code_lines_list = Parser.find_object_from_startpoint(js, match.end(0)).split("\n")
|
|
285
|
-
joined_lines = code_lines_list.join("")
|
|
286
|
-
|
|
287
|
-
"#{match[0]}#{joined_lines}"
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
def get_throttling_function_array(js)
|
|
291
|
-
raw_code = get_throttling_function_code(js)
|
|
292
|
-
|
|
293
|
-
array_regex = /,c=\[/
|
|
294
|
-
match = raw_code.match(array_regex)
|
|
295
|
-
array_raw = Parser.find_object_from_startpoint(raw_code, match.end(0) - 1)
|
|
296
|
-
str_array = Parser.throttling_array_split(array_raw)
|
|
297
|
-
|
|
298
|
-
converted_array = []
|
|
299
|
-
str_array.each do |el|
|
|
300
|
-
begin
|
|
301
|
-
converted_array << Integer(el)
|
|
302
|
-
next
|
|
303
|
-
rescue ArgumentError
|
|
304
|
-
# Not an integer value.
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
if el == "null"
|
|
308
|
-
converted_array << nil
|
|
309
|
-
next
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
if el.start_with?('"') && el.end_with?('"')
|
|
313
|
-
converted_array << el[1..-2]
|
|
314
|
-
next
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
if el.start_with?("function")
|
|
318
|
-
mapper = [
|
|
319
|
-
[%r"{for\(\w=\(\w%\w\.length\+\w\.length\)%\w\.length;\w--;\)\w\.unshift\(\w.pop\(\)\)}", method(:throttling_unshift)],
|
|
320
|
-
[%r"{\w\.reverse\(\)}", method(:reverse)],
|
|
321
|
-
[%r"{\w\.push\(\w\)}", method(:push)],
|
|
322
|
-
[%r";var\s\w=\w\[0\];\w\[0\]=\w\[\w\];\w\[\w\]=\w}", method(:swap)],
|
|
323
|
-
[%r{case\s\d+}, method(:throttling_cipher_function)],
|
|
324
|
-
[%r{\w\.splice\(0,1,\w\.splice\(\w,1,\w\[0\]\)\[0\]\)}, method(:throttling_nested_splice)],
|
|
325
|
-
[%r";\w\.splice\(\w,1\)}", method(:js_splice)],
|
|
326
|
-
[%r"\w\.splice\(-\w\)\.reverse\(\)\.forEach\(function\(\w\){\w\.unshift\(\w\)}\)", method(:throttling_prepend)],
|
|
327
|
-
[%r"for\(var \w=\w\.length;\w;\)\w\.push\(\w\.splice\(--\w,1\)\[0\]\)}", method(:reverse)]
|
|
328
|
-
]
|
|
329
|
-
|
|
330
|
-
found = false
|
|
331
|
-
mapper.each do |pattern, fn|
|
|
332
|
-
if el.match?(pattern)
|
|
333
|
-
converted_array << fn
|
|
334
|
-
found = true
|
|
335
|
-
end
|
|
336
|
-
end
|
|
337
|
-
next if found
|
|
338
|
-
end
|
|
339
|
-
|
|
340
|
-
converted_array << el
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
converted_array.map! { |el| el.nil? ? converted_array : el }
|
|
344
|
-
converted_array
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
def get_throttling_plan(js)
|
|
348
|
-
raw_code = get_throttling_function_code(js)
|
|
349
|
-
|
|
350
|
-
transform_start = "try{"
|
|
351
|
-
plan_regex = Regexp.new(transform_start)
|
|
352
|
-
match = raw_code.match(plan_regex)
|
|
353
|
-
|
|
354
|
-
transform_plan_raw = Parser.find_object_from_startpoint(raw_code, match.end(0) - 1)
|
|
355
|
-
step_regex = %r{c\[(\d+)\]\(c\[(\d+)\](,c(\[(\d+)\]))?\)}
|
|
356
|
-
matches = transform_plan_raw.scan(step_regex)
|
|
357
|
-
transform_steps = []
|
|
358
|
-
|
|
359
|
-
matches.each do |match|
|
|
360
|
-
if match[3]
|
|
361
|
-
transform_steps.push([match[0], match[1], match[3]])
|
|
362
|
-
else
|
|
363
|
-
transform_steps.push([match[0], match[1]])
|
|
364
|
-
end
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
transform_steps
|
|
368
|
-
end
|
|
369
|
-
end
|
|
370
|
-
end
|
data/lib/rubytube/client.rb
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
module RubyTube
|
|
2
|
-
class Client
|
|
3
|
-
attr_accessor :video_id, :watch_url, :embed_url, :stream_monostate
|
|
4
|
-
|
|
5
|
-
def initialize(url)
|
|
6
|
-
self.video_id = Extractor.video_id(url)
|
|
7
|
-
|
|
8
|
-
self.watch_url = "https://youtube.com/watch?v=#{video_id}"
|
|
9
|
-
self.embed_url = "https://www.youtube.com/embed/#{video_id}"
|
|
10
|
-
|
|
11
|
-
self.stream_monostate = Monostate.new
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def watch_html
|
|
15
|
-
return @watch_html if @watch_html
|
|
16
|
-
|
|
17
|
-
@watch_html = Request.get(watch_url)
|
|
18
|
-
@watch_html
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def js
|
|
22
|
-
return @js if @js
|
|
23
|
-
|
|
24
|
-
@js = Request.get(js_url)
|
|
25
|
-
@js
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def js_url
|
|
29
|
-
return @js_url if @js_url
|
|
30
|
-
|
|
31
|
-
@js_url = Extractor.js_url(watch_html)
|
|
32
|
-
@js_url
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def streaming_data
|
|
36
|
-
return vid_info["streamingData"] if vid_info && vid_info.key?("streamingData")
|
|
37
|
-
|
|
38
|
-
bypass_age_gate
|
|
39
|
-
vid_info["streamingData"]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def fmt_streams
|
|
43
|
-
check_availability
|
|
44
|
-
return @fmt_streams if @fmt_streams
|
|
45
|
-
|
|
46
|
-
@fmt_streams = []
|
|
47
|
-
stream_manifest = Extractor.apply_descrambler(streaming_data)
|
|
48
|
-
|
|
49
|
-
begin
|
|
50
|
-
Extractor.apply_signature(stream_manifest, vid_info, js)
|
|
51
|
-
rescue ExtractError
|
|
52
|
-
js = nil
|
|
53
|
-
js_url = nil
|
|
54
|
-
Extractor.apply_signature(stream_manifest, vid_info, js)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
for stream in stream_manifest
|
|
58
|
-
@fmt_streams << Stream.new(stream, stream_monostate)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
stream_monostate.title = title
|
|
62
|
-
stream_monostate.duration = length
|
|
63
|
-
|
|
64
|
-
@fmt_streams
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def check_availability
|
|
68
|
-
status, messages = Extractor.playability_status(watch_html)
|
|
69
|
-
|
|
70
|
-
messages.each do |reason|
|
|
71
|
-
case status
|
|
72
|
-
when "UNPLAYABLE"
|
|
73
|
-
case reason
|
|
74
|
-
when "Join this channel to get access to members-only content like this video, and other exclusive perks."
|
|
75
|
-
raise MembersOnly.new(video_id)
|
|
76
|
-
when "This live stream recording is not available."
|
|
77
|
-
raise RecordingUnavailable.new(video_id)
|
|
78
|
-
else
|
|
79
|
-
raise VideoUnavailable.new(video_id)
|
|
80
|
-
end
|
|
81
|
-
when "LOGIN_REQUIRED"
|
|
82
|
-
if reason == "This is a private video. Please sign in to verify that you may see it."
|
|
83
|
-
raise VideoPrivate.new(video_id)
|
|
84
|
-
end
|
|
85
|
-
when "ERROR"
|
|
86
|
-
if reason == "Video unavailable"
|
|
87
|
-
raise VideoUnavailable.new(video_id)
|
|
88
|
-
end
|
|
89
|
-
when "LIVE_STREAM"
|
|
90
|
-
raise LiveStreamError.new(video_id)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def streams
|
|
96
|
-
return @streams if @streams
|
|
97
|
-
|
|
98
|
-
check_availability
|
|
99
|
-
@streams = StreamQuery.new(fmt_streams)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def thumbnail_url
|
|
103
|
-
thumbs = vid_info.fetch("videoDetails", {}).fetch("thumbnail", {}).fetch("thumbnails", [])
|
|
104
|
-
|
|
105
|
-
return thumbs[-1]["url"] if thumbs.size > 0
|
|
106
|
-
|
|
107
|
-
"https://img.youtube.com/vi/#{ideo_id}/maxresdefault.jpg"
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def vid_info
|
|
111
|
-
return @vid_info if @vid_info
|
|
112
|
-
|
|
113
|
-
it = InnerTube.new
|
|
114
|
-
@vid_info = it.player(video_id)
|
|
115
|
-
|
|
116
|
-
@vid_info
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def bypass_age_gate
|
|
120
|
-
it = InnerTube.new(client: "ANDROID_EMBED")
|
|
121
|
-
resp = it.player(video_id)
|
|
122
|
-
|
|
123
|
-
status = resp["playabilityStatus"]["status"]
|
|
124
|
-
if status == "UNPLAYABLE"
|
|
125
|
-
raise VideoUnavailable.new(video_id)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
@vid_info = resp
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def title
|
|
132
|
-
return @title if @title
|
|
133
|
-
|
|
134
|
-
@title = vid_info["videoDetails"]["title"]
|
|
135
|
-
@title
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def length
|
|
139
|
-
return @length if @length
|
|
140
|
-
|
|
141
|
-
@length = vid_info["videoDetails"]["lengthSeconds"].to_i
|
|
142
|
-
@length
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def views
|
|
146
|
-
return @views if @views
|
|
147
|
-
|
|
148
|
-
@views = vid_info["videoDetails"]["viewCount"].to_i
|
|
149
|
-
@views
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def author
|
|
153
|
-
return @author if @author
|
|
154
|
-
|
|
155
|
-
@author = vid_info["videoDetails"]["author"]
|
|
156
|
-
@author
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def keywords
|
|
160
|
-
return @keywords if @keywords
|
|
161
|
-
|
|
162
|
-
@keywords = vid_info["videoDetails"]["keywords"]
|
|
163
|
-
@keywords
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def channel_id
|
|
167
|
-
return @channel_id if @channel_id
|
|
168
|
-
|
|
169
|
-
@channel_id = vid_info["videoDetails"]["channelId"]
|
|
170
|
-
@channel_id
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
data/lib/rubytube/error.rb
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
module RubyTube
|
|
2
|
-
class Error < StandardError; end
|
|
3
|
-
|
|
4
|
-
class HTMLParseError < StandardError; end
|
|
5
|
-
|
|
6
|
-
class ExtractError < StandardError; end
|
|
7
|
-
|
|
8
|
-
class MaxRetriesExceeded < StandardError; end
|
|
9
|
-
|
|
10
|
-
class VideoUnavailable < StandardError; end
|
|
11
|
-
|
|
12
|
-
class InvalidArgumentError < ArgumentError; end
|
|
13
|
-
|
|
14
|
-
class RegexMatchError < StandardError
|
|
15
|
-
def initialize(caller, pattern)
|
|
16
|
-
super("Regex match error in #{caller} for pattern #{pattern}")
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
class MembersOnly < StandardError
|
|
21
|
-
def initialize(video_id)
|
|
22
|
-
super("Members only video: #{video_id}")
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class RecordingUnavailable < StandardError
|
|
27
|
-
def initialize(video_id)
|
|
28
|
-
super("Recording unavailable: #{video_id}")
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
class VideoUnavailable < StandardError
|
|
33
|
-
def initialize(video_id)
|
|
34
|
-
super("Video unavailable: #{video_id}")
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
class VideoPrivate < StandardError
|
|
39
|
-
def initialize(video_id)
|
|
40
|
-
super("Video is private: #{video_id}")
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
class LiveStreamError < StandardError
|
|
45
|
-
def initialize(video_id)
|
|
46
|
-
super("Video is a live stream: #{video_id}")
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|