Compare commits

..

9 Commits

11 changed files with 176 additions and 113 deletions

31
.env
View File

@@ -36,34 +36,3 @@ MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages # MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###< symfony/messenger ### ###< symfony/messenger ###
APP_URL=
APP_SECRET=
# Use the DATABASE_URL below to use the MariaDB container
# provided in the example.compose.yml file, or remove this
# line and fill in the details of your own MySQL/MariaDB server
DATABASE_URL=
# Fill in your MySQL/MariaDB connection details
#DATABASE_URL="mysql://<mysql user>:<mysql pass>@<mysql host>:3306/<mysql db name>?serverVersion=10.6.19.2-MariaDB&charset=utf8mb4"
# Enter your Real Debrid API key
# This key is never saved anywhere
# else and is passed to Torrentio
# to retrieve download options
REAL_DEBRID_KEY=
# Enter you TMDB API key
# This is used to provide rich search results
# when searching for media and rendering the
# Popular Movies and TV Shows section.
TMDB_API=
MERCURE_JWT_SECRET=
# Use your own Redis instance or use the
# below value to use the container included
# in the example compose.yml file.
REDIS_HOST=

View File

@@ -3,7 +3,7 @@
# or pass your certificates into the 'app' container. # or pass your certificates into the 'app' container.
# Please omit any trailing slashes. The APP_URL is # Please omit any trailing slashes. The APP_URL is
# used to generate the Mercure URL behind the scenes. # used to generate the Mercure URL behind the scenes.
APP_URL="https://torsearch-test.caldwell.digital" APP_URL="https://torsearch.idocode.io"
APP_SECRET="70169beadfbc8101c393cbfbba27a313" APP_SECRET="70169beadfbc8101c393cbfbba27a313"
# Use the DATABASE_URL below to use the MariaDB container # Use the DATABASE_URL below to use the MariaDB container
@@ -24,7 +24,7 @@ REAL_DEBRID_KEY=""
# This is used to provide rich search results # This is used to provide rich search results
# when searching for media and rendering the # when searching for media and rendering the
# Popular Movies and TV Shows section. # Popular Movies and TV Shows section.
TMDB_API="" TMDB_API=
MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!" MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"

View File

@@ -3,7 +3,7 @@ services:
# base container. If not running behind a reverse proxy, # base container. If not running behind a reverse proxy,
# inject your SSL certificates into this container # inject your SSL certificates into this container
app: app:
image: registry.caldwell.digital/home/torsearch:test-app image: code.caldwell.digital/home/torsearch:0.14.5-app
ports: ports:
- "8006:80" - "8006:80"
env_file: env_file:
@@ -20,7 +20,7 @@ services:
# This container runs a Symfony worker process. # This container runs a Symfony worker process.
# See: https://symfony.com/doc/current/messenger.html # See: https://symfony.com/doc/current/messenger.html
worker: worker:
image: registry.caldwell.digital/home/torsearch:test-worker image: code.caldwell.digital/home/torsearch:0.14.5-worker
volumes: volumes:
- ./downloads/movies:/var/download/movies - ./downloads/movies:/var/download/movies
- ./downloads/tvshows:/var/download/tvshows - ./downloads/tvshows:/var/download/tvshows
@@ -37,7 +37,7 @@ services:
# This container runs a Symfony worker process. # This container runs a Symfony worker process.
# See: https://symfony.com/doc/current/messenger.html # See: https://symfony.com/doc/current/messenger.html
scheduler: scheduler:
image: registry.caldwell.digital/home/torsearch:test-worker image: code.caldwell.digital/home/torsearch:0.14.5-worker
volumes: volumes:
- ./downloads:/var/download - ./downloads:/var/download
command: php ./bin/console messenger:consume scheduler_monitor -vv --time-limit=3600 command: php ./bin/console messenger:consume scheduler_monitor -vv --time-limit=3600
@@ -82,6 +82,15 @@ services:
timeout: 10s timeout: 10s
retries: 10 retries: 10
redis:
image: redis:latest
volumes:
- redis_data:/data
command: redis-server --maxmemory 512MB
restart: unless-stopped
# **Optional**
# Provides a simple method of viewing the database
adminer: adminer:
image: adminer image: adminer
ports: ports:
@@ -91,3 +100,4 @@ volumes:
mysql: mysql:
mercure_config: mercure_config:
mercure_data: mercure_data:
redis_data:

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250519193350 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE preference ADD type VARCHAR(255) DEFAULT NULL
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE preference DROP type
SQL);
}
}

View File

@@ -53,6 +53,7 @@ class SeedDatabaseCommand extends Command
->setName($preference['name']) ->setName($preference['name'])
->setDescription($preference['description']) ->setDescription($preference['description'])
->setEnabled($preference['enabled']) ->setEnabled($preference['enabled'])
->setType($preference['type'])
); );
} }
@@ -66,26 +67,37 @@ class SeedDatabaseCommand extends Command
'id' => 'codec', 'id' => 'codec',
'name' => 'Codec', 'name' => 'Codec',
'description' => null, 'description' => null,
'enabled' => true 'enabled' => true,
'type' => 'media',
], ],
[ [
'id' => 'resolution', 'id' => 'resolution',
'name' => 'Resolution', 'name' => 'Resolution',
'description' => null, 'description' => null,
'enabled' => true 'enabled' => true,
'type' => 'media',
], ],
[ [
'id' => 'language', 'id' => 'language',
'name' => 'Language', 'name' => 'Language',
'description' => null, 'description' => null,
'enabled' => true 'enabled' => true,
'type' => 'media',
], ],
[ [
'id' => 'provider', 'id' => 'provider',
'name' => 'Provider', 'name' => 'Provider',
'description' => null, 'description' => null,
'enabled' => true 'enabled' => true,
] 'type' => 'media',
],
[
'id' => 'movie_folder',
'name' => 'Create new folder for Movies',
'description' => 'When downloading a movie, store it in a new folder in your base \'movies\' folder. (e.g.: .../movies/Inception/Inception.2160p.h265.mkv)',
'enabled' => true,
'type' => 'download'
],
]; ];
} }

View File

@@ -4,20 +4,15 @@ namespace App\Torrentio\Client;
use App\Torrentio\Client\Rule\DownloadOptionFilter\Resolution; use App\Torrentio\Client\Rule\DownloadOptionFilter\Resolution;
use App\Torrentio\Client\Rule\RuleEngine; use App\Torrentio\Client\Rule\RuleEngine;
use App\Torrentio\MediaResult;
use App\Torrentio\Result\ResultFactory; use App\Torrentio\Result\ResultFactory;
use Carbon\Carbon; use Carbon\Carbon;
use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Contracts\Cache\CacheInterface; use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface; use Symfony\Contracts\Cache\ItemInterface;
/**
* ToDo: Fix
*/
class Torrentio class Torrentio
{ {
private string $baseUrl = 'https://torrentio.strem.fun/providers%253Dyts%252Ceztv%252Crarbg%252C1337x%252Cthepiratebay%252Ckickasstorrents%252Ctorrentgalaxy%252Cmagnetdl%252Chorriblesubs%252Cnyaasi%7Csort%253Dqualitysize%7Cqualityfilter%253D480p%252Cscr%252Ccam%7Crealdebrid={realDebridKey}/stream/movie/{imdbCode}.json'; private string $baseUrl = 'https://torrentio.strem.fun/providers%253Dyts%252Ceztv%252Crarbg%252C1337x%252Cthepiratebay%252Ckickasstorrents%252Ctorrentgalaxy%252Cmagnetdl%252Chorriblesubs%252Cnyaasi%7Csort%253Dqualitysize%7Cqualityfilter%253D480p%252Cscr%252Ccam%7Crealdebrid={realDebridKey}/stream/movie/{imdbCode}.json';
// private string $baseUrl = 'https://torrentio.strem.fun/providers=yts,eztv,rarbg,1337x,thepiratebay,kickasstorrents,torrentgalaxy,magnetdl,horriblesubs|sort=qualitysize|qualityfilter=480p,cam,unknown|debridoptions=nodownloadlinks|realdebrid=QYYBR7OSQ4VEFKWASDEZ2B4VO67KHUJY6IWOT7HHA7ATXO7QCYDQ/stream/{imdbCode}.json';
private string $searchUrl; private string $searchUrl;
@@ -44,26 +39,6 @@ class Torrentio
return $this->parse($results, $filter); return $this->parse($results, $filter);
} }
public function searchBySeriesSeason(MediaResult $series): MediaResult
{
$imdbCode = $series->imdbId;
// foreach ($series->episodes as $season => $episodes) {
// foreach ($episodes as $key => $episode) {
// $cacheKey = "torrentio.$series->imdbId.$season.{$episode['episode_number']}";
// $downloadOptions = $this->cache->get($cacheKey, function (ItemInterface $item) use ($imdbCode, $season, $episode) {
// $item->expiresAt(new \DateTimeImmutable("today 11:59 pm"));
// $response = file_get_contents(str_replace('{imdbCode}', "$imdbCode:$season:{$episode['episode_number']}", $this->searchUrl));
// return json_decode(
// $response,
// true
// );
// });
// $series->episodes[$season][$key]['download_options'] = $this->parse($downloadOptions, []);
// }
// }
return $series;
}
public function fetchEpisodeResults(string $imdbId, int $season, int $episode): array public function fetchEpisodeResults(string $imdbId, int $season, int $episode): array
{ {
$cacheKey = "torrentio.$imdbId.$season.$episode"; $cacheKey = "torrentio.$imdbId.$season.$episode";

View File

@@ -26,22 +26,13 @@ class PreferencesController extends AbstractController
public function __construct( public function __construct(
private readonly PreferencesRepository $preferencesRepository, private readonly PreferencesRepository $preferencesRepository,
private readonly SaveUserMediaPreferencesHandler $saveUserMediaPreferencesHandler, private readonly SaveUserMediaPreferencesHandler $saveUserMediaPreferencesHandler,
private readonly Security $security,
private readonly HubInterface $hub, private readonly HubInterface $hub,
) {} ) {}
#[Route('/media/preferences', 'app_media_preferences', methods: ['GET'])] #[Route('/user/preferences', 'app_user_preferences', methods: ['GET'])]
public function mediaPreferences(): Response public function mediaPreferences(): Response
{ {
$enabledPreferences = $this->preferencesRepository->findEnabled(); $mediaPreferences = $this->getUser()->getMediaPreferences();
$downloadPreferences = $this->getUser()->getDownloadPreferences();
if ($this->security->getUser()->getUserPreferences()->count() !== count($enabledPreferences)) {
$this->setUserPreferences($this->security->getUser(), $enabledPreferences);
}
$userPreferences = $this->security->getUser()->getUserPreferences()->toArray();
$userPreferences = Map::from($userPreferences)
->rekey(fn($preference) => $preference->getPreference()->getId());
$languages = CountryLanguages::$languages; $languages = CountryLanguages::$languages;
sort($languages); sort($languages);
@@ -51,12 +42,13 @@ class PreferencesController extends AbstractController
'preferences' => $this->preferencesRepository->findEnabled(), 'preferences' => $this->preferencesRepository->findEnabled(),
'languages' => $languages, 'languages' => $languages,
'providers' => ProviderList::$providers, 'providers' => ProviderList::$providers,
'userPreferences' => $userPreferences->toArray(), 'mediaPreferences' => $mediaPreferences,
'downloadPreferences' => $downloadPreferences,
] ]
); );
} }
#[Route('/media/preferences', 'app_save_media_preferences', methods: ['POST'])] #[Route('/user/preferences/media', 'app_save_media_preferences', methods: ['POST'])]
public function saveMediaPreferences( public function saveMediaPreferences(
Request $request, Request $request,
SaveUserMediaPreferencesInput $input, SaveUserMediaPreferencesInput $input,
@@ -88,17 +80,35 @@ class PreferencesController extends AbstractController
); );
} }
private function setUserPreferences(User $user, array $preferences): void #[Route('/user/preferences/download', 'app_save_download_preferences', methods: ['POST'])]
public function saveDownloadPreferences(
Request $request,
SaveUserMediaPreferencesInput $input,
): Response
{ {
foreach ($preferences as $preference) { $userPreferences = $this->saveUserMediaPreferencesHandler->handle($input->toCommand())->userPreferences;
if (false === $user->hasUserPreference($preference->getId())) { $userPreferences = Map::from($userPreferences)->rekey(fn($preference) => $preference->getPreference()->getId());
$user->addUserPreference((new UserPreference())
->setUser($user) $languages = CountryLanguages::$languages;
->setPreference($preference) sort($languages);
->setPreferenceValue(null)
); $this->hub->publish(new Update(
} $request->getSession()->get('mercure_alert_topic'),
} $this->renderView('broadcast/Alert.stream.html.twig', [
$this->preferencesRepository->getEntityManager()->flush(); 'alert_id' => uniqid(),
'title' => 'Success',
'message' => 'Your media preferences have been saved.',
])
));
return $this->render(
'user/preferences.html.twig',
[
'preferences' => $this->preferencesRepository->findEnabled(),
'languages' => $languages,
'providers' => ProviderList::$providers,
'userPreferences' => $userPreferences->toArray(),
]
);
} }
} }

View File

@@ -14,6 +14,9 @@ class Preference
#[ORM\Column] #[ORM\Column]
private ?string $id = null; private ?string $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $type = null;
#[ORM\Column(length: 255, nullable: true)] #[ORM\Column(length: 255, nullable: true)]
private ?string $name = null; private ?string $name = null;
@@ -57,6 +60,17 @@ class Preference
return $this; return $this;
} }
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
public function getDescription(): ?string public function getDescription(): ?string
{ {
return $this->description; return $this->description;

View File

@@ -204,7 +204,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this; return $this;
} }
public function getUserPreferenceValues() public function getUserPreferenceValues(string $type = 'all'): array
{ {
return Map::from($this->userPreferences) return Map::from($this->userPreferences)
->rekey(fn(UserPreference $userPreference) => $userPreference->getPreference()->getId()) ->rekey(fn(UserPreference $userPreference) => $userPreference->getPreference()->getId())
@@ -213,7 +213,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $userPreference->getPreferenceValue(); return $userPreference->getPreferenceValue();
} }
foreach ($userPreference->getPreference()->getPreferenceOptions() as $preferenceOption) { foreach ($userPreference->getPreference()->getPreferenceOptions() as $preferenceOption) {
// dd((int) $userPreference->getPreferenceValue(), $preferenceOption->getId(), $preferenceOption->getValue());
if ($preferenceOption->getId() === (int) $userPreference->getPreferenceValue()) { if ($preferenceOption->getId() === (int) $userPreference->getPreferenceValue()) {
return $preferenceOption->getValue(); return $preferenceOption->getValue();
} }
@@ -273,6 +272,24 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this->downloads; return $this->downloads;
} }
public function getMediaPreferences()
{
return Map::from($this->userPreferences)
->rekey(fn(UserPreference $userPreference) => $userPreference->getPreference()->getId())
->filter(fn(UserPreference $userPreference) => $userPreference->getPreference()->getType() === 'media')
->toArray()
;
}
public function getDownloadPreferences()
{
return Map::from($this->userPreferences)
->rekey(fn(UserPreference $userPreference) => $userPreference->getPreference()->getId())
->filter(fn(UserPreference $userPreference) => $userPreference->getPreference()->getType() === 'download')
->toArray()
;
}
/** /**
* @return Collection<int, Download> * @return Collection<int, Download>
*/ */

View File

@@ -21,7 +21,7 @@
</li> </li>
<li> <li>
<a href="{{ path('app_media_preferences') }}" <a href="{{ path('app_user_preferences') }}"
class="block rounded-lg px-4 py-2 text-sm font-medium text-gray-50 hover:bg-gray-100 hover:text-stone-700"> class="block rounded-lg px-4 py-2 text-sm font-medium text-gray-50 hover:bg-gray-100 hover:text-stone-700">
Preferences Preferences
</a> </a>

View File

@@ -3,57 +3,78 @@
{% block h2 %}Preferences{% endblock %} {% block h2 %}Preferences{% endblock %}
{% block body %} {% block body %}
<div class="p-4 flex flex-col"> <div class="p-4 flex flex-row gap-2">
<twig:Card title="Choose your preferences"> <twig:Card title="Media Preferences" class="w-full">
<p class="text-gray-50 mb-2">Define a set of filters to apply to your media download option results.</p> <p class="text-gray-50 mb-2">Define a filter to be pre-applied to your download options.</p>
<form id="media_preferences" class="flex flex-col max-w-64" name="media_preferences" method="post" action="{{ path('app_media_preferences') }}"> <form id="media_preferences" class="flex flex-col max-w-64" name="media_preferences" method="post" action="{{ path('app_save_media_preferences') }}">
<label class="text-gray-50" for="resolution">Resolution</label> <label class="text-gray-50" for="resolution">Resolution</label>
<select class="p-1.5 rounded-md mb-2" name="resolution" id="resolution" value="{{ userPreferences['resolution'].getPreferenceValue() }}"> <select class="p-1.5 rounded-md mb-2" name="resolution" id="resolution" value="{{ mediaPreferences['resolution'].getPreferenceValue() }}">
{% for pref in userPreferences['resolution'].getPreference().getPreferenceOptions() %} <option class="text-gray-800"
value=""
{{ mediaPreferences['resolution'] is null ? "selected" }}
>n/a</option>
{% for pref in mediaPreferences['resolution'].getPreference().getPreferenceOptions() %}
<option class="text-gray-800" <option class="text-gray-800"
value="{{ pref.id }}" value="{{ pref.id }}"
{{ pref.id == userPreferences['resolution'].getPreferenceValue() ? "selected" }} {{ pref.id == mediaPreferences['resolution'].getPreferenceValue() ? "selected" }}
>{{ pref.name }}</option> >{{ pref.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
<label class="text-gray-50" for="codec">Codec</label> <label class="text-gray-50" for="codec">Codec</label>
<select class="p-1.5 rounded-md mb-2" name="codec" id="codec" value="{{ userPreferences['codec'].getPreferenceValue() }}"> <select class="p-1.5 rounded-md mb-2" name="codec" id="codec" value="{{ mediaPreferences['codec'].getPreferenceValue() }}">
{% for pref in userPreferences['codec'].getPreference().getPreferenceOptions() %} <option class="text-gray-800"
value=""
{{ mediaPreferences['codec'].getPreferenceValue() is null ? "selected" }}
>n/a</option>
{% for pref in mediaPreferences['codec'].getPreference().getPreferenceOptions() %}
<option class="text-gray-800" <option class="text-gray-800"
value="{{ pref.id }}" value="{{ pref.id }}"
{{ pref.id == userPreferences['codec'].getPreferenceValue() ? "selected" }} {{ pref.id == mediaPreferences['codec'].getPreferenceValue() ? "selected" }}
>{{ pref.name }}</option> >{{ pref.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
<label class="text-gray-50" for="provider">Provider</label> <label class="text-gray-50" for="provider">Provider</label>
<select class="p-1.5 rounded-md mb-2" name="provider" id="provider" value="{{ userPreferences['provider'].getPreferenceValue() }}"> <select class="p-1.5 rounded-md mb-2" name="provider" id="provider" value="{{ mediaPreferences['provider'].getPreferenceValue() }}">
<option class="text-gray-800" value="" <option class="text-gray-800"
{{ "" == userPreferences['provider'].getPreferenceValue() ? "selected" }} value=""
{{ "" == mediaPreferences['provider'].getPreferenceValue() ? "selected" }}
>n/a</option> >n/a</option>
{% for provider in providers %} {% for provider in providers %}
<option class="text-gray-800" <option class="text-gray-800"
value="{{ provider }}" value="{{ provider }}"
{{ provider == userPreferences['provider'].getPreferenceValue() ? "selected" }} {{ provider == mediaPreferences['provider'].getPreferenceValue() ? "selected" }}
>{{ provider }}</option> >{{ provider }}</option>
{% endfor %} {% endfor %}
</select> </select>
<label class="text-gray-50" for="language">Language</label> <label class="text-gray-50" for="language">Language</label>
<select class="p-1.5 rounded-md mb-2" name="language" id="language" value="{{ userPreferences['language'].getPreferenceValue() }}"> <select class="p-1.5 rounded-md mb-2" name="language" id="language" value="{{ mediaPreferences['language'].getPreferenceValue() }}">
<option class="text-gray-800"
value=""
{{ mediaPreferences['language'].getPreferenceValue() is null ? "selected" }}
>n/a</option>
{% for language in languages %} {% for language in languages %}
<option class="text-gray-800" <option class="text-gray-800"
value="{{ language }}" value="{{ language }}"
{{ language == userPreferences['language'].getPreferenceValue() ? "selected" }} {{ language == mediaPreferences['language'].getPreferenceValue() ? "selected" }}
>{{ language }}</option> >{{ language }}</option>
{% endfor %} {% endfor %}
</select> </select>
<button class="px-1.5 py-1 max-w-20 rounded-md bg-green-600 text-white" type="submit">Submit</button> <button class="px-1.5 py-1 max-w-20 rounded-md bg-green-600 text-white" type="submit">Submit</button>
</form> </form>
</twig:Card> </twig:Card>
<twig:Card title="Download Preferences" class="w-full">
<p class="text-gray-50 mb-2">Change how your downloads are stored.</p>
<form id="media_preferences" class="flex flex-col" name="media_preferences" method="post" action="{{ path('app_save_download_preferences') }}">
<div class="flex flex-row gap-2">
<input type="checkbox" name="movie_folder" id="movie_folder" {{ downloadPreferences['movie_folder'].getPreferenceValue() == true ? 'checked' }} />
<label class="text-gray-50" for="movie_folder">Store movies in a new directory?</label>
</div>
</form>
</twig:Card>
</div> </div>
{% endblock %} {% endblock %}