mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-04-01 01:25:39 +00:00
replace bencode library to rhilip/bencode, fix files tree builder #11
This commit is contained in:
parent
387acb59b6
commit
86e1455c6b
9 changed files with 175 additions and 130 deletions
|
|
@ -189,7 +189,7 @@ class PageController extends AbstractController
|
|||
continue;
|
||||
}
|
||||
|
||||
if (empty($torrentService->getTorrentFilenameByFilepath($file->getPathName())))
|
||||
if (empty($torrentService->getTorrentInfoNameByFilepath($file->getPathName())))
|
||||
{
|
||||
$form['torrent']['error'][] = $translator->trans('Could not parse torrent file');
|
||||
|
||||
|
|
|
|||
|
|
@ -40,28 +40,63 @@ class TorrentController extends AbstractController
|
|||
$request->getClientIp()
|
||||
);
|
||||
|
||||
// Init torrent
|
||||
if (!$torrent = $torrentService->getTorrent($request->get('id')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// Init file
|
||||
try
|
||||
{
|
||||
$file = \Rhilip\Bencode\TorrentFile::load(
|
||||
$torrentService->getStoragePathById(
|
||||
$torrent->getId()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
catch (ParseException $e)
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
/*
|
||||
if (!$torrent = $torrentService->getTorrentLocales($request->get('id')))
|
||||
{
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
*/
|
||||
|
||||
//print_r($file->getFileTree());exit;
|
||||
return $this->render('default/torrent/info.html.twig', [
|
||||
'torrent' =>
|
||||
[
|
||||
'id' => $torrent->getId(),
|
||||
'added' => 0, // @TODO
|
||||
'locales' => [], //$torrent->getLocales(),
|
||||
'pages' => []
|
||||
],
|
||||
'file' => $torrentService->decodeTorrentById(
|
||||
$torrent->getId()
|
||||
),
|
||||
'file' =>
|
||||
[
|
||||
'name' => $file->getName(),
|
||||
'size' => $file->getSize(),
|
||||
'count' => $file->getFileCount(),
|
||||
'pieces' => $file->getPieceLength(),
|
||||
'created' => $file->getCreationDate(),
|
||||
'software' => $file->getCreatedBy(),
|
||||
'protocol' => $file->getProtocol(),
|
||||
'private' => $file->isPrivate(),
|
||||
'source' => $file->getSource(),
|
||||
'comment' => $file->getComment(),
|
||||
'tree' => $file->getFileTree(),
|
||||
'trackers' => $file->getAnnounceList(),
|
||||
'hash' =>
|
||||
[
|
||||
'v1' => $file->getInfoHashV1(false),
|
||||
'v2' => $file->getInfoHashV2(false)
|
||||
],
|
||||
'magnet' => $file->getMagnetLink()
|
||||
],
|
||||
'trackers' => explode('|', $this->getParameter('app.trackers')),
|
||||
]);
|
||||
}
|
||||
|
|
@ -158,7 +193,7 @@ class TorrentController extends AbstractController
|
|||
$form['torrent']['error'][] = $translator->trans('Torrent file out of size limit');
|
||||
}
|
||||
|
||||
if (empty($torrentService->getTorrentFilenameByFilepath($file->getPathName())))
|
||||
if (empty($torrentService->getTorrentInfoNameByFilepath($file->getPathName())))
|
||||
{
|
||||
$form['torrent']['error'][] = $translator->trans('Could not parse torrent file');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,38 +29,16 @@ class TorrentService
|
|||
$this->entityManagerInterface = $entityManagerInterface;
|
||||
}
|
||||
|
||||
public function decodeTorrentById(int $id): array
|
||||
public function getStoragePathById(int $id): string
|
||||
{
|
||||
$decoder = new \BitTorrent\Decoder();
|
||||
|
||||
return $decoder->decodeFile(
|
||||
sprintf(
|
||||
'%s/var/torrents/%s.torrent',
|
||||
$this->kernelInterface->getProjectDir(),
|
||||
implode('/', str_split($id))
|
||||
)
|
||||
return sprintf(
|
||||
'%s/var/torrents/%s.torrent',
|
||||
$this->kernelInterface->getProjectDir(),
|
||||
implode('/', str_split($id))
|
||||
);
|
||||
}
|
||||
|
||||
public function decodeTorrentByFilepath(string $filepath): array
|
||||
{
|
||||
$decoder = new \BitTorrent\Decoder();
|
||||
|
||||
return $decoder->decodeFile($filepath);
|
||||
}
|
||||
|
||||
public function getTorrentFilenameByFilepath(string $filepath): string
|
||||
{
|
||||
$data = $this->decodeTorrentByFilepath($filepath);
|
||||
|
||||
if (!empty($data['info']['name']))
|
||||
{
|
||||
return $data['info']['name'];
|
||||
}
|
||||
|
||||
return $data['info']['name'];
|
||||
}
|
||||
|
||||
/*
|
||||
public function getTorrentKeywordsByFilepath(string $filepath): string
|
||||
{
|
||||
$data = $this->decodeTorrentByFilepath($filepath);
|
||||
|
|
@ -82,6 +60,7 @@ class TorrentService
|
|||
|
||||
return '';
|
||||
}
|
||||
*/
|
||||
|
||||
public function getTorrent(int $id): ?Torrent
|
||||
{
|
||||
|
|
@ -100,17 +79,15 @@ class TorrentService
|
|||
): ?Torrent
|
||||
{
|
||||
$torrent = $this->saveTorrent(
|
||||
$this->getTorrentFilenameByFilepath($filepath),
|
||||
$this->getTorrentInfoNameByFilepath($filepath),
|
||||
$this->getTorrentKeywordsByFilepath($filepath)
|
||||
);
|
||||
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->copy(
|
||||
$filepath,
|
||||
sprintf(
|
||||
'%s/var/torrents/%s.torrent',
|
||||
$this->kernelInterface->getProjectDir(),
|
||||
implode('/', str_split($torrent->getId()))
|
||||
$this->getStoragePathById(
|
||||
$torrent->getId()
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue