Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates #141

Merged
merged 11 commits into from
Sep 7, 2021
Next Next commit
update last_attempt_date *after* the actual attempt so the UI is accu…
…rate, save torrent name on media
  • Loading branch information
lardbit committed Sep 4, 2021
commit c267e1010493ba3ac32028599e79a85c5a4710a0
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
</thead>
<tbody>
<tr *ngFor="let result of results">
<td>
<button type="button" class="btn btn-outline-success" *ngIf="result.torrent" placement="right" [ngbPopover]="result.torrent.name" popoverTitle="Torrent Name">
{{ result.watchMedia.name }}
</button>
<button *ngIf="!result.torrent" type="button" class="btn" [ngClass]="{'btn-outline-success': result.watchMedia.collected, 'btn-outline-secondary': !result.watchMedia.collected}">{{ result.watchMedia.name }}</button>
<td class="text-nowrap">
<button type="button" class="btn" [ngClass]="{'btn-outline-success': result.watchMedia.collected, 'btn-outline-secondary': !result.watchMedia.collected}" placement="right" [ngbPopover]="result.watchMedia.transmission_torrent_name || '(torrent no longer exists)'" popoverTitle="Torrent Name">{{ result.watchMedia.name }}</button>
</td>
<td><span *ngIf="result.watchMedia.release_date">{{ result.watchMedia.release_date | date | date: 'shortDate' }}</span></td>
<td>{{ result.watchMedia.date_added | date | date: 'shortDate' }}</td>
Expand Down
28 changes: 28 additions & 0 deletions src/nefarious/migrations/0066_auto_20210904_2035.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.0.2 on 2021-09-04 20:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nefarious', '0065_auto_20210829_2248'),
]

operations = [
migrations.AddField(
model_name='watchmovie',
name='transmission_torrent_name',
field=models.CharField(blank=True, max_length=1000, null=True),
),
migrations.AddField(
model_name='watchtvepisode',
name='transmission_torrent_name',
field=models.CharField(blank=True, max_length=1000, null=True),
),
migrations.AddField(
model_name='watchtvseason',
name='transmission_torrent_name',
field=models.CharField(blank=True, max_length=1000, null=True),
),
]
1 change: 1 addition & 0 deletions src/nefarious/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class WatchMediaBase(models.Model):
download_path = models.CharField(max_length=1000, blank=True, null=True, unique=True)
last_attempt_date = models.DateTimeField(blank=True, null=True)
transmission_torrent_hash = models.CharField(max_length=100, null=True, blank=True)
transmission_torrent_name = models.CharField(max_length=1000, null=True, blank=True)
release_date = models.DateField(null=True, blank=True)

def abs_download_path(self):
Expand Down
23 changes: 16 additions & 7 deletions src/nefarious/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.conf import settings
from datetime import datetime
from django.utils import dateparse
from transmissionrpc import Torrent

from nefarious.models import WatchMovie, NefariousSettings, TorrentBlacklist, WatchTVEpisode, WatchTVSeason
from nefarious.parsers.movie import MovieParser
from nefarious.parsers.tv import TVParser
Expand Down Expand Up @@ -35,11 +37,6 @@ def fetch(self):
valid_search_results = []
search = self._get_search_results()

# TODO - last attempt should only populate _after_ an actual attempt
# save this attempt date
self.watch_media.last_attempt_date = datetime.utcnow()
self.watch_media.save()

if search.ok:

for result in search.results:
Expand All @@ -66,7 +63,7 @@ def fetch(self):
# add to transmission
torrent = transmission_client.add_torrent(
best_result['torrent_url'],
paused=True, # start paused to we can verify if the torrent has been blacklisted
paused=True, # start paused so we can verify if the torrent has been blacklisted
download_dir=self._get_download_dir(transmission_session),
)

Expand All @@ -82,6 +79,10 @@ def fetch(self):
# start the torrent
if not settings.DEBUG:
torrent.start()

# set attempt date
self._set_last_attempt_date()

return True
else:
# remove the blacklisted/paused torrent and continue to the next result
Expand All @@ -101,6 +102,9 @@ def fetch(self):

logger_background.info('Unable to find any results for media {}'.format(self.watch_media))

# set attempt date
self._set_last_attempt_date()

return False

def is_match(self, title: str) -> bool:
Expand All @@ -117,6 +121,10 @@ def is_match(self, title: str) -> bool:
)
)

def _set_last_attempt_date(self):
self.watch_media.last_attempt_date = datetime.utcnow()
self.watch_media.save()

def _sanitize_title(self, title: str):
# conditionally remove possessive apostrophes
if self._reprocess_without_possessive_apostrophes:
Expand Down Expand Up @@ -150,7 +158,8 @@ def _get_tmdb_title_key(self):
def _get_media_type(self) -> str:
raise NotImplementedError

def _save_torrent_details(self, torrent):
def _save_torrent_details(self, torrent: Torrent):
self.watch_media.transmission_torrent_name = torrent.name
self.watch_media.transmission_torrent_hash = torrent.hashString
self.watch_media.save()

Expand Down