|
|
@ -62,63 +62,167 @@ class TorrentService |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function generateTorrentKeywordsByString( |
|
|
|
|
|
|
|
string $string, |
|
|
|
|
|
|
|
bool $transliteration, |
|
|
|
|
|
|
|
int $wordLengthMin, |
|
|
|
|
|
|
|
int $wordLengthMax, |
|
|
|
|
|
|
|
): array |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$words = explode( |
|
|
|
|
|
|
|
' ', |
|
|
|
|
|
|
|
preg_replace( |
|
|
|
|
|
|
|
'/[\s]+/', |
|
|
|
|
|
|
|
' ', |
|
|
|
|
|
|
|
preg_replace( |
|
|
|
|
|
|
|
'/[\W_]+/u', |
|
|
|
|
|
|
|
' ', |
|
|
|
|
|
|
|
$string |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Apply words filter |
|
|
|
|
|
|
|
foreach ((array) $words as $key => $value) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Apply word length filter |
|
|
|
|
|
|
|
$length = mb_strlen($value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($length < $wordLengthMin || $length > $wordLengthMax) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
unset($words[$key]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Apply case insensitive search conversion |
|
|
|
|
|
|
|
$words[$key] = mb_strtolower($value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($transliteration) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// @TODO |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build simple array |
|
|
|
|
|
|
|
$keywords = []; |
|
|
|
|
|
|
|
foreach ((array) $words as $word) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$keywords[] = $word; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return unique keywords |
|
|
|
|
|
|
|
return array_unique( |
|
|
|
|
|
|
|
$keywords |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function generateTorrentKeywordsByTorrentFilepath( |
|
|
|
public function generateTorrentKeywordsByTorrentFilepath( |
|
|
|
|
|
|
|
|
|
|
|
string $filepath, |
|
|
|
string $filepath, |
|
|
|
int $minLength = 3 |
|
|
|
|
|
|
|
|
|
|
|
bool $extractName, |
|
|
|
|
|
|
|
bool $extractFilenames, |
|
|
|
|
|
|
|
bool $extractInfoHashV1, |
|
|
|
|
|
|
|
bool $extractInfoHashV2, |
|
|
|
|
|
|
|
bool $extractSource, |
|
|
|
|
|
|
|
bool $extractComment, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool $wordTransliteration, |
|
|
|
|
|
|
|
int $wordLengthMin, |
|
|
|
|
|
|
|
int $wordLengthMax |
|
|
|
|
|
|
|
|
|
|
|
): array |
|
|
|
): array |
|
|
|
{ |
|
|
|
{ |
|
|
|
$keywords = []; |
|
|
|
$keywords = []; |
|
|
|
|
|
|
|
|
|
|
|
if ($file = $this->readTorrentFileByFilepath($filepath)) |
|
|
|
if ($file = $this->readTorrentFileByFilepath($filepath)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach ($file->getFileList() as $list) |
|
|
|
if ($extractName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$words = explode( |
|
|
|
if ($name = $file->getName(false)) |
|
|
|
' ', |
|
|
|
{ |
|
|
|
preg_replace( |
|
|
|
$keywords = array_merge( |
|
|
|
'/[\s]+/', |
|
|
|
$keywords, |
|
|
|
' ', |
|
|
|
$this->generateTorrentKeywordsByString( |
|
|
|
preg_replace( |
|
|
|
$name, |
|
|
|
'/[\W_]+/u', |
|
|
|
$wordTransliteration, |
|
|
|
' ', |
|
|
|
$wordLengthMin, |
|
|
|
$list['path'] |
|
|
|
$wordLengthMax |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach ($words as $key => $value) |
|
|
|
if ($extractFilenames) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach ($file->getFileList() as $list) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (mb_strlen($value) < $minLength) |
|
|
|
$keywords = array_merge( |
|
|
|
{ |
|
|
|
$keywords, |
|
|
|
unset($words[$key]); |
|
|
|
$this->generateTorrentKeywordsByString( |
|
|
|
} |
|
|
|
$list['path'], |
|
|
|
|
|
|
|
$wordTransliteration, |
|
|
|
else |
|
|
|
$wordLengthMin, |
|
|
|
{ |
|
|
|
$wordLengthMax |
|
|
|
$words[$key] = mb_strtolower($value); |
|
|
|
) |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($hash = $file->getInfoHashV1(false)) |
|
|
|
if ($extractSource) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($source = $file->getSource(false)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$keywords[] = $hash; |
|
|
|
$keywords = array_merge( |
|
|
|
|
|
|
|
$keywords, |
|
|
|
|
|
|
|
$this->generateTorrentKeywordsByString( |
|
|
|
|
|
|
|
$source, |
|
|
|
|
|
|
|
$wordTransliteration, |
|
|
|
|
|
|
|
$wordLengthMin, |
|
|
|
|
|
|
|
$wordLengthMax |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($hash = $file->getInfoHashV2(false)) |
|
|
|
if ($extractComment) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($comment = $file->getComment(false)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$keywords[] = $hash; |
|
|
|
$keywords = array_merge( |
|
|
|
|
|
|
|
$keywords, |
|
|
|
|
|
|
|
$this->generateTorrentKeywordsByString( |
|
|
|
|
|
|
|
$comment, |
|
|
|
|
|
|
|
$wordTransliteration, |
|
|
|
|
|
|
|
$wordLengthMin, |
|
|
|
|
|
|
|
$wordLengthMax |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($name = $file->getName(false)) |
|
|
|
if ($extractInfoHashV1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($hash = $file->getInfoHashV1(false)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$keywords[] = $name; |
|
|
|
$keywords[] = $hash; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$keywords = array_merge($keywords, $words); |
|
|
|
if ($extractInfoHashV2) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($hash = $file->getInfoHashV2(false)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$keywords[] = $hash; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return array_unique($keywords); |
|
|
|
return array_unique( |
|
|
|
|
|
|
|
$keywords |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getStorageFilepathByTorrentId(int $torrentId): string |
|
|
|
public function getStorageFilepathByTorrentId(int $torrentId): string |
|
|
@ -187,13 +291,27 @@ class TorrentService |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function add( |
|
|
|
public function add( |
|
|
|
|
|
|
|
|
|
|
|
string $filepath, |
|
|
|
string $filepath, |
|
|
|
int $userId, |
|
|
|
|
|
|
|
int $added, |
|
|
|
bool $extractName, |
|
|
|
array $locales, |
|
|
|
bool $extractFilenames, |
|
|
|
bool $sensitive, |
|
|
|
bool $extractInfoHashV1, |
|
|
|
bool $approved, |
|
|
|
bool $extractInfoHashV2, |
|
|
|
bool $status |
|
|
|
bool $extractSource, |
|
|
|
|
|
|
|
bool $extractComment, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool $wordTransliteration, |
|
|
|
|
|
|
|
int $wordLengthMin, |
|
|
|
|
|
|
|
int $wordLengthMax, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int $userId, |
|
|
|
|
|
|
|
int $added, |
|
|
|
|
|
|
|
array $locales, |
|
|
|
|
|
|
|
bool $sensitive, |
|
|
|
|
|
|
|
bool $approved, |
|
|
|
|
|
|
|
bool $status |
|
|
|
|
|
|
|
|
|
|
|
): ?Torrent |
|
|
|
): ?Torrent |
|
|
|
{ |
|
|
|
{ |
|
|
|
$torrent = $this->addTorrent( |
|
|
|
$torrent = $this->addTorrent( |
|
|
@ -201,7 +319,16 @@ class TorrentService |
|
|
|
$added, |
|
|
|
$added, |
|
|
|
md5_file($filepath), |
|
|
|
md5_file($filepath), |
|
|
|
$this->generateTorrentKeywordsByTorrentFilepath( |
|
|
|
$this->generateTorrentKeywordsByTorrentFilepath( |
|
|
|
$filepath |
|
|
|
$filepath, |
|
|
|
|
|
|
|
$extractName, |
|
|
|
|
|
|
|
$extractFilenames, |
|
|
|
|
|
|
|
$extractInfoHashV1, |
|
|
|
|
|
|
|
$extractInfoHashV2, |
|
|
|
|
|
|
|
$extractSource, |
|
|
|
|
|
|
|
$extractComment, |
|
|
|
|
|
|
|
$wordTransliteration, |
|
|
|
|
|
|
|
$wordLengthMin, |
|
|
|
|
|
|
|
$wordLengthMax |
|
|
|
), |
|
|
|
), |
|
|
|
$locales, |
|
|
|
$locales, |
|
|
|
$sensitive, |
|
|
|
$sensitive, |
|
|
@ -489,7 +616,17 @@ class TorrentService |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function reindexTorrentKeywordsAll(): void |
|
|
|
public function reindexTorrentKeywordsAll( |
|
|
|
|
|
|
|
bool $extractName, |
|
|
|
|
|
|
|
bool $extractFilenames, |
|
|
|
|
|
|
|
bool $extractInfoHashV1, |
|
|
|
|
|
|
|
bool $extractInfoHashV2, |
|
|
|
|
|
|
|
bool $extractSource, |
|
|
|
|
|
|
|
bool $extractComment, |
|
|
|
|
|
|
|
bool $wordTransliteration, |
|
|
|
|
|
|
|
int $wordLengthMin, |
|
|
|
|
|
|
|
int $wordLengthMax |
|
|
|
|
|
|
|
): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach ($this->entityManagerInterface |
|
|
|
foreach ($this->entityManagerInterface |
|
|
|
->getRepository(Torrent::class) |
|
|
|
->getRepository(Torrent::class) |
|
|
@ -499,7 +636,16 @@ class TorrentService |
|
|
|
$this->generateTorrentKeywordsByTorrentFilepath( |
|
|
|
$this->generateTorrentKeywordsByTorrentFilepath( |
|
|
|
$this->getStorageFilepathByTorrentId( |
|
|
|
$this->getStorageFilepathByTorrentId( |
|
|
|
$torrent->getId() |
|
|
|
$torrent->getId() |
|
|
|
) |
|
|
|
), |
|
|
|
|
|
|
|
$extractName, |
|
|
|
|
|
|
|
$extractFilenames, |
|
|
|
|
|
|
|
$extractInfoHashV1, |
|
|
|
|
|
|
|
$extractInfoHashV2, |
|
|
|
|
|
|
|
$extractSource, |
|
|
|
|
|
|
|
$extractComment, |
|
|
|
|
|
|
|
$wordTransliteration, |
|
|
|
|
|
|
|
$wordLengthMin, |
|
|
|
|
|
|
|
$wordLengthMax |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|