Skip to content

Commit

Permalink
Moved b64encode & b64decode to a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixuge committed Jul 23, 2024
1 parent 33492fe commit 6e1da81
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/aniwave/utils/urlGrabber.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { b64encode } from "../../shared/utils/aniwave/b64encode";
import { rc4Cypher } from "../../shared/utils/aniwave/rc4";
import { b64encode } from "../../shared/utils/b64";

function serializeText(t: string) {
return "".concat(b64encode(t)).replace(/\//g, "_").replace(/\+/g, "-");
Expand Down
2 changes: 1 addition & 1 deletion src/shared/extractors/voe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { VideoExtractor } from '../../shared/models/Iextractor';
import { ISource } from '../../shared/models/types';
import { getM3u8Qualities } from '../../shared/utils/m3u8';
import { PlaylistEpisodeServerSubtitle, PlaylistEpisodeServerSubtitleFormat } from '@mochiapp/js/dist';
import { b64decode } from '../utils/b64decode';
import { b64decode } from '../utils/b64';

export class VoeE extends VideoExtractor {
protected override serverName = 'voe';
Expand Down
35 changes: 35 additions & 0 deletions src/shared/utils/aniwave/b64encode.ts → src/shared/utils/b64.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
export function b64decode(input: string): string {
const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
const base64Lookup: Record<string, number> = {};
for (let i = 0; i < base64Chars.length; i++) {
base64Lookup[base64Chars.charAt(i)] = i;
}

let output = '';
let buffer = 0;
let bufferLength = 0;

for (let i = 0; i < input.length; i++) {
const char = input.charAt(i);
if (char === '=') {
// Padding signifies end of data, break out of the loop
break;
}

const charCode = base64Lookup[char];
if (charCode === undefined) {
throw new Error('Invalid Base64 input');
}

buffer = (buffer << 6) | charCode;
bufferLength += 6;

if (bufferLength >= 8) {
bufferLength -= 8;
output += String.fromCharCode((buffer >> bufferLength) & 0xFF);
}
}

return output;
}

export function b64encode(data: string): string {
data = "".concat(data);
for (s = 0; s < data.length; s++) {
Expand Down
34 changes: 0 additions & 34 deletions src/shared/utils/b64decode.ts

This file was deleted.

0 comments on commit 6e1da81

Please sign in to comment.