add cover to torrent

This commit is contained in:
xiaomlove
2022-05-03 23:58:27 +08:00
parent 71d10de4c2
commit 130051d648
9 changed files with 144 additions and 28 deletions

View File

@@ -126,8 +126,7 @@ class Test extends Command
// $r = $rep->getContinuousDays($attendance);
// $r = $rep->getContinuousPoints(11);
$today = Carbon::today();
$r = $today->endOfMonth();
$r = parse_url('https://img9.doubanio.com/view/photo/l_ratio_poster/public/p2867903173.jpg', PHP_URL_SCHEME);
dd($r);
}

View File

@@ -49,9 +49,17 @@ class TorrentResource extends JsonResource
'thanks' => ThankResource::collection($this->whenLoaded('thanks')),
'reward_logs' => RewardResource::collection($this->whenLoaded('reward_logs')),
];
$descriptionArr = format_description($this->descr);
$out['cover'] = get_image_from_description($descriptionArr, true);
if ($this->cover) {
$cover = $this->cover;
} else {
$descriptionArr = format_description($this->descr);
$cover = get_image_from_description($descriptionArr, true);
}
$out['cover'] = resize_image($cover, 100, 100);
if ($request->routeIs('torrents.show')) {
if (!isset($descriptionArr)) {
$descriptionArr = format_description($this->descr);
}
$baseInfo = [
['label' => nexus_trans('torrent.show.size'), 'value' => mksize($this->size)],
];

View File

@@ -13,7 +13,7 @@ class Torrent extends NexusModel
'category', 'source', 'medium', 'codec', 'standard', 'processing', 'team', 'audiocodec',
'size', 'added', 'type', 'numfiles', 'owner', 'nfo', 'sp_state', 'promotion_time_type',
'promotion_until', 'anonymous', 'url', 'pos_state', 'cache_stamp', 'picktype', 'picktime',
'last_reseed', 'pt_gen', 'technical_info', 'leechers', 'seeders',
'last_reseed', 'pt_gen', 'technical_info', 'leechers', 'seeders', 'cover',
];
private static $globalPromotionState;
@@ -31,7 +31,7 @@ class Torrent extends NexusModel
public static $commentFields = [
'id', 'name', 'added', 'visible', 'banned', 'owner', 'sp_state', 'pos_state', 'hr', 'picktype', 'picktime',
'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size'
'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size', 'cover'
];
public static $basicRelations = [

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('torrents', function (Blueprint $table) {
$table->string('cover')->default('')->after('save_as');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('torrents', function (Blueprint $table) {
$table->dropColumn('cover');
});
}
};

View File

@@ -1195,7 +1195,7 @@ function parse_imdb_id($url)
if ($url != "" && preg_match("/[0-9]+/i", $url, $matches)) {
return $matches[0];
}
return false;
return '';
}
function build_imdb_url($imdb_id)
@@ -5046,7 +5046,7 @@ function displayHotAndClassic()
{
global $showextinfo, $showmovies, $Cache, $lang_functions;
if (($showextinfo['imdb'] == 'yes' || get_setting('main.enable_pt_gen_system')) && ($showmovies['hot'] == "yes" || $showmovies['classic'] == "yes"))
if ($showmovies['hot'] == "yes" || $showmovies['classic'] == "yes")
{
$imdb = new \Nexus\Imdb\Imdb();
$type = array('hot', 'classic');
@@ -5059,17 +5059,20 @@ function displayHotAndClassic()
{
$Cache->add_whole_row();
$res = sql_query("SELECT sp_state, url, id, name, small_descr FROM torrents WHERE picktype = " . sqlesc($type_each) . " AND seeders > 0 AND url != '' ORDER BY id DESC LIMIT 30") or sqlerr(__FILE__, __LINE__);
$res = sql_query("SELECT sp_state, url, id, name, small_descr, cover FROM torrents WHERE picktype = " . sqlesc($type_each) . " AND seeders > 0 AND (url != '' OR cover != '') ORDER BY id DESC LIMIT 30") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0)
{
$movies_list = "";
$count = 0;
$allImdb = array();
$width = 101;
$height = 140;
while($array = mysql_fetch_array($res))
{
$pro_torrent = get_torrent_promotion_append($array['sp_state'],'word');
if ($imdb_id = parse_imdb_id($array["url"]))
{
if (!empty($array['cover'])) {
$thumbnail = "<img width=\"{$width}\" height=\"{$height}\" src=\"".resize_image($array['cover'], $width, $height)."\" border=\"0\" alt=\"poster\" />";
} elseif ($imdb_id = parse_imdb_id($array["url"])) {
if (array_search($imdb_id, $allImdb) !== false) { //a torrent with the same IMDb url already exists
continue;
}
@@ -5079,13 +5082,14 @@ function displayHotAndClassic()
if (empty($photo_url)) {
do_log("torrent: {$array['id']}, url: {$array['url']}, imdb_id: $imdb_id can not get photo", 'error');
}
$thumbnail = "<img width=\"101\" height=\"140\" src=\"".$photo_url."\" border=\"0\" alt=\"poster\" />";
$thumbnail = "<img width=\"{$width}\" height=\"{$height}\" src=\"".resize_image($photo_url, $width, $height)."\" border=\"0\" alt=\"poster\" />";
} catch (\Exception $exception) {
do_log($exception->getMessage() . "\n[stacktrace]\n" . $exception->getTraceAsString(), 'error');
continue;
}
} else {
continue;
}
else continue;
$thumbnail = "<a style=\"margin-right: 2px\" href=\"details.php?id=" . $array['id'] . "&amp;hit=1\" onmouseover=\"domTT_activate(this, event, 'content', '" . htmlspecialchars("<font class=\'big\'><b>" . (addslashes($array['name'] . $pro_torrent)) . "</b></font><br /><font class=\'medium\'>".(addslashes($array['small_descr'])) ."</font>"). "', 'trail', true, 'delay', 0,'lifetime',5000,'styleClass','niceTitle','maxWidth', 600);\">" . $thumbnail . "</a>";
$movies_list .= $thumbnail;
$count++;
@@ -5189,7 +5193,7 @@ function strip_all_tags($text)
//去掉表情
static $emoji = null;
if (is_null($emoji)) {
$emoji = config('emoji');
$emoji = nexus_config('emoji');
}
// $text = preg_replace("/\[em([1-9][0-9]*)\]/isU", "", $text);
$text = preg_replace_callback("/\[em([1-9][0-9]*)\]/isU", function ($matches) use ($emoji) {
@@ -5306,7 +5310,7 @@ function format_description(string $description)
return $results;
}
function get_image_from_description(array $descriptionArr, $first = false)
function get_image_from_description(array $descriptionArr, $first = false, $useDefault = true)
{
$imageType = ['attachment', 'image'];
$images = [];
@@ -5325,11 +5329,32 @@ function get_image_from_description(array $descriptionArr, $first = false)
}
}
if ($first) {
return getSchemeAndHttpHost() . "/pic/imdb_pic/nophoto.gif";
if ($useDefault) {
return getSchemeAndHttpHost() . "/pic/imdb_pic/nophoto.gif";
} else {
return '';
}
}
return $images;
}
function resize_image($url, $with = null, $height = null, $fit = "cover")
{
$scheme = parse_url($url, PHP_URL_SCHEME);
if ($scheme === false) {
return $url;
}
$url = "$scheme://images.weserv.nl/?url=$url";
if ($with !== null) {
$url .= "&w=$with";
}
if ($height !== null) {
$url .= "&h=$height";
}
$url .= "&fit=$fit";
return $url;
}
function get_share_ratio($uploaded, $downloaded)
{
if ($downloaded) {

View File

@@ -250,12 +250,16 @@ function getLogFile()
function nexus_config($key, $default = null)
{
if (!IN_NEXUS) {
return config($key, $default);
}
static $configs;
if (is_null($configs)) {
//get all configuration from config file
// $files = glob(ROOT_PATH . 'config/*.php');
$files = [
ROOT_PATH . 'config/nexus.php',
ROOT_PATH . 'config/emoji.php',
];
foreach ($files as $file) {
$basename = basename($file);

View File

@@ -150,12 +150,12 @@ class NexusDB
public static function insert($table, $data)
{
if (!IN_NEXUS) {
return DB::table($table)->insertGetId($data);
}
if (empty($table) || empty($data) || !is_array($data)) {
throw new DatabaseException("require table and data(array).");
}
if (!IN_NEXUS) {
return DB::table($table)->insertGetId($data);
}
$fields = array_map(function ($value) {return "`$value`";}, array_keys($data));
$values = array_map(function ($value) {return sqlesc($value);}, array_values($data));
$sql = sprintf("insert into `%s` (%s) values (%s)", $table, implode(', ', $fields), implode(', ', $values));

View File

@@ -193,11 +193,19 @@ if(get_user_class()>=$torrentmanage_class && ($CURUSER['picker'] == 'yes' || get
$doRecommend = true;
}
if ($doRecommend) {
do_log("[DEL_HOT_CLASSIC_RESOURCES]");
\Nexus\Database\NexusDB::cache_del("hot_resources");
\Nexus\Database\NexusDB::cache_del("classic_resources");
}
}
/**
* get cover
* @since 1.7.8
*/
$descriptionArr = format_description($descr);
$cover = get_image_from_description($descriptionArr, true, false);
$updateset[] = "cover = " . sqlesc($cover);
sql_query("UPDATE torrents SET " . join(",", $updateset) . " WHERE id = $id") or sqlerr(__FILE__, __LINE__);

View File

@@ -302,15 +302,55 @@ if (!is_writable($torrentSavePath)) {
bark("torrent save path: $torrentSavePath not writeable.");
}
$ret = sql_query("INSERT INTO torrents (filename, owner, visible, anonymous, name, size, numfiles, type, url, small_descr, descr, ori_descr, category, source, medium, codec, audiocodec, standard, processing, team, save_as, sp_state, added, last_action, nfo, info_hash, pt_gen, technical_info) VALUES (".sqlesc($fname).", ".sqlesc($CURUSER["id"]).", 'yes', ".sqlesc($anonymous).", ".sqlesc($torrent).", ".sqlesc($totallen).", ".count($filelist).", ".sqlesc($type).", ".sqlesc($url).", ".sqlesc($small_descr).", ".sqlesc($descr).", ".sqlesc($descr).", ".sqlesc($catid).", ".sqlesc($sourceid).", ".sqlesc($mediumid).", ".sqlesc($codecid).", ".sqlesc($audiocodecid).", ".sqlesc($standardid).", ".sqlesc($processingid).", ".sqlesc($teamid).", ".sqlesc($dname).", ".sqlesc($sp_state) .
", " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc(date("Y-m-d H:i:s")) . ", ".sqlesc($nfo).", " . sqlesc($infohash). ", " . sqlesc($_POST['pt_gen']) . ", " . sqlesc($_POST['technical_info'] ?? '') . ")");
if (!$ret) {
if (mysql_errno() == 1062)
bark($lang_takeupload['std_torrent_existed']);
bark("mysql puked: ".mysql_error());
//bark("mysql puked: ".preg_replace_callback('/./s', "hex_esc2", mysql_error()));
}
$id = mysql_insert_id();
/**
* get cover
* @since 1.7.8
*/
$descriptionArr = format_description($descr);
$cover = get_image_from_description($descriptionArr, true, false);
$insert = [
'filename' => $fname,
'owner' => $CURUSER['id'],
'visible' => 'yes',
'anonymous' => $anonymous,
'name' => $torrent,
'size' => $totallen,
'numfiles' => count($filelist),
'type' => $type,
'url' => $url,
'small_descr' => $small_descr,
'descr' => $descr,
'ori_descr' => $descr,
'category' => $catid,
'source' => $sourceid,
'medium' => $mediumid,
'codec' => $codecid,
'audiocodec' => $audiocodecid,
'standard' => $standardid,
'processing' => $processingid,
'team' => $teamid,
'save_as' => $dname,
'sp_state' => $sp_state,
'added' => $dateTimeStringNow,
'last_action' => $dateTimeStringNow,
'nfo' => $nfo,
'info_hash' => $infohash,
'pt_gen' => $_POST['pt_gen'] ?? '',
'technical_info' => $_POST['technical_info'] ?? '',
'cover' => $cover,
];
$id = \Nexus\Database\NexusDB::insert('torrents', $insert);
//$ret = sql_query("INSERT INTO torrents (filename, owner, visible, anonymous, name, size, numfiles, type, url, small_descr, descr, ori_descr, category, source, medium, codec, audiocodec, standard, processing, team, save_as, sp_state, added, last_action, nfo, info_hash, pt_gen, technical_info) VALUES (".sqlesc($fname).", ".sqlesc($CURUSER["id"]).", 'yes', ".sqlesc($anonymous).", ".sqlesc($torrent).", ".sqlesc($totallen).", ".count($filelist).", ".sqlesc($type).", ".sqlesc($url).", ".sqlesc($small_descr).", ".sqlesc($descr).", ".sqlesc($descr).", ".sqlesc($catid).", ".sqlesc($sourceid).", ".sqlesc($mediumid).", ".sqlesc($codecid).", ".sqlesc($audiocodecid).", ".sqlesc($standardid).", ".sqlesc($processingid).", ".sqlesc($teamid).", ".sqlesc($dname).", ".sqlesc($sp_state) .
//", " . sqlesc(date("Y-m-d H:i:s")) . ", " . sqlesc(date("Y-m-d H:i:s")) . ", ".sqlesc($nfo).", " . sqlesc($infohash). ", " . sqlesc($_POST['pt_gen']) . ", " . sqlesc($_POST['technical_info'] ?? '') . ")");
//if (!$ret) {
// if (mysql_errno() == 1062)
// bark($lang_takeupload['std_torrent_existed']);
// bark("mysql puked: ".mysql_error());
// //bark("mysql puked: ".preg_replace_callback('/./s', "hex_esc2", mysql_error()));
//}
//$id = mysql_insert_id();
$torrentFilePath = "$torrentSavePath/$id.torrent";
$saveResult = \Rhilip\Bencode\Bencode::dump($torrentFilePath, $dict);
if ($saveResult === false) {