mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 10:45:27 +00:00
Store full content-length if using head request to initalize.
This commit is contained in:
parent
5eeb51585d
commit
3e16614eab
2 changed files with 28 additions and 1 deletions
|
|
@ -93,7 +93,24 @@ class PersistentVODConnection:
|
|||
|
||||
# Capture headers from final URL
|
||||
if not self.content_length:
|
||||
self.content_length = response.headers.get('content-length')
|
||||
# First check if we have a pre-stored content length from HEAD request
|
||||
try:
|
||||
import redis
|
||||
r = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True)
|
||||
content_length_key = f"vod_content_length:{self.session_id}"
|
||||
stored_length = r.get(content_length_key)
|
||||
if stored_length:
|
||||
self.content_length = stored_length
|
||||
logger.info(f"[{self.session_id}] *** USING PRE-STORED CONTENT LENGTH: {self.content_length} ***")
|
||||
else:
|
||||
# Fallback to response headers
|
||||
self.content_length = response.headers.get('content-length')
|
||||
logger.info(f"[{self.session_id}] *** USING RESPONSE CONTENT LENGTH: {self.content_length} ***")
|
||||
except Exception as e:
|
||||
logger.error(f"[{self.session_id}] Error checking Redis for content length: {e}")
|
||||
# Fallback to response headers
|
||||
self.content_length = response.headers.get('content-length')
|
||||
|
||||
self.content_type = response.headers.get('content-type', 'video/mp4')
|
||||
self.final_url = response.url
|
||||
logger.info(f"[{self.session_id}] *** PERSISTENT CONNECTION - Final URL: {self.final_url} ***")
|
||||
|
|
|
|||
|
|
@ -292,6 +292,16 @@ class VODStreamView(View):
|
|||
# Close the small range request - we don't need to keep this connection
|
||||
response.close()
|
||||
|
||||
# Store the total content length in Redis for the persistent connection to use
|
||||
try:
|
||||
import redis
|
||||
r = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True)
|
||||
content_length_key = f"vod_content_length:{session_id}"
|
||||
r.set(content_length_key, total_size, ex=1800) # Store for 30 minutes
|
||||
logger.info(f"[VOD-HEAD] Stored total content length {total_size} for session {session_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"[VOD-HEAD] Failed to store content length in Redis: {e}")
|
||||
|
||||
# Now create a persistent connection for the session (if one doesn't exist)
|
||||
# This ensures the FUSE GET requests will reuse the same connection
|
||||
connection_manager = VODConnectionManager.get_instance()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue