Skip to content

Commit

Permalink
yt-dlp options
Browse files Browse the repository at this point in the history
  • Loading branch information
rogit committed Dec 7, 2024
1 parent c729b3b commit a781dcf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ Note: Some [anti-viruses complain about this file](https://www.virustotal.com/gu
## Requirements

Modern web-browser set as default (it is not Internet Explorer).

It's more convenient to use Firefox because of YouTube's cookie issues.
29 changes: 23 additions & 6 deletions www/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const STAGE_MAIN = 'main';
const TOOL_EXE_FILENAME = 'yt-dlp_x86.exe';
const TOOL_FOLDER_SETTING_NAME = 'yt-dlp_x86_folder';
const TOOL_OPTIONS_SETTING_NAME = 'ytDlpOptions';

function ret400 (): never {
header ( "HTTP/1.1 400 Bad Request", true, 400 );
Expand Down Expand Up @@ -39,10 +40,16 @@ function startJob ( string $jobId, string $jobCmd ): bool {
return getHTTPResponseCode ( $http_response_header ) === 200;
}

function getJobCmd ( string $link, array $settings ): string {
$toolFullPath = convertToLocale ( $settings[TOOL_FOLDER_SETTING_NAME] ) . "\\" . TOOL_EXE_FILENAME;
function getBaseCmd(array $settings): string {
$toolFullPath = convertToLocale($settings[TOOL_FOLDER_SETTING_NAME]) . "\\" . TOOL_EXE_FILENAME;
$jobCmd = "$toolFullPath --encoding utf-8 --no-check-certificate --no-color";
if ( $settings['proxy'] !== '' ) $jobCmd .= ' --proxy ' . $settings['proxy'];
if ($settings['proxy'] !== '') $jobCmd .= ' --proxy ' . $settings['proxy'];
if ($settings[TOOL_OPTIONS_SETTING_NAME] !== '') $jobCmd .= ' ' . $settings[TOOL_OPTIONS_SETTING_NAME];
return $jobCmd;
}

function getJobCmd ( string $link, array $settings ): string {
$jobCmd = getBaseCmd($settings);
$jobCmd .= ' --get-title ' . $link;
return $jobCmd;
}
Expand Down Expand Up @@ -159,9 +166,7 @@ function updateTask ( $db, array $data, array $task ): void {
$stage = STAGE_MAIN;
$showTitle = 1;
$settings = getSettings ( $db );
$toolFullPath = convertToLocale ( $settings[TOOL_FOLDER_SETTING_NAME] ) . "\\" . TOOL_EXE_FILENAME;
$jobCmd = "$toolFullPath --encoding utf-8 --no-check-certificate --no-color";
if ( $settings['proxy'] !== '' ) $jobCmd .= ' --proxy ' . $settings['proxy'];
$jobCmd = getBaseCmd($settings);
$targetFolder = convertToLocale ( $settings['targetFolder'] );
$jobCmd .= ' -v --newline';
$ffmpegHome = convertToLocale ( $settings['ffmpegHome'] );
Expand Down Expand Up @@ -265,6 +270,12 @@ function getSettings ( $db ): array {
$stmt->execute();
$stmt->close ();
}
if ( !isset ( $settings[TOOL_OPTIONS_SETTING_NAME] )) {
$settings[TOOL_OPTIONS_SETTING_NAME] = '';
$stmt = $db->prepare ( "INSERT INTO settings ( name, value ) values ( '" . TOOL_OPTIONS_SETTING_NAME . "', '' )" );
$stmt->execute();
$stmt->close ();
}
if ( !isset ( $settings['locale'] )) {
$settings['locale'] = 'en-US';
$stmt = $db->prepare ( "INSERT INTO settings ( name, value ) values ( 'locale', 'en-US' )" );
Expand Down Expand Up @@ -311,6 +322,12 @@ function saveSettings ( $db, array $settings ): void {
$stmt->execute();
$stmt->close ();

$ytDlpOptions = trim ( $settings[TOOL_OPTIONS_SETTING_NAME] );
$stmt = $db->prepare ( "UPDATE settings set value = :value where name = '" . TOOL_OPTIONS_SETTING_NAME . "'" );
$stmt->bindParam ( ':value', $ytDlpOptions );
$stmt->execute();
$stmt->close ();

$locale = $settings['locale'];
$stmt = $db->prepare ( "UPDATE settings set value = :value where name = 'locale'" );
$stmt->bindParam ( ':value', $locale );
Expand Down
3 changes: 3 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<tr v-show="showSettings">
<td>{{$t('Proxy')}}</td><td><input type=text v-model="settings.proxy" size=90 placeholder="192.168.100.200:3128"></td>
</tr>
<tr v-show="showSettings">
<td>{{$t('ytDlpOptions')}}</td><td><input type=text v-model="settings.ytDlpOptions" size=90 placeholder="--cookies-from-browser firefox"></td>
</tr>
<tr>
<td>{{$t('targetFolder')}}</td><td><input type=text v-model="settings.targetFolder" size=90> <button @click="openTargetFolder" class="button_primary">{{$t('open')}}</button></td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions www/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ new Vue ({
videoResolution: -1,
ffmpegHome: '',
proxy: '',
ytDlpOptions: '',
locale: 'en-US'
}
}
Expand Down
3 changes: 3 additions & 0 deletions www/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var messages = {
Audio: "Audio",
pathToBinFolder: "Path to 'bin' folder",
Proxy: "Proxy",
ytDlpOptions: "yt-dlp options",
link: "link",
title: "title",
downloaded: "downloaded",
Expand Down Expand Up @@ -68,6 +69,7 @@ var messages = {
Audio: "Audio",
pathToBinFolder: "Pfad zum 'bin'-Ordner",
Proxy: "Stellvertreter",
ytDlpOptions: "yt-dlp Optionen",
link: "link",
title: "titel",
downloaded: "heruntergeladen",
Expand Down Expand Up @@ -117,6 +119,7 @@ var messages = {
Audio: "Аудио",
pathToBinFolder: "Путь к папке 'bin'",
Proxy: "Прокси",
ytDlpOptions: "yt-dlp опции",
link: "ссылка",
title: "название",
downloaded: "скачено",
Expand Down

0 comments on commit a781dcf

Please sign in to comment.