Compare commits

..

11 Commits

Author SHA1 Message Date
Pablo Ferreiro c041e84967 Fixed video on Safari 2022-05-30 13:48:06 +02:00
Pablo Ferreiro 6c7c0272d4 Added support for non-ascii characters 2022-05-24 16:35:48 +02:00
Pablo Ferreiro f1728257f2 Fix optional parameters positioning and ttwid 2022-05-24 16:03:43 +02:00
Pablo Ferreiro 0c100d650b hotfix 2022-05-24 14:17:41 +02:00
Pablo Ferreiro 55e1e9057b Updated wrapper 2022-05-24 14:10:41 +02:00
Pablo Ferreiro 14a8829087 Using prebuilt image 2022-05-22 13:14:30 +02:00
Pablo Ferreiro 367fe8d9de Merge pull request #36 from aosus/master
Auto build the docker image and push it to ghcr.io
2022-05-22 12:54:43 +02:00
Pablo Ferreiro abf23450db Changed chromedriver with SignTok 2022-05-22 12:52:56 +02:00
Pablo Ferreiro 177f290e56 Avoid warning 2022-05-22 12:31:49 +02:00
Pablo Ferreiro cd524c8da8 fixed dotenv 2022-05-22 12:12:37 +02:00
FarisZR 62a6f6b9dd Create docker-publish.yml 2022-05-21 22:28:09 +03:00
23 changed files with 216 additions and 87 deletions
+93
View File
@@ -0,0 +1,93 @@
name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
branches: [ master ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ master ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v2.3.0
with:
cosign-release: 'v1.7.1'
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: cosign sign ${{ steps.meta.outputs.tags }}@${{ steps.build-and-push.outputs.digest }}
+1 -1
View File
@@ -9,7 +9,7 @@ use App\Models\FeedTemplate;
class DiscoverController {
static public function get() {
$api = Wrappers::api();
$feed = $api->getDiscover();
$feed = $api->discover();
if ($feed->meta->success) {
$latte = Wrappers::latte();
$latte->render(Misc::getView('discover'), new FeedTemplate('Discover', $feed));
+7 -5
View File
@@ -4,19 +4,21 @@ namespace App\Controllers;
use App\Helpers\ErrorHandler;
use App\Helpers\Misc;
use App\Helpers\Wrappers;
use App\Models\FeedTemplate;
use App\Models\FullTemplate;
class MusicController {
static public function get(string $music_id) {
$cursor = Misc::getCursor();
$api = Wrappers::api();
$feed = $api->getMusicFeed($music_id, $cursor);
if ($feed->meta->success) {
$music = $api->music($music_id);
$music->feed($cursor);
if ($music->ok()) {
$data = $music->getFull();
$latte = Wrappers::latte();
$latte->render(Misc::getView('music'), new FeedTemplate('Music', $feed));
$latte->render(Misc::getView('music'), new FullTemplate('Music', $data));
} else {
ErrorHandler::show($feed->meta);
ErrorHandler::show($music->error());
}
}
}
+12 -8
View File
@@ -4,28 +4,32 @@ namespace App\Controllers;
use App\Helpers\ErrorHandler;
use App\Helpers\Misc;
use App\Helpers\Wrappers;
use App\Models\FeedTemplate;
use App\Models\FullTemplate;
use App\Models\RSSTemplate;
class TagController {
static public function get(string $name) {
$cursor = Misc::getCursor();
$api = Wrappers::api();
$feed = $api->getHashtagFeed($name, $cursor);
if ($feed->meta->success) {
$hashtag = $api->hashtag($name);
$hashtag->feed($cursor);
if ($hashtag->ok()) {
$data = $hashtag->getFull();
$latte = Wrappers::latte();
$latte->render(Misc::getView('tag'), new FeedTemplate('Tag', $feed));
$latte->render(Misc::getView('tag'), new FullTemplate('Tag', $data));
} else {
ErrorHandler::show($feed->meta);
ErrorHandler::show($hashtag->error());
}
}
static public function rss(string $name) {
$api = Wrappers::api();
$feed = $api->getHashtagFeed($name);
if ($feed->meta->success) {
$hashtag = $api->hashtag($name);
$hashtag->feed();
if ($hashtag->ok()) {
$data = $hashtag->getFull();
$latte = Wrappers::latte();
$latte->render(Misc::getView('rss'), new RSSTemplate($name, $feed->info->detail->desc, "/tag/{$name}", $feed->items));
$latte->render(Misc::getView('rss'), new RSSTemplate($name, $data->info->detail->desc, "/tag/{$name}", $data->feed->items));
}
}
}
+14 -8
View File
@@ -12,24 +12,30 @@ class TrendingController {
$api = Wrappers::api();
// Ttwid if standard, cursor if legacy
if ($api::MODE === 'STANDARD') {
$cursor = Misc::getTtwid();
} else {
if ($api->isLegacy()) {
$cursor = Misc::getCursor();
} else {
$cursor = Misc::getTtwid();
}
$feed = $api->getTrending($cursor);
if ($feed->meta->success) {
$trending = $api->trending();
$trending->feed($cursor);
$feed = $trending->getFeed();
if ($feed && $feed->meta->success) {
$latte = Wrappers::latte();
$latte->render(Misc::getView('trending'), new FeedTemplate('Trending', $feed));
} else {
ErrorHandler::show($feed->meta);
ErrorHandler::show($trending->error());
}
}
static public function rss() {
$api = Wrappers::api();
$feed = $api->getTrending();
if ($feed->meta->success) {
$trending = $api->trending();
$trending->feed();
$feed = $trending->getFeed();
if ($feed && $feed->meta->success) {
$latte = Wrappers::latte();
$latte->render(Misc::getView('rss'), new RSSTemplate('Trending', 'Trending on TikTok', '/trending', $feed->items));
}
+19 -13
View File
@@ -4,7 +4,7 @@ namespace App\Controllers;
use App\Helpers\ErrorHandler;
use App\Helpers\Misc;
use App\Helpers\Wrappers;
use App\Models\FeedTemplate;
use App\Models\FullTemplate;
use App\Models\RSSTemplate;
use App\Models\VideoTemplate;
@@ -12,37 +12,43 @@ class UserController {
static public function get(string $username) {
$cursor = Misc::getCursor();
$api = Wrappers::api();
$feed = $api->getUserFeed($username, $cursor);
if ($feed->meta->success) {
if ($feed->info->detail->privateAccount) {
$user = $api->user($username);
$user->feed($cursor);
if ($user->ok()) {
$data = $user->getFull();
if ($data->info->detail->privateAccount) {
http_response_code(403);
echo 'Private account detected! Not supported';
exit;
}
$latte = Wrappers::latte();
$latte->render(Misc::getView('user'), new FeedTemplate($feed->info->detail->nickname, $feed));
$latte->render(Misc::getView('user'), new FullTemplate($data->info->detail->nickname, $data));
} else {
ErrorHandler::show($feed->meta);
ErrorHandler::show($user->error());
}
}
static public function video(string $username, string $video_id) {
$api = Wrappers::api();
$feed = $api->getVideoByID($video_id);
if ($feed->meta->success) {
$video = $api->video($video_id);
$video->feed();
if ($video->ok()) {
$data = $video->getFull();
$latte = Wrappers::latte();
$latte->render(Misc::getView('video'), new VideoTemplate($feed->items[0], $feed->info->detail));
$latte->render(Misc::getView('video'), new VideoTemplate($data->feed->items[0], $data->info->detail));
} else {
ErrorHandler::show($feed->meta);
ErrorHandler::show($video->error());
}
}
static public function rss(string $username) {
$api = Wrappers::api();
$feed = $api->getUserFeed($username);
if ($feed->meta->success) {
$user = $api->user($username);
$user->feed();
if ($user->ok()) {
$data = $user->getFull();
$latte = Wrappers::latte();
$latte->render(Misc::getView('rss'), new RSSTemplate($username, $feed->info->detail->signature, '/@' . $username, $feed->items));
$latte->render(Misc::getView('rss'), new RSSTemplate($username, $data->info->detail->signature, '/@' . $username, $data->feed->items));
}
}
}
+2 -1
View File
@@ -2,9 +2,10 @@
namespace App\Helpers;
use App\Models\ErrorTemplate;
use TikScraper\Models\Meta;
class ErrorHandler {
static public function show(object $meta) {
static public function show(Meta $meta) {
http_response_code($meta->http_code);
$latte = Wrappers::latte();
$latte->render(Misc::getView('error'), new ErrorTemplate($meta));
+1 -1
View File
@@ -7,7 +7,7 @@ class Misc {
}
static public function getTtwid(): string {
return isset($_GET['cursor']) ? $_GET['cursor'] : '';
return isset($_GET['cursor']) ? $_GET['cursor'] : '';
}
static public function url(string $endpoint = ''): string {
+3 -5
View File
@@ -42,11 +42,10 @@ class Wrappers {
return $latte;
}
/**
/**
* Setup of TikTok Api wrapper
* @return \TikScraper\Api|\TikScraper\Legacy
*/
static public function api() {
static public function api(): \TikScraper\Api {
$options = [
'use_test_endpoints' => Misc::env('API_TEST_ENDPOINTS', false),
'signer' => [
@@ -84,7 +83,6 @@ class Wrappers {
// Legacy mode
$legacy = Misc::env('API_FORCE_LEGACY', false) || isset($_COOKIE['api-legacy']) && $_COOKIE['api-legacy'] === 'on';
return $legacy === false ? new \TikScraper\Api($options, $cacheEngine) : new \TikScraper\Legacy($options, $cacheEngine);
return new \TikScraper\Api($options, $legacy, $cacheEngine);
}
}
+3 -1
View File
@@ -1,8 +1,10 @@
<?php
namespace App\Models;
use TikScraper\Models\Meta;
class ErrorTemplate extends BaseTemplate {
public object $error;
public Meta $error;
function __construct(object $error) {
parent::__construct('Error');
+4 -2
View File
@@ -5,10 +5,12 @@ namespace App\Models;
* Base for templates with a feed
*/
class FeedTemplate extends BaseTemplate {
public object $feed;
public object $data;
function __construct(string $title, object $feed) {
parent::__construct($title);
$this->feed = $feed;
$this->data = (object) [
'feed' => $feed
];
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use TikScraper\Models\Full;
/**
* Base for templates with both info and feed
*/
class FullTemplate extends BaseTemplate {
public Full $data;
function __construct(string $title, Full $data) {
parent::__construct($title);
$this->data = $data;
}
}
+2 -2
View File
@@ -2,7 +2,7 @@
<noscript>JavaScript is required for this section to work!</noscript>
<section class="section">
<div class="columns is-multiline is-vcentered">
{foreach $feed->items as $item}
{foreach $data->feed->items as $item}
{do $share_url = 'https://tiktok.com/@' . $item->author->uniqueId . '/video/' . $item->id}
<div class="column is-one-quarter clickable-img" id="{$item->id}" onclick="openVideo(this.id)"
data-video_url="{path('/stream?url=' . urlencode($item->video->playAddr))}"
@@ -16,7 +16,7 @@
<img class="hidden" loading="lazy" data-src="{path('/stream?url=' . urlencode($item->video->dynamicCover))}" />
</div>
{/foreach}
{if empty($feed->items)}
{if empty($data->feed->items)}
<p class="title">No items sent by TikTok!</p>
{/if}
</div>
+3 -3
View File
@@ -1,8 +1,8 @@
<div n:ifset="$feed->info" class="buttons">
<div n:ifset="$data->info" class="buttons">
{* is_numeric is used to avoid having a back button with ttwid cursors *}
{if isset($_GET['cursor']) && is_numeric($_GET['cursor']) && $_GET['cursor'] != 0 }
<a class="button is-danger" href="?cursor=0">First</a>
<a class="button is-danger" href="?cursor={$feed->minCursor}">Back</a>
<a class="button is-danger" href="?cursor={$data->feed->minCursor}">Back</a>
{/if}
<a n:attr="disabled => !$feed->hasMore" class="button is-success" href="?cursor={$feed->maxCursor}">Next</a>
<a n:attr="disabled => !$data->feed->hasMore" class="button is-success" href="?cursor={$data->feed->maxCursor}">Next</a>
</div>
+2 -2
View File
@@ -1,5 +1,5 @@
<div class="container">
{foreach $feed->items as $item}
{foreach $data->feed->items as $item}
<article class="media">
<figure class="media-left">
<p class="image is-64x64">
@@ -29,7 +29,7 @@
</div>
</article>
{/foreach}
{if empty($feed->items)}
{if empty($data->feed->items)}
<p class="title">No items sent by TikTok!</p>
{/if}
</div>
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "pablouser1/proxitok",
"description": "An alternative frontend for TikTok",
"version": "2.2.2.0",
"version": "2.3.0.1",
"license": "AGPL-3.0-or-later",
"type": "project",
"authors": [
@@ -24,7 +24,7 @@
"latte/latte": "^2.11",
"bramus/router": "^1.6",
"josegonzalez/dotenv": "dev-master",
"pablouser1/tikscraper": "^1.3"
"pablouser1/tikscraper": "^2.0"
},
"autoload": {
"psr-4": {
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": "f1c0945357108862633ea87a1f6bbdd8",
"content-hash": "cfe4122df9742d32e631921902c8e213",
"packages": [
{
"name": "bramus/router",
@@ -263,16 +263,16 @@
},
{
"name": "pablouser1/tikscraper",
"version": "v1.3.5.2",
"version": "v2.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/pablouser1/TikScraperPHP.git",
"reference": "cb2580e9868cd4f77f3ab93987786fbd57e4efaf"
"reference": "f0594187000ac522b320d9d612010a346b270aa9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/cb2580e9868cd4f77f3ab93987786fbd57e4efaf",
"reference": "cb2580e9868cd4f77f3ab93987786fbd57e4efaf",
"url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/f0594187000ac522b320d9d612010a346b270aa9",
"reference": "f0594187000ac522b320d9d612010a346b270aa9",
"shasum": ""
},
"require": {
@@ -298,9 +298,9 @@
"description": "Get data from TikTok API",
"support": {
"issues": "https://github.com/pablouser1/TikScraperPHP/issues",
"source": "https://github.com/pablouser1/TikScraperPHP/tree/v1.3.5.2"
"source": "https://github.com/pablouser1/TikScraperPHP/tree/v2.0.2.0"
},
"time": "2022-05-22T09:33:26+00:00"
"time": "2022-05-30T11:46:48+00:00"
},
{
"name": "php-webdriver/webdriver",
+7 -11
View File
@@ -3,7 +3,7 @@ version: '3'
services:
web:
container_name: proxitok-web
build: .
image: ghcr.io/pablouser1/proxitok:master
ports:
- 8080:80
environment:
@@ -11,23 +11,19 @@ services:
- API_CACHE=redis
- REDIS_HOST=proxitok-redis
- REDIS_PORT=6379
- API_BROWSER_URL=http://proxitok-chrome:9515
- API_SIGNER_URL=http://proxitok-signer:8080/signature
volumes:
- proxitok-cache:/cache
depends_on:
- redis
- chrome
- signer
redis:
container_name: proxitok-redis
image: redis:6-alpine
image: redis:7-alpine
command: redis-server --save 60 1 --loglevel warning
restart: unless-stopped
chrome:
container_name: proxitok-chrome
image: zenika/alpine-chrome:with-chromedriver
shm_size: 1g
ports:
- "9515:9515"
signer:
container_name: proxitok-signer
image: ghcr.io/pablouser1/signtok:master
volumes:
proxitok-cache:
+5 -2
View File
@@ -2,8 +2,11 @@
require __DIR__ . "/vendor/autoload.php";
$dotenv = new josegonzalez\Dotenv\Loader(__DIR__ . '/.env');
$dotenv->parse();
$dotenv->toEnv();
$dotenv->raiseExceptions(false);
$result = $dotenv->parse();
if ($result !== false) {
$dotenv->toEnv();
}
// ROUTER
$router = new Bramus\Router\Router();
+1 -1
View File
@@ -5,7 +5,7 @@
{/block}
{block content}
{foreach $feed->items as $type => $items}
{foreach $data->feed->items as $type => $items}
<p class="title">{$type|firstUpper}</p>
<div class="columns is-multiline is-vcentered">
{foreach $items as $item}
+3 -3
View File
@@ -1,9 +1,9 @@
{layout '../layouts/default.latte'}
{block header}
<p class="title">{$feed->info->detail->title}</p>
<p class="subtitle">{$feed->info->detail->desc}</p>
<p>Videos: {number($feed->info->stats->videoCount)}</p>
<p class="title">{$data->info->detail->title}</p>
<p class="subtitle">{$data->info->detail->desc}</p>
<p>Videos: {number($data->info->stats->videoCount)}</p>
{/block}
{block content}
+4 -4
View File
@@ -1,14 +1,14 @@
{layout '../layouts/default.latte'}
{block header}
{if $feed->info->detail->profileThumb !== ''}
{if $data->info->detail->profileThumb !== ''}
<figure class="figure is-96x96">
<img src="{path('/stream?url=' . urlencode($feed->info->detail->profileThumb))}" />
<img src="{path('/stream?url=' . urlencode($data->info->detail->profileThumb))}" />
</figure>
{/if}
<p class="title">{$feed->info->detail->title}</p>
<p class="title">{$data->info->detail->title}</p>
<p class="subtitle">{include '../components/rss.latte'}</p>
<p>Videos: {number($feed->info->stats->videoCount)} / Views: {number($feed->info->stats->viewCount)}</p>
<p>Videos: {number($data->info->stats->videoCount)} / Views: {number($data->info->stats->viewCount)}</p>
{/block}
{block content}
+5 -5
View File
@@ -2,13 +2,13 @@
{block header}
<figure class="figure is-96x96">
<img src="{path('/stream?url=' . urlencode($feed->info->detail->avatarThumb))}" />
<img src="{path('/stream?url=' . urlencode($data->info->detail->avatarThumb))}" />
</figure>
<p class="title">{$feed->info->detail->uniqueId}</p>
<p class="title">{$data->info->detail->uniqueId}</p>
<p class="subtitle">{include '../components/rss.latte'}</p>
<p>{$feed->info->detail->signature}</p>
<p>Following: {number($feed->info->stats->followingCount)} / Followers: {number($feed->info->stats->followerCount)}</p>
<p>Hearts: {number($feed->info->stats->heartCount)} / Videos: {$feed->info->stats->videoCount}</p>
<p>{$data->info->detail->signature}</p>
<p>Following: {number($data->info->stats->followingCount)} / Followers: {number($data->info->stats->followerCount)}</p>
<p>Hearts: {number($data->info->stats->heartCount)} / Videos: {$data->info->stats->videoCount}</p>
{/block}
{block content}