apply patch from @inedia:ahimsa.chat
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m26s

Tracking issue at https://github.com/iv-org/invidious/issues/5108
This commit is contained in:
Fijxu 2024-12-09 16:09:54 -03:00
parent ef11b83a97
commit c35adbcc0a
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 171 additions and 20 deletions

View file

@ -0,0 +1,68 @@
name: Build and Push Docker Image
# Define when this workflow will run
on:
push:
branches:
- master # Trigger on pushes to master branch
tags:
- '[0-9]+.[0-9]+.[0-9]+' # Trigger on semantic version tags
paths-ignore:
- 'Cargo.lock'
- 'LICENSE'
- 'README.md'
- 'docker-compose.yml'
workflow_dispatch: # Allow manual triggering of the workflow
# Define environment variables used throughout the workflow
env:
REGISTRY: git.nadeko.net
IMAGE_NAME: fijxu/inv_sig_helper
jobs:
build-and-push:
runs-on: runner
steps:
# Step 1: Check out the repository code
- name: Checkout code
uses: https://github.com/actions/checkout@v3
# Step 3: Set up Docker Buildx for enhanced build capabilities
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
# Step 4: Authenticate with Quay.io registry
- name: Login to Docker Container Registry
uses: https://github.com/docker/login-action@v3.1.0
with:
registry: git.nadeko.net
username: ${{ secrets.USERNAME }}
password: ${{ secrets.TOKEN }}
# Step 5: Extract metadata for Docker image tagging and labeling
- name: Extract metadata for Docker
id: meta
uses: https://github.com/docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Define tagging strategy
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
type=sha,prefix={{branch}}-
# Define labels
labels: |
quay.expires-after=12w
# Step 6: Build and push the Docker image
- name: Build and push Docker image
uses: https://github.com/docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

75
X7dZ.patch Normal file
View file

@ -0,0 +1,75 @@
diff --git a/src/player.rs b/src/player.rs
index 23333b3..a3d79af 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -18,8 +18,10 @@ pub enum FetchUpdateStatus {
CannotFetchPlayerJS,
NsigRegexCompileFailed,
PlayerAlreadyUpdated,
+ SignatureExtractionFailed,
}
+
pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStatus> {
let global_state = state.clone();
let response = match reqwest::get(TEST_YOUTUBE_VIDEO).await {
@@ -145,33 +147,39 @@ pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStat
}
// Extract signature function name
- let sig_function_name = REGEX_SIGNATURE_FUNCTION
- .captures(&player_javascript)
- .unwrap()
- .get(1)
- .unwrap()
- .as_str();
+ let sig_function_name = match REGEX_SIGNATURE_FUNCTION.captures(&player_javascript) {
+ Some(captures) => match captures.get(1) {
+ Some(m) => m.as_str(),
+ None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
+ },
+ None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
+ };
let mut sig_function_body_regex_str: String = String::new();
sig_function_body_regex_str += &sig_function_name.replace("$", "\\$");
sig_function_body_regex_str += "=function\\([a-zA-Z0-9_]+\\)\\{.+?\\}";
- let sig_function_body_regex = Regex::new(&sig_function_body_regex_str).unwrap();
+ let sig_function_body_regex = match Regex::new(&sig_function_body_regex_str) {
+ Ok(r) => r,
+ Err(_) => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
+ };
- let sig_function_body = sig_function_body_regex
- .captures(&player_javascript)
- .unwrap()
- .get(0)
- .unwrap()
- .as_str();
+ let sig_function_body = match sig_function_body_regex.captures(&player_javascript) {
+ Some(captures) => match captures.get(0) {
+ Some(m) => m.as_str(),
+ None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
+ },
+ None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
+ };
- // Get the helper object
- let helper_object_name = REGEX_HELPER_OBJ_NAME
- .captures(sig_function_body)
- .unwrap()
- .get(1)
- .unwrap()
- .as_str();
+ // Get the helper object
+ let helper_object_name = match REGEX_HELPER_OBJ_NAME.captures(sig_function_body) {
+ Some(captures) => match captures.get(1) {
+ Some(m) => m.as_str(),
+ None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
+ },
+ None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
+ };
let mut helper_object_body_regex_str = String::new();
helper_object_body_regex_str += "(var ";

View file

@ -18,8 +18,10 @@ pub enum FetchUpdateStatus {
CannotFetchPlayerJS,
NsigRegexCompileFailed,
PlayerAlreadyUpdated,
SignatureExtractionFailed,
}
pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStatus> {
let global_state = state.clone();
let response = match reqwest::get(TEST_YOUTUBE_VIDEO).await {
@ -145,33 +147,39 @@ pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStat
}
// Extract signature function name
let sig_function_name = REGEX_SIGNATURE_FUNCTION
.captures(&player_javascript)
.unwrap()
.get(1)
.unwrap()
.as_str();
let sig_function_name = match REGEX_SIGNATURE_FUNCTION.captures(&player_javascript) {
Some(captures) => match captures.get(1) {
Some(m) => m.as_str(),
None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
},
None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
};
let mut sig_function_body_regex_str: String = String::new();
sig_function_body_regex_str += &sig_function_name.replace("$", "\\$");
sig_function_body_regex_str += "=function\\([a-zA-Z0-9_]+\\)\\{.+?\\}";
let sig_function_body_regex = Regex::new(&sig_function_body_regex_str).unwrap();
let sig_function_body_regex = match Regex::new(&sig_function_body_regex_str) {
Ok(r) => r,
Err(_) => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
};
let sig_function_body = sig_function_body_regex
.captures(&player_javascript)
.unwrap()
.get(0)
.unwrap()
.as_str();
let sig_function_body = match sig_function_body_regex.captures(&player_javascript) {
Some(captures) => match captures.get(0) {
Some(m) => m.as_str(),
None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
},
None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
};
// Get the helper object
let helper_object_name = REGEX_HELPER_OBJ_NAME
.captures(sig_function_body)
.unwrap()
.get(1)
.unwrap()
.as_str();
// Get the helper object
let helper_object_name = match REGEX_HELPER_OBJ_NAME.captures(sig_function_body) {
Some(captures) => match captures.get(1) {
Some(m) => m.as_str(),
None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
},
None => return Err(FetchUpdateStatus::NsigRegexCompileFailed),
};
let mut helper_object_body_regex_str = String::new();
helper_object_body_regex_str += "(var ";