mirror of
https://github.com/neosubhamoy/pytubepp-helper.git
synced 2026-02-04 11:22:22 +05:30
(refactor): switched to pytubepp from pytubefix to fetch video info
This commit is contained in:
@@ -55,8 +55,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "fetch-video-info",
|
"name": "fetch-video-info",
|
||||||
"cmd": "pytubefix",
|
"cmd": "pytubepp",
|
||||||
"args": [{ "validator": "\\S+"}, "--list"]
|
"args": [{ "validator": "\\S+"}, "--raw-info"]
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,41 +1,8 @@
|
|||||||
import { type ClassValue, clsx } from "clsx"
|
import { type ClassValue, clsx } from "clsx"
|
||||||
import { twMerge } from "tailwind-merge"
|
import { twMerge } from "tailwind-merge"
|
||||||
import { Command } from '@tauri-apps/api/shell';
|
import { Command } from '@tauri-apps/api/shell';
|
||||||
import { Stream } from "@/types";
|
|
||||||
import { invoke } from "@tauri-apps/api";
|
import { invoke } from "@tauri-apps/api";
|
||||||
|
|
||||||
export function extractXml(input: string): string[] {
|
|
||||||
const regex = /<Stream: [^>]+>/g;
|
|
||||||
const matches = input.match(regex);
|
|
||||||
return matches ? matches : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function parseAttributes(attributesString: string): Partial<Stream> {
|
|
||||||
const attributes: Partial<Stream> = {};
|
|
||||||
const regex = /(\w+)="([^"]*)"/g;
|
|
||||||
let match;
|
|
||||||
|
|
||||||
while ((match = regex.exec(attributesString)) !== null) {
|
|
||||||
const key = match[1];
|
|
||||||
const value = match[2];
|
|
||||||
if (['itag', 'mime_type', 'res', 'fps', 'vcodec'].includes(key)) {
|
|
||||||
attributes[key as keyof Partial<Stream>] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function convertXmlToJson(xmlStrings: string[]): Stream[] {
|
|
||||||
return xmlStrings
|
|
||||||
.map(xmlString => {
|
|
||||||
const attributesString = xmlString.replace('<Stream: ', '').replace('>', '');
|
|
||||||
return parseAttributes(attributesString);
|
|
||||||
})
|
|
||||||
.filter(stream => stream.res !== undefined) as Stream[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs))
|
||||||
}
|
}
|
||||||
@@ -116,8 +83,7 @@ export async function sendStreamInfo(url: string) {
|
|||||||
console.log(output.stdout);
|
console.log(output.stdout);
|
||||||
const sendStreamData = async () => {
|
const sendStreamData = async () => {
|
||||||
try {
|
try {
|
||||||
const streamsstr = JSON.stringify(convertXmlToJson(extractXml(output.stdout)))
|
await invoke('receive_frontend_response', { response: output.stdout });
|
||||||
await invoke('receive_frontend_response', { response: streamsstr });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "fetch-video-info",
|
"name": "fetch-video-info",
|
||||||
"cmd": "pytubefix",
|
"cmd": "pytubepp",
|
||||||
"args": [{ "validator": "\\S+"}, "--list"]
|
"args": [{ "validator": "\\S+"}, "--raw-info"]
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,41 +1,8 @@
|
|||||||
import { type ClassValue, clsx } from "clsx"
|
import { type ClassValue, clsx } from "clsx"
|
||||||
import { twMerge } from "tailwind-merge"
|
import { twMerge } from "tailwind-merge"
|
||||||
import { Command } from '@tauri-apps/api/shell';
|
import { Command } from '@tauri-apps/api/shell';
|
||||||
import { Stream } from "@/types";
|
|
||||||
import { invoke } from "@tauri-apps/api";
|
import { invoke } from "@tauri-apps/api";
|
||||||
|
|
||||||
export function extract_xml(input: string): string[] {
|
|
||||||
const regex = /<Stream: [^>]+>/g;
|
|
||||||
const matches = input.match(regex);
|
|
||||||
return matches ? matches : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function parseAttributes(attributesString: string): Partial<Stream> {
|
|
||||||
const attributes: Partial<Stream> = {};
|
|
||||||
const regex = /(\w+)="([^"]*)"/g;
|
|
||||||
let match;
|
|
||||||
|
|
||||||
while ((match = regex.exec(attributesString)) !== null) {
|
|
||||||
const key = match[1];
|
|
||||||
const value = match[2];
|
|
||||||
if (['itag', 'mime_type', 'res', 'fps', 'vcodec'].includes(key)) {
|
|
||||||
attributes[key as keyof Partial<Stream>] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function convert_xml_to_json(xmlStrings: string[]): Stream[] {
|
|
||||||
return xmlStrings
|
|
||||||
.map(xmlString => {
|
|
||||||
const attributesString = xmlString.replace('<Stream: ', '').replace('>', '');
|
|
||||||
return parseAttributes(attributesString);
|
|
||||||
})
|
|
||||||
.filter(stream => stream.res !== undefined) as Stream[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs))
|
||||||
}
|
}
|
||||||
@@ -76,13 +43,12 @@ export function extract_version(output: string): string | null {
|
|||||||
export async function sendStreamInfo(url: string) {
|
export async function sendStreamInfo(url: string) {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
const output = await new Command('fetch-video-info', [url, '--list']).execute();
|
const output = await new Command('fetch-video-info', [url, '--raw-info']).execute();
|
||||||
if (output.code === 0) {
|
if (output.code === 0) {
|
||||||
console.log(output.stdout);
|
console.log(output.stdout);
|
||||||
const sendStreamData = async () => {
|
const sendStreamData = async () => {
|
||||||
try {
|
try {
|
||||||
const streamsstr = JSON.stringify(convert_xml_to_json(extract_xml(output.stdout)))
|
await invoke('receive_frontend_response', { response: output.stdout });
|
||||||
await invoke('receive_frontend_response', { response: streamsstr });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user