Skip to content

Commit

Permalink
Merge branch 'windows-server-2003:main' into morelang
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsFrocat authored Feb 23, 2024
2 parents aaac67e + a5e6f3a commit 7791c3e
Show file tree
Hide file tree
Showing 148 changed files with 5,998 additions and 1,738 deletions.
42 changes: 23 additions & 19 deletions decrypter/0_latest.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# 19417
s 17
c 1
# 19773
s 52
c 3
s 45
R
s 53
R
s 65
c 1
s 29
>
r -800848978
r -1473906590
s 773462082
t ej4E 0aA-_
R
e 330905968
r -1801395041
r -45203544
r 969944705
s -1266939812
s 1071587255
r 2070384319
t hwadna7 Aa0-_
s 61910453
r 1099802296
e 252625712
r -434708788
r 1320364804
s -1560567458
R
t UDjUn 0aA-_
r -1700764381
s -787267704
e -302748668
e -2100786658
s 527271687
R
R
r 859083917
r -2140614363
r -307172264
r 531841242
R
r 1430129269
s 1333417834
55 changes: 55 additions & 0 deletions decrypter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## YouTube "decrypter" file
YouTube employs some measures for anti-third-party client. Something called "signature cipher" or "n parameter" is one of them.
We can fetch stream URLs from `ytInitialPlayerResponse` in the video page or `/player` endpoint, but the URLs are unusable or rate-limited without some parameter conversion.
The conversion is done in `base.js` on the official web client, and the process seems to be always a combination of a certain simple operations.
We could download `base.js` and execute the conversion code on ThirdTube, but `base.js` is a large(1~2 MB) file and it slows down video loading,
so we make a text file(2-300 B) describing the operations in the conversion process and let the app load it.
This document describes the format of the file.

## How ThirdTube loads the file
1. embedded in romfs of the app file (updated with the ThirdTube releases)
2. local cache (updated along with 3.)
3. `decrypter/0_latest.txt` in this repository (latest)

On startup, the app loads the decrypter in the following order, and uses the last one that is succeeded to load.

## How to find conversion function in base.js

### sig
1. Search for `a=a.split("")`. It should be at the start of a function, followed by \[VAR\].\[FUNC\](a,[x]). The function is the conversion function.
2. Search for `var [VAR]=` to see the content of `FUNC`s.

### n
1. Search for `("n")`. The unique match should be followed by `&&(b=[ARR][0](b))`.
2. Go for the defintion of `[ARR]` by searching `var [ARR]` and get the conversion function name

## Format
```
# [STS]
[one or more lines for "sig" conversion]
>
[one or more lines for "n" conversion]
```
`STS` is like a version of the decrypter and seems to be the day count from unix epoch to the deployment of the decrypter.
A line for "sig"/"n" conversion is one of the following:
`s [x]` : **s**wap `a[0]` and `a[x mod a.size()]`
`e [x]` : **e**rase `a[x mod a.size()]` from `a`
`c [x]` : (**c**ut) erase the first `x` items of `a`
`r [x]` : **r**otate `a` right for `x mod a.size()` items
`R` : reverse `a`
`t [key] [charset]` : **t**ransform `a` with the following procedure:

1. Replace `A` in `charset` with `ABC...Z` (string containing all latin uppercase letters in order)
2. Replace `a` in `charset` with `abc...z` (string containing all latin lowercase letters in order)
3. Replace `0` in `charset` with `012...9` (string containing all digit letters in order)
(These three steps are done in order to be able to compress the "decrypter" file)
4. Let f(c) be the index in `charset` at which the character `c` appears
5. For $i = 0, 1, 2, ..., \mathrm{a.size()-1}$ do the following :
1. Assign `charset[(f(a[i]) - f(key[i])) mod 64]` to `a[i]` (64 is always equal to `charset.size()`)
2. Push `a[i]` to the back of `key`

Here, `a` denotes the original string of "sig"/"n" parameter and `x mod y` denotes an integer between $0$ and $y - 1$ that is congruent to $x$ mod $y$.
When the url of the streams are fetched, ThirdTube converts the `sig` parameter by executing the lines for `sig` conversion in order and `n` in the same way.
While YouTube updates the decrypter regularly (around every three days?), we can use old decrypter by requesting the stream with old `STS`.
However, they seem to invalidate decrypters older than 2-3 weeks, so we have to update the decrypter regularly.

24 changes: 24 additions & 0 deletions decrypter/archive/0/19660.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 19660
s 67
c 1
s 31
>
t split Aa0-_
e 349754986
s 1399367760
e 1563194841
r 1680918897
s -1227273718
r 945509789
s -386866156
r -2141966360
r -505298648
e 349713772
r 1006958380
e 191776033
r 1956089104
t finally Aa0-_
s -1467723118
s -703780294
s 1903244263
R
26 changes: 26 additions & 0 deletions decrypter/archive/0/19681.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 19681
R
s 54
R
c 3
s 48
>
r -2114236808
s -859914900
r -751746778
R
e 48057633
s -1388828265
t fRPX Aa0-_
r -220910187
e 749343079
s -1577246924
R
r 1582850347
r -1956832839
s 1105433053
e 1232306809
r 1984862675
e -1502358264
s 599671842
R
30 changes: 30 additions & 0 deletions decrypter/archive/0/19773.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 19773
s 52
c 3
s 45
R
s 53
R
c 1
s 29
>
r -1473906590
s 773462082
t ej4E 0aA-_
R
r 1099802296
e 252625712
r -434708788
r 1320364804
s -1560567458
R
s -787267704
e -302748668
e -2100786658
s 527271687
R
R
r 531841242
R
r 1430129269
s 1333417834
2 changes: 1 addition & 1 deletion library/FFmpeg/FFmpeg
Submodule FFmpeg updated 4588 files
Loading

0 comments on commit 7791c3e

Please sign in to comment.