Add year support to anime folder names
- Add year property to Serie entity with name_with_year - Add year column to AnimeSeries database model - Add get_year() method to AniworldLoader provider - Extract year from folder names before fetching from API - Update SerieScanner to populate year during rescan - Update add_series endpoint to fetch and store year - Optimize: check folder name for year before API call
This commit is contained in:
@@ -380,6 +380,54 @@ class AniworldLoader(Loader):
|
||||
logging.warning(f"No title found for key: {key}")
|
||||
return ""
|
||||
|
||||
def get_year(self, key: str) -> int | None:
|
||||
"""Get anime release year from series key.
|
||||
|
||||
Attempts to extract the year from the series page metadata.
|
||||
Returns None if year cannot be determined.
|
||||
|
||||
Args:
|
||||
key: Series identifier
|
||||
|
||||
Returns:
|
||||
int or None: Release year if found, None otherwise
|
||||
"""
|
||||
logging.debug(f"Getting year for key: {key}")
|
||||
try:
|
||||
soup = BeautifulSoup(
|
||||
self._get_key_html(key).content,
|
||||
'html.parser'
|
||||
)
|
||||
|
||||
# Try to find year in metadata
|
||||
# Check for "Jahr:" or similar metadata fields
|
||||
for p_tag in soup.find_all('p'):
|
||||
text = p_tag.get_text()
|
||||
if 'Jahr:' in text or 'Year:' in text:
|
||||
# Extract year from text like "Jahr: 2025"
|
||||
match = re.search(r'(\d{4})', text)
|
||||
if match:
|
||||
year = int(match.group(1))
|
||||
logging.debug(f"Found year in metadata: {year}")
|
||||
return year
|
||||
|
||||
# Try alternative: look for year in genre/info section
|
||||
info_div = soup.find('div', class_='series-info')
|
||||
if info_div:
|
||||
text = info_div.get_text()
|
||||
match = re.search(r'\b(19\d{2}|20\d{2})\b', text)
|
||||
if match:
|
||||
year = int(match.group(1))
|
||||
logging.debug(f"Found year in info section: {year}")
|
||||
return year
|
||||
|
||||
logging.debug(f"No year found for key: {key}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
logging.warning(f"Error extracting year for key {key}: {e}")
|
||||
return None
|
||||
|
||||
def _get_key_html(self, key: str):
|
||||
"""Get cached HTML for series key.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user