mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-26 02:35:57 +02:00
auto update show metadata weekly
This commit is contained in:
@@ -51,7 +51,9 @@ import media_manager.tv.router as tv_router
|
|||||||
from media_manager.tv.service import (
|
from media_manager.tv.service import (
|
||||||
auto_download_all_approved_season_requests,
|
auto_download_all_approved_season_requests,
|
||||||
import_all_torrents,
|
import_all_torrents,
|
||||||
|
update_all_non_ended_shows_metadata,
|
||||||
)
|
)
|
||||||
|
|
||||||
from media_manager.config import BasicConfig
|
from media_manager.config import BasicConfig
|
||||||
|
|
||||||
import media_manager.torrent.router as torrent_router
|
import media_manager.torrent.router as torrent_router
|
||||||
@@ -77,14 +79,20 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
def hourly_tasks():
|
def hourly_tasks():
|
||||||
log.info(f"Tasks are running at {datetime.now()}")
|
log.info(f"Hourly tasks are running at {datetime.now()}")
|
||||||
auto_download_all_approved_season_requests()
|
auto_download_all_approved_season_requests()
|
||||||
import_all_torrents()
|
import_all_torrents()
|
||||||
|
|
||||||
|
def weekly_tasks():
|
||||||
|
log.info(f"Weekly tasks are running at {datetime.now()}")
|
||||||
|
update_all_non_ended_shows_metadata()
|
||||||
|
|
||||||
|
|
||||||
scheduler = BackgroundScheduler()
|
scheduler = BackgroundScheduler()
|
||||||
trigger = CronTrigger(minute=0, hour="*")
|
trigger = CronTrigger(minute=0, hour="*")
|
||||||
|
weekly_trigger = CronTrigger(day_of_week="mon", hour=0, minute=0, jitter=60*60*24*2)
|
||||||
scheduler.add_job(hourly_tasks, trigger)
|
scheduler.add_job(hourly_tasks, trigger)
|
||||||
|
scheduler.add_job(weekly_tasks, trigger)
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -707,6 +707,7 @@ def auto_download_all_approved_season_requests() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
log.info(f"Auto downloaded {count} approved season requests")
|
log.info(f"Auto downloaded {count} approved season requests")
|
||||||
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
@@ -734,3 +735,33 @@ def import_all_torrents() -> None:
|
|||||||
continue
|
continue
|
||||||
imported_torrents.append(tv_service.import_torrent_files(torrent=t, show=show))
|
imported_torrents.append(tv_service.import_torrent_files(torrent=t, show=show))
|
||||||
log.info("Finished importing all torrents")
|
log.info("Finished importing all torrents")
|
||||||
|
db.commit()
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
def update_all_non_ended_shows_metadata() -> None:
|
||||||
|
"""
|
||||||
|
Updates the metadata of all non-ended shows.
|
||||||
|
"""
|
||||||
|
db: Session = SessionLocal()
|
||||||
|
tv_repository = TvRepository(db=db)
|
||||||
|
tv_service = TvService(
|
||||||
|
tv_repository=tv_repository,
|
||||||
|
torrent_service=TorrentService(torrent_repository=TorrentRepository(db=db)),
|
||||||
|
indexer_service=IndexerService(indexer_repository=IndexerRepository(db=db)),
|
||||||
|
)
|
||||||
|
|
||||||
|
log.info("Updating metadata for all non-ended shows")
|
||||||
|
|
||||||
|
shows = [show for show in tv_repository.get_shows() if not show.ended]
|
||||||
|
|
||||||
|
log.info(f"Found {len(shows)} non-ended shows to update")
|
||||||
|
|
||||||
|
for show in shows:
|
||||||
|
updated_show = tv_service.update_show_metadata(db_show=show)
|
||||||
|
if updated_show:
|
||||||
|
log.info(f"Successfully updated metadata for show: {updated_show.name}")
|
||||||
|
else:
|
||||||
|
log.warning(f"Failed to update metadata for show: {show.name}")
|
||||||
|
db.commit()
|
||||||
|
db.close()
|
||||||
Reference in New Issue
Block a user