Compare commits

...

7 Commits

Author SHA1 Message Date
Pablo Ferreiro 19a2066fc2 changed keyword order 2023-04-27 20:23:23 +02:00
Pablo Ferreiro e43580f3f9 RSS TextExtra and Gallery support 2023-04-27 20:22:55 +02:00
Pablo Ferreiro b5d034437f fix multiple carousel in one page 2023-04-08 12:03:33 +02:00
Pablo Ferreiro 4e191922fe accept both desktop and mobile user agents scraper 2023-04-05 17:09:22 +02:00
Pablo Ferreiro d09830cc89 bump scraper 2023-04-03 16:24:51 +02:00
Pablo Ferreiro 3556fef036 commerce fix 2023-04-03 14:37:04 +02:00
Pablo Ferreiro 7e65da7fe9 fixes to ttag 2023-04-02 20:37:36 +02:00
23 changed files with 87 additions and 68 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ use App\Helpers\Wrappers;
use App\Models\DiscoverTemplate;
class DiscoverController {
static public function get() {
public static function get() {
$api = Wrappers::api();
$data = $api->discover();
if ($data->meta->success) {
+1 -1
View File
@@ -6,7 +6,7 @@ use App\Helpers\Wrappers;
use App\Models\VideoTemplate;
class EmbedController {
static public function v2(int $id) {
public static function v2(int $id) {
$api = Wrappers::api();
$video = $api->video($id);
$video->feed();
+1 -1
View File
@@ -7,7 +7,7 @@ use App\Helpers\Wrappers;
use App\Models\FullTemplate;
class MusicController {
static public function get(string $music_id) {
public static function get(string $music_id) {
$cursor = Misc::getCursor();
$api = Wrappers::api();
+2 -2
View File
@@ -10,7 +10,7 @@ class ProxyController {
"tiktokcdn.com", "tiktokcdn-us.com", "tiktok.com"
];
static public function stream() {
public static function stream() {
self::checkUrl();
$url = $_GET['url'];
$config['user_agent'] = Misc::env("USER_AGENT", TikScraperUserAgents::DEFAULT);
@@ -18,7 +18,7 @@ class ProxyController {
$streamer->url($url);
}
static public function download() {
public static function download() {
self::checkUrl();
$method = Cookies::downloader();
$downloader = new \TikScraper\Download($method);
+2 -2
View File
@@ -8,7 +8,7 @@ use App\Helpers\UrlBuilder;
* Used to be compatible with HTML forms
*/
class RedirectController {
static public function search() {
public static function search() {
$endpoint = '/';
if (isset($_GET['type'], $_GET['term'])) {
$term = trim($_GET['term']);
@@ -49,7 +49,7 @@ class RedirectController {
header("Location: {$url}");
}
static public function download() {
public static function download() {
if (!(isset($_GET['videoId'], $_GET['authorUsername'], $_GET['playAddr']))) {
ErrorHandler::showText(400, 'Request incomplete');
return;
+3 -3
View File
@@ -7,11 +7,11 @@ use App\Helpers\Wrappers;
use App\Models\SettingsTemplate;
class SettingsController {
static public function index() {
public static function index() {
Wrappers::latte('settings', new SettingsTemplate());
}
static public function general() {
public static function general() {
if (isset($_POST['theme'])) {
$theme = $_POST['theme'];
Cookies::set('theme', $theme);
@@ -19,7 +19,7 @@ class SettingsController {
self::redirect();
}
static public function api() {
public static function api() {
// TODO, ADD COUNT
if (isset($_POST['api-test_endpoints'])) {
$test_endpoints = $_POST['api-test_endpoints'];
+2 -2
View File
@@ -9,7 +9,7 @@ use App\Models\FullTemplate;
use App\Models\RSSTemplate;
class TagController {
static public function get(string $name) {
public static function get(string $name) {
$cursor = Misc::getCursor();
$api = Wrappers::api();
$hashtag = $api->hashtag($name);
@@ -23,7 +23,7 @@ class TagController {
}
}
static public function rss(string $name) {
public static function rss(string $name) {
$api = Wrappers::api();
$hashtag = $api->hashtag($name);
$hashtag->feed();
+2 -2
View File
@@ -8,7 +8,7 @@ use App\Helpers\Wrappers;
use App\Models\RSSTemplate;
class TrendingController {
static public function get() {
public static function get() {
$api = Wrappers::api();
$cursor = Misc::getTtwid();
@@ -23,7 +23,7 @@ class TrendingController {
}
}
static public function rss() {
public static function rss() {
$api = Wrappers::api();
$trending = $api->trending();
$trending->feed();
+3 -3
View File
@@ -10,7 +10,7 @@ use App\Models\RSSTemplate;
use App\Models\VideoTemplate;
class UserController {
static public function get(string $username) {
public static function get(string $username) {
$cursor = Misc::getCursor();
$api = Wrappers::api();
$user = $api->user($username);
@@ -24,7 +24,7 @@ class UserController {
}
}
static public function video(string $username, string $video_id) {
public static function video(string $username, string $video_id) {
$api = Wrappers::api();
$video = $api->video($video_id);
$video->feed();
@@ -37,7 +37,7 @@ class UserController {
}
}
static public function rss(string $username) {
public static function rss(string $username) {
$api = Wrappers::api();
$user = $api->user($username);
$user->feed();
+1 -1
View File
@@ -2,7 +2,7 @@
namespace App\Controllers;
class VideoController {
static public function get(string $video_id) {
public static function get(string $video_id) {
UserController::video('placeholder', $video_id);
}
}
+6 -6
View File
@@ -4,14 +4,14 @@ namespace App\Helpers;
use App\Constants\Themes;
class Cookies {
static public function get(string $name, string $default_value = ''): string {
public static function get(string $name, string $default_value = ''): string {
if (isset($_COOKIE[$name]) && !empty($_COOKIE[$name])) {
return $_COOKIE[$name];
}
return $default_value;
}
static public function theme(): string {
public static function theme(): string {
$theme = self::get('theme');
$ref = new \ReflectionClass(Themes::class);
$themes = $ref->getConstants();
@@ -21,20 +21,20 @@ class Cookies {
return 'default';
}
static public function downloader(): string {
public static function downloader(): string {
$downloader = self::get('api-downloader', 'default');
return $downloader;
}
static public function exists(string $name): bool {
public static function exists(string $name): bool {
return isset($_COOKIE[$name]);
}
static public function check(string $name, string $value): bool {
public static function check(string $name, string $value): bool {
return self::exists($name) && $_COOKIE[$name] === $value;
}
static public function set(string $name, string $value) {
public static function set(string $name, string $value) {
setcookie($name, $value, time()+60*60*24*30, '/', '', isset($_SERVER['HTTPS']), true);
}
};
+2 -2
View File
@@ -5,12 +5,12 @@ use App\Models\ErrorTemplate;
use TikScraper\Models\Meta;
class ErrorHandler {
static public function showMeta(Meta $meta) {
public static function showMeta(Meta $meta) {
http_response_code($meta->http_code);
Wrappers::latte('error', new ErrorTemplate($meta->http_code, $meta->tiktok_msg, $meta->tiktok_code));
}
static public function showText(int $code, string $msg) {
public static function showText(int $code, string $msg) {
http_response_code($code);
Wrappers::latte('error', new ErrorTemplate($code, $msg));
}
+7 -6
View File
@@ -2,33 +2,34 @@
namespace App\Helpers;
class Misc {
static public function getCursor(): int {
public static function getCursor(): int {
return isset($_GET['cursor']) && is_numeric($_GET['cursor']) ? (int) $_GET['cursor'] : 0;
}
static public function getTtwid(): string {
public static function getTtwid(): string {
return isset($_GET['cursor']) ? $_GET['cursor'] : '';
}
static public function url(string $endpoint = ''): string {
public static function url(string $endpoint = ''): string {
return self::env('APP_URL', '') . $endpoint;
}
static public function env(string $key, $default_value) {
public static function env(string $key, $default_value) {
return $_ENV[$key] ?? $default_value;
}
/**
* Returns absolute path for view
*/
static public function getView(string $template): string {
public static function getView(string $template): string {
return __DIR__ . "/../../templates/views/{$template}.latte";
}
/**
* Common method for rss feeds
*/
static public function rss(string $title) {
public static function rss(string $title) {
header('Content-Type: application/rss+xml');
header('Content-Disposition: attachment; filename="' . $title . '.rss' . '"');
}
}
+6 -6
View File
@@ -2,29 +2,29 @@
namespace App\Helpers;
class UrlBuilder {
static public function stream(string $url): string {
public static function stream(string $url): string {
return Misc::url('/stream?url=' . urlencode($url));
}
static public function download(string $url, string $username, string $id, bool $watermark): string {
public static function download(string $url, string $username, string $id, bool $watermark): string {
$down_url = Misc::url('/download?url=' . urlencode($url) . '&id=' . $id . '&user=' . $username);
if ($watermark) $down_url .= '&watermark=1';
return $down_url;
}
static public function user(string $username): string {
public static function user(string $username): string {
return Misc::url('/@' . $username);
}
static public function tag(string $tag): string {
public static function tag(string $tag): string {
return Misc::url('/tag/' . $tag);
}
static public function video_internal(string $username, string $id): string {
public static function video_internal(string $username, string $id): string {
return Misc::url('/@' . $username . "/video/" . $id);
}
static public function video_external(string $username, string $id): string {
public static function video_external(string $username, string $id): string {
return "https://www.tiktok.com/@" . $username . "/video/" . $id;
}
}
+2 -2
View File
@@ -12,7 +12,7 @@ class Wrappers {
/**
* Setup of Latte template engine
*/
static public function latte(string $template, BaseTemplate $base) {
public static function latte(string $template, BaseTemplate $base) {
$latte = new \Latte\Engine;
$cache_path = Misc::env('LATTE_CACHE', __DIR__ . '/../../cache/latte');
$latte->setTempDirectory($cache_path);
@@ -131,7 +131,7 @@ class Wrappers {
/**
* Setup of TikTok Api wrapper
*/
static public function api(): \TikScraper\Api {
public static function api(): \TikScraper\Api {
$method = Misc::env('API_SIGNER', '');
$url = Misc::env('API_SIGNER_URL', '');
if (!$method) {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "pablouser1/proxitok",
"description": "An alternative frontend for TikTok",
"version": "2.4.9.0",
"version": "2.4.9.1",
"license": "AGPL-3.0-or-later",
"type": "project",
"authors": [
Generated
+7 -7
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d8e56c687ca265b350f34789ce3cf82b",
"content-hash": "790ea9098323ef66c520cfe44b92b7d3",
"packages": [
{
"name": "bramus/router",
@@ -303,16 +303,16 @@
},
{
"name": "pablouser1/tikscraper",
"version": "v2.3.6.2",
"version": "v2.3.6.4",
"source": {
"type": "git",
"url": "https://github.com/pablouser1/TikScraperPHP.git",
"reference": "10394fb5fb5213d05fe0eb29f7582423fc15d08a"
"reference": "b26764777121dbc4408f84140b802869a77b575e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/10394fb5fb5213d05fe0eb29f7582423fc15d08a",
"reference": "10394fb5fb5213d05fe0eb29f7582423fc15d08a",
"url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/b26764777121dbc4408f84140b802869a77b575e",
"reference": "b26764777121dbc4408f84140b802869a77b575e",
"shasum": ""
},
"require": {
@@ -346,9 +346,9 @@
"description": "Get data from TikTok API",
"support": {
"issues": "https://github.com/pablouser1/TikScraperPHP/issues",
"source": "https://github.com/pablouser1/TikScraperPHP/tree/v2.3.6.2"
"source": "https://github.com/pablouser1/TikScraperPHP/tree/v2.3.6.4"
},
"time": "2023-04-01T13:46:50+00:00"
"time": "2023-04-05T15:08:06+00:00"
},
{
"name": "php-webdriver/webdriver",
@@ -3,19 +3,25 @@
<source src="{url_stream($item->video->playAddr)}" type="video/mp4" />
</video>
{else}
<section class="carousel" aria-label="carousel" Tabindex="0">
<div class="slides">
{foreach $item->imagePost->images as $i => $image}
<div class="slides-item" id="image-{$i + 1}" tabindex="0">
<img src="{url_stream($image->imageURL->urlList[0])}" />
</div>
{/foreach}
</div>
<div class="carousel__nav">
{for $i = 0; $i < count($item->imagePost->images); $i++}
<a class="slider-nav" href="#image-{$i + 1}">{$i + 1}</a>
{/for}
</div>
<div class="carousel__skip-message" id="skip-link" tabindex="0"></div>
</section>
{if isset($isSimple)}
{foreach $item->imagePost->images as $i => $image}
<img src="{url_stream($image->imageURL->urlList[0])}" />
{/foreach}
{else}
<section class="carousel" aria-label="carousel" Tabindex="0">
<div class="slides">
{foreach $item->imagePost->images as $i => $image}
<div class="slides-item" id="{$item->id}-image{$i + 1}" tabindex="0">
<img src="{url_stream($image->imageURL->urlList[0])}" />
</div>
{/foreach}
</div>
<div class="carousel__nav">
{for $i = 0; $i < count($item->imagePost->images); $i++}
<a class="slider-nav" href="#{$item->id}-image{$i + 1}">{$i + 1}</a>
{/for}
</div>
<div class="carousel__skip-message" id="skip-link" tabindex="0"></div>
</section>
{/if}
{/if}
+4 -1
View File
@@ -17,15 +17,18 @@
{if !empty($item->challenges)}
<p>{include './common/tags.latte', challenges: $item->challenges}</p>
{/if}
<p n:ifcontent>{render_desc($item->desc, $item->textExtra)|noescape}</p>
<p n:ifcontent>{render_desc($item->desc, $item->textExtra ?? [])|noescape}</p>
<p>Song: {$item->music->title}</p>
<audio controls preload="none" src="{url_stream($item->music->playUrl)}"></audio>
{include './common/stats.latte', playCount: $item->stats->playCount, diggCount: $item->stats->diggCount, commentCount: $item->stats->commentCount, shareCount: $item->stats->shareCount}
<div class="has-text-centered">
{include './common/content.latte', item: $item, isAutoplay: false, isBig: false}
</div>
{if isset($item->video->playAddr) && $item->video->playAddr !== ""}
<!-- Download links, not shown if item is a gallery -->
<p class="has-text-centered"><b>Download video</b></p>
{include './common/download.latte', playAddr: $item->video->playAddr, id: $item->id, uniqueId: $item->author->uniqueId}
{/if}
<p class="has-text-centered"><b>Share link</b></p>
{include './common/share.latte', uniqueId: $item->author->uniqueId, id: $item->id}
<div class="has-text-centered">
+1 -2
View File
@@ -1,4 +1,3 @@
{contentType application/rss+xml}
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
@@ -9,7 +8,7 @@
{foreach $items as $item}
<item>
<title>{$item->desc}</title>
<description><![CDATA[<p>{$item->desc}</p><video controls="controls" preload="auto" src="{url_stream($item->video->playAddr)}"></video>]]></description>
<description><![CDATA[<p n:ifcontent>{render_desc($item->desc, $item->textExtra ?? [])|noescape}</p>{include '../components/themes/common/content.latte', item: $item, isAutoplay: false, isSimple: true}]]></description>
<link>{url_video_internal($item->author->uniqueId, $item->id)}</link>
<pubDate>{date('r', $item->createTime)}</pubDate>
<guid isPermaLink="false">{$item->id}</guid>
+6 -1
View File
@@ -14,7 +14,12 @@
{/if}
<p class="title">{$info->detail->title}</p>
<p class="subtitle">{include '../components/rss.latte'}</p>
<p>Videos: {number($info->stats->videoCount)} / Views: {number($info->stats->viewCount)}</p>
<p>Views: {number($info->stats->viewCount)}</p>
{embed '../components/details.latte', title: 'Details'}
{block content}
<p>Is commerce: {bool_to_str($info->detail->isCommerce)}</p>
{/block}
{/embed}
{/block}
{block content}
+2
View File
@@ -32,7 +32,9 @@
{embed '../components/details.latte', title: "Details"}
{block content}
<p>Region: {$info->detail->region}</p>
{if $info->detail->commerceUserInfo->commerceUser}
<p>Category: {$info->detail->commerceUserInfo->category}</p>
{/if}
{/block}
{/embed}
{/block}
+4 -1
View File
@@ -33,13 +33,16 @@
<p>{include '../components/themes/common/tags.latte', challenges: $item->challenges}</p>
{/if}
<div class="content">
<p n:ifcontent>{render_desc($item->desc, $item->textExtra)|noescape}</p>
<p n:ifcontent>{render_desc($item->desc, $item->textExtra ?? [])|noescape}</p>
<p>Song: {$item->music->title}</p>
<audio controls preload="none" src="{url_stream($item->music->playUrl)}"></audio>
{include '../components/themes/common/stats.latte', playCount: $item->stats->playCount, diggCount: $item->stats->diggCount, commentCount: $item->stats->commentCount, shareCount: $item->stats->shareCount}
<div class="has-text-centered">
{include '../components/themes/common/share.latte', uniqueId: $info->detail->uniqueId, id: $item->id}
{if isset($item->video->playAddr) && $item->video->playAddr !== ""}
<!-- Download links, not shown if item is a gallery -->
{include '../components/themes/common/download.latte', playAddr: $item->video->playAddr, id: $item->id, uniqueId: $info->detail->uniqueId}
{/if}
</div>
</div>
</div>