Fixed issue with download filename

This commit is contained in:
Pablo Ferreiro 2022-10-24 20:53:59 +02:00
parent 6fafcdcd11
commit 23583ef7ab
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
5 changed files with 12 additions and 12 deletions

View file

@ -33,8 +33,7 @@ class ProxyController {
}
static private function getFilename(string $url, string $user): string {
$id = Converter::urlToId($url);
static private function getFilename(string $id, string $user): string {
$filename = 'tiktok-video-' . $id . '-' . $user;
return $filename;
}
@ -52,12 +51,13 @@ class ProxyController {
$downloader = new \TikScraper\Download($method);
// Params
$id = $_GET['id'] ?? '';
$watermark = isset($_GET['watermark']);
$url = $_GET['url'];
$user = $_GET['user'] ?? '';
// Filename
$filename = self::getFilename($url, $user);
$filename = self::getFilename($id, $user);
// Running
$downloader->url($_GET['url'], $filename, $watermark);
$downloader->url($url, $filename, $watermark);
}
}

View file

@ -6,9 +6,9 @@ class UrlBuilder {
return Misc::url('/stream?url=' . urlencode($url));
}
static public function download(string $url, string $username, bool $watermark): string {
static public function download(string $url, string $username, string $id, bool $watermark): string {
// {path('/download?url=' . urlencode($playAddr) . '&id=' . $id . '&user=' . $uniqueId) . '&watermark=1'}
$down_url = Misc::url('/download?url=' . urlencode($url) . '&user=' . $username);
$down_url = Misc::url('/download?url=' . urlencode($url) . '&id=' . $id . '&user=' . $username);
if ($watermark) $down_url .= '&watermark=1';
return $down_url;
}

View file

@ -43,8 +43,8 @@ class Wrappers {
$latte->addFunction('url_video_external', function (string $username, string $id): string {
return UrlBuilder::video_external($username, $id);
});
$latte->addFunction('url_download', function (string $url, string $username, bool $watermark): string {
return UrlBuilder::download($url, $username, $watermark);
$latte->addFunction('url_download', function (string $url, string $username, string $id, bool $watermark): string {
return UrlBuilder::download($url, $username, $id, $watermark);
});
// https://stackoverflow.com/a/36365553
$latte->addFunction('number', function (float $x) {

View file

@ -6,8 +6,8 @@
{do $share_url = url_video_external($item->author->uniqueId, $item->id)}
<div class="column is-one-quarter clickable-img" id="{$item->id}" onclick="openVideo(this.id)"
data-video_url="{url_stream($item->video->playAddr)}"
data-video_download_watermark="{url_download($item->video->playAddr, $item->author->uniqueId, true)}"
data-video_download_nowatermark="{url_download($item->video->playAddr, $item->author->uniqueId, false)}"
data-video_download_watermark="{url_download($item->video->playAddr, $item->author->uniqueId, $item->id, true)}"
data-video_download_nowatermark="{url_download(url_video_external($item->author->uniqueId, $item->id), $item->author->uniqueId, $item->id, false)}"
data-video_share_url="{$share_url}"
data-desc="{$item->desc}"
data-createtime="{$item->createTime}"

View file

@ -6,8 +6,8 @@
</div>
<div class="dropdown-menu" role="menu">
<div class="dropdown-content">
<a target="_blank" href="{url_download($playAddr, $uniqueId, true)}" class="dropdown-item">Watermark</a>
<a target="_blank" href="{url_download(url_video_external($uniqueId, $id), $uniqueId, false)}" class="dropdown-item">No watermark</a>
<a target="_blank" href="{url_download($playAddr, $uniqueId, $id, true)}" class="dropdown-item">Watermark</a>
<a target="_blank" href="{url_download(url_video_external($uniqueId, $id), $uniqueId, $id, false)}" class="dropdown-item">No watermark</a>
</div>
</div>
</div>