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
112 lines
4.6 KiB
Python
112 lines
4.6 KiB
Python
import logging
|
|
import random
|
|
from datetime import datetime, timedelta
|
|
|
|
import pytz
|
|
import scrapy
|
|
from dateutil import parser as date_parser
|
|
|
|
from utils.config import config_manager
|
|
from utils.runtime_const import SPORTS_ARTIFACTS
|
|
|
|
|
|
class DaddyLiveHDSpider(scrapy.Spider):
|
|
name = "dlhd"
|
|
start_urls = [config_manager.get_scraper_config(name, "schedule_url")]
|
|
|
|
# The number of hours to consider the event as starting within next hours from now.
|
|
start_within_next_hours = 1
|
|
started_within_hours_ago = 6
|
|
|
|
category_map = config_manager.get_scraper_config(name, "category_mapping")
|
|
m3u8_base_url = config_manager.get_scraper_config(name, "m3u8_base_url")
|
|
referer = config_manager.get_scraper_config(name, "referer")
|
|
gmt = pytz.timezone("Etc/GMT")
|
|
|
|
custom_settings = {
|
|
"ITEM_PIPELINES": {
|
|
"mediafusion_scrapy.pipelines.LiveStreamResolverPipeline": 100,
|
|
"mediafusion_scrapy.pipelines.LiveEventStorePipeline": 300,
|
|
},
|
|
"DUPEFILTER_DEBUG": True,
|
|
}
|
|
|
|
def start_requests(self):
|
|
yield scrapy.Request(self.start_urls[0], self.parse)
|
|
|
|
def parse(self, response, **kwargs):
|
|
data = response.json()
|
|
current_time = datetime.now(tz=self.gmt)
|
|
for date_section, sports in data.items():
|
|
date_str = date_section.split(" - ")[0]
|
|
event_date = date_parser.parse(date_str).date()
|
|
for sport, events in sports.items():
|
|
for event in events:
|
|
time = datetime.strptime(event["time"], "%H:%M").time()
|
|
datetime_obj = datetime.combine(event_date, time)
|
|
# Make the datetime object timezone aware (UK GMT)
|
|
aware_datetime = self.gmt.localize(datetime_obj)
|
|
|
|
# Check if event starts within the specified time range
|
|
time_difference = aware_datetime - current_time
|
|
if not (
|
|
timedelta(hours=-self.started_within_hours_ago)
|
|
<= time_difference
|
|
<= timedelta(hours=self.start_within_next_hours)
|
|
):
|
|
logging.warning(
|
|
"Skipping event %s as it doesn't start within the specified time range. %s",
|
|
event["event"],
|
|
time_difference,
|
|
)
|
|
continue
|
|
|
|
# Convert to UNIX timestamp
|
|
event_start_timestamp = int(aware_datetime.timestamp())
|
|
if event_start_timestamp != 0:
|
|
event_start_time = datetime.fromtimestamp(
|
|
event_start_timestamp
|
|
).strftime("%I:%M%p GMT")
|
|
description = f'{event["event"]} - {event_start_time}'
|
|
else:
|
|
description = event["event"]
|
|
category = self.category_map.get(sport, "Other Sports")
|
|
|
|
item = {
|
|
"stream_source": "DaddyLiveHD (1.dlhd.sx)",
|
|
"genres": [category],
|
|
"poster": random.choice(SPORTS_ARTIFACTS[category]["poster"]),
|
|
"background": random.choice(
|
|
SPORTS_ARTIFACTS[category]["background"]
|
|
),
|
|
"logo": random.choice(SPORTS_ARTIFACTS[category]["logo"]),
|
|
"is_add_title_to_poster": True,
|
|
"title": event["event"],
|
|
"description": description,
|
|
"channels": event["channels"],
|
|
"event_start_timestamp": event_start_timestamp,
|
|
"streams": [],
|
|
}
|
|
yield from self.parse_channels(item)
|
|
|
|
def parse_channels(self, item):
|
|
for channel in item["channels"]:
|
|
item_copy = item.copy()
|
|
m3u8_url = self.m3u8_base_url.format(channel_id=channel["channel_id"])
|
|
item_copy.update(
|
|
{
|
|
"stream_name": channel["channel_name"],
|
|
"stream_url": m3u8_url,
|
|
"stream_headers": {
|
|
"Referer": self.referer,
|
|
"Origin": self.referer.rstrip("/"),
|
|
},
|
|
"response_headers": {
|
|
"Content-Type": "application/vnd.apple.mpegurl",
|
|
},
|
|
"channel_id": channel["channel_id"],
|
|
}
|
|
)
|
|
|
|
yield item_copy
|