mirror of
https://github.com/Viren070/MediaFusion.git
synced 2025-12-01 23:21:11 +01:00
52d8956034
* Refactor ZileanScraper to use parallel requests for searching and filtering streams with new endpoints * Fix DLHD scraping & enable DLHD without MediaFlow * Switch to httpx for async HTTP requests * Implement caching for PikPak token to reduce login error * Refactor torrent cleanup logic * Add inactivity monitor extension to close idle spiders Introduced `InactivityMonitor` to automatically close spiders that remain inactive for a specified time. This extension checks activity at regular intervals and uses configurable settings for check intervals and inactivity timeouts. If no items are scraped within the timeout period, the spider is closed to free resources. * Handle TypeError in dynamic sorting of streams * Refactor torrent info scraper to support pre-processing. Introduced a pre-processing function mapping to handle specific indexer requirements before parsing the HTML. Added a custom pre-processing function for "TheRARBG" to handle URL adjustments, improving modularity and readability in the `get_torrent_info` function. * Refine error logging and fix hash key in spider * Fix Prowlarr not stop on max process limit * #315: Integrate ScrapeOps logging into all scrapers & spiders Added ScrapeOps logging to Zilean, Torrentio, Prowlarr, and Prowlarr Feed scrapers to enhance request tracking and error handling. Configured ScrapeOps API key in settings and updated Pipfile/Pipfile.lock with scrapeops-python-requests and scrapeops-scrapy dependencies. * Refactor scraper cache status handler * verify torrent before parsing on prowlarr & prioritize magnet on badass_torrents * Add support for provide locally hosted mediaflow proxy public address and reduce the time leg on private ip address checking * handle RD exception cases * do not setup scrapeops when api key is none * Enhanced dynamic sorting of torrent streams Revised the dynamic_sort_key function to handle different key types more efficiently with match-case. Simplified error handling and improved logging to capture sorting data in the case of exceptions. * add missing last update date for metadata * update domain for nowmesports
232 lines
7.8 KiB
Python
232 lines
7.8 KiB
Python
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
from apscheduler.triggers.cron import CronTrigger
|
|
|
|
from db.config import settings
|
|
from mediafusion_scrapy.task import run_spider
|
|
from scrapers.imdb_data import fetch_movie_ids_to_update
|
|
from scrapers.prowlarr_feed import run_prowlarr_feed_scraper
|
|
from scrapers.trackers import update_torrent_seeders
|
|
from scrapers.tv import validate_tv_streams_in_db
|
|
from scrapers.utils import cleanup_expired_scraper_task
|
|
|
|
|
|
def setup_scheduler(scheduler: AsyncIOScheduler):
|
|
"""
|
|
Set up the scheduler with the required jobs.
|
|
"""
|
|
# Setup tamil blasters scraper
|
|
if not settings.disable_tamil_blasters_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.tamil_blasters_scheduler_crontab),
|
|
name="tamil_blasters",
|
|
kwargs={
|
|
"spider_name": "tamil_blasters",
|
|
"crontab_expression": settings.tamil_blasters_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Setup tamilmv scraper
|
|
if not settings.disable_tamilmv_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.tamilmv_scheduler_crontab),
|
|
name="tamilmv",
|
|
kwargs={
|
|
"spider_name": "tamilmv",
|
|
"crontab_expression": settings.tamilmv_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Setup formula_tgx scraper
|
|
if not settings.disable_formula_tgx_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.formula_tgx_scheduler_crontab),
|
|
name="formula_tgx",
|
|
kwargs={
|
|
"spider_name": "formula_tgx",
|
|
"scrape_all": "false",
|
|
"crontab_expression": settings.formula_tgx_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Setup nowmetv scraper
|
|
if not settings.disable_nowmetv_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.nowmetv_scheduler_crontab),
|
|
name="nowmetv",
|
|
kwargs={
|
|
"spider_name": "nowmetv",
|
|
"crontab_expression": settings.nowmetv_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Setup nowsports scraper
|
|
if not settings.disable_nowsports_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.nowsports_scheduler_crontab),
|
|
name="nowsports",
|
|
kwargs={
|
|
"spider_name": "nowsports",
|
|
"crontab_expression": settings.nowsports_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Setup tamilultra scraper
|
|
if not settings.disable_tamilultra_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.tamilultra_scheduler_crontab),
|
|
name="tamilultra",
|
|
kwargs={
|
|
"spider_name": "tamilultra",
|
|
"crontab_expression": settings.tamilultra_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Schedule validate_tv_streams_in_db
|
|
if not settings.disable_validate_tv_streams_in_db:
|
|
scheduler.add_job(
|
|
validate_tv_streams_in_db.send,
|
|
CronTrigger.from_crontab(settings.validate_tv_streams_in_db_crontab),
|
|
name="validate_tv_streams_in_db",
|
|
kwargs={"crontab_expression": settings.validate_tv_streams_in_db_crontab},
|
|
)
|
|
|
|
# Schedule sport_video scraper
|
|
if not settings.disable_sport_video_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.sport_video_scheduler_crontab),
|
|
name="sport_video",
|
|
kwargs={
|
|
"spider_name": "sport_video",
|
|
"scrape_all": "false",
|
|
"crontab_expression": settings.sport_video_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Schedule streamed scraper
|
|
if not settings.disable_streamed_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.streamed_scheduler_crontab),
|
|
name="streamed",
|
|
kwargs={
|
|
"spider_name": "streamed",
|
|
"crontab_expression": settings.streamed_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Schedule streambtw scraper
|
|
if not settings.disable_streambtw_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.streambtw_scheduler_crontab),
|
|
name="streambtw",
|
|
kwargs={
|
|
"spider_name": "streambtw",
|
|
"crontab_expression": settings.streambtw_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
# Schedule dlhd scraper
|
|
if not settings.disable_dlhd_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.dlhd_scheduler_crontab),
|
|
name="dlhd",
|
|
kwargs={
|
|
"spider_name": "dlhd",
|
|
"crontab_expression": settings.dlhd_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
scheduler.add_job(
|
|
fetch_movie_ids_to_update.send,
|
|
CronTrigger.from_crontab(settings.update_imdb_data_crontab),
|
|
name="update_imdb_data",
|
|
kwargs={
|
|
"crontab_expression": settings.update_imdb_data_crontab,
|
|
},
|
|
)
|
|
|
|
if not settings.disable_motogp_tgx_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.motogp_tgx_scheduler_crontab),
|
|
name="motogp_tgx",
|
|
kwargs={
|
|
"spider_name": "motogp_tgx",
|
|
"crontab_expression": settings.motogp_tgx_scheduler_crontab,
|
|
"scrape_all": "false",
|
|
},
|
|
)
|
|
|
|
scheduler.add_job(
|
|
update_torrent_seeders.send,
|
|
CronTrigger.from_crontab(settings.update_seeders_crontab),
|
|
name="update_seeders",
|
|
kwargs={
|
|
"crontab_expression": settings.update_seeders_crontab,
|
|
},
|
|
)
|
|
|
|
if not settings.disable_arab_torrents_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.arab_torrents_scheduler_crontab),
|
|
name="arab_torrents",
|
|
kwargs={
|
|
"spider_name": "arab_torrents",
|
|
"crontab_expression": settings.arab_torrents_scheduler_crontab,
|
|
},
|
|
)
|
|
|
|
if not settings.disable_wwe_tgx_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.wwe_tgx_scheduler_crontab),
|
|
name="wwe_tgx",
|
|
kwargs={
|
|
"spider_name": "wwe_tgx",
|
|
"crontab_expression": settings.wwe_tgx_scheduler_crontab,
|
|
"scrape_all": "false",
|
|
},
|
|
)
|
|
|
|
if not settings.disable_ufc_tgx_scheduler:
|
|
scheduler.add_job(
|
|
run_spider.send,
|
|
CronTrigger.from_crontab(settings.ufc_tgx_scheduler_crontab),
|
|
name="ufc_tgx",
|
|
kwargs={
|
|
"spider_name": "ufc_tgx",
|
|
"crontab_expression": settings.ufc_tgx_scheduler_crontab,
|
|
"scrape_all": "false",
|
|
},
|
|
)
|
|
|
|
# Schedule the feed scraper
|
|
if not settings.disable_prowlarr_feed_scraper:
|
|
scheduler.add_job(
|
|
run_prowlarr_feed_scraper.send,
|
|
CronTrigger.from_crontab(settings.prowlarr_feed_scraper_crontab),
|
|
name="prowlarr_feed_scraper",
|
|
kwargs={
|
|
"crontab_expression": settings.prowlarr_feed_scraper_crontab,
|
|
},
|
|
)
|
|
|
|
scheduler.add_job(
|
|
cleanup_expired_scraper_task.send,
|
|
CronTrigger.from_crontab(settings.cleanup_expired_scraper_task_crontab),
|
|
name="cleanup_expired_scraper_task",
|
|
kwargs={
|
|
"crontab_expression": settings.cleanup_expired_scraper_task_crontab,
|
|
},
|
|
)
|