Add season and episode tags in NFO

This commit is contained in:
Someone 2023-12-09 17:55:17 +01:00 committed by GitHub
parent c159c24d15
commit b9b702ab85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 0 deletions

View File

@ -1269,6 +1269,21 @@ class Media(models.Model):
showtitle.text = str(self.source.name).strip()
showtitle.tail = '\n '
nfo.append(showtitle)
# season = upload date year
season = nfo.makeelement('season', {})
if self.source.source_type == Source.SOURCE_TYPE_YOUTUBE_PLAYLIST:
# If it's a playlist, set season to 1
season.text = '1'
else:
# If it's not a playlist, set season to upload date year
season.text = str(self.upload_date.year) if self.upload_date else ''
season.tail = '\n '
nfo.append(season)
# episode = number of video in the year
episode = nfo.makeelement('episode', {})
episode.text = str(self.calculate_episode_number()) # Remplacez par la logique de calcul
episode.tail = '\n '
nfo.append(episode)
# ratings = media metadata youtube rating
value = nfo.makeelement('value', {})
value.text = str(self.rating)
@ -1393,6 +1408,38 @@ class Media(models.Model):
f'has no indexer')
return indexer(self.url)
def calculate_episode_number(self):
filtered_media = Media.objects.filter(source=self.source)
if self.source.source_type == Source.SOURCE_TYPE_YOUTUBE_PLAYLIST:
# Calculate the episode number based on the position in the playlist
position_counter = 1
for media in filtered_media:
if media == self:
return position_counter
position_counter += 1
else:
# Sort the filtered media by upload_date in ascending order and video ID
sorted_media = sorted(filtered_media, key=lambda x: (x.upload_date, x.id))
# Initialize an episode counter by year
episode_counter = {}
self_year = self.upload_date.year if self.upload_date else self.created.year
for media in sorted_media:
year = media.upload_date.year
if year not in episode_counter:
# If it's the first video of the year, initialize the counter to 1
episode_counter[year] = 1
else:
# If it's not the first video of the year, use the current counter
episode_counter[year] += 1
# Assign the calculated episode number to the media
if media == self:
return episode_counter[self_year]
class MediaServer(models.Model):
'''