File size: 1,302 Bytes
12e4bed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113fcd6
c37663e
12e4bed
 
 
 
 
 
 
dc6febb
12e4bed
dc6febb
12e4bed
dc6febb
12e4bed
 
dc6febb
12e4bed
 
dc6febb
12e4bed
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

import os
import json
import logging
import asyncio
import traceback
import aiohttp_cors
from aiohttp import web
from pyrogram import raw
from bson import ObjectId
from bson.json_util import dumps
from aiohttp.http_exceptions import BadStatusLine

#---------------------Local Imports----------------------------------#
from FileStream.bot import req_client
from ..Functions import media_streamer
from FileStream.Database import Database
from FileStream.config import Telegram, Server
from FileStream.Exceptions import FileNotFound, InvalidHash
from FileStream.APIs.TMDB.Endpoint import search_tmdb_any, search_tmdb_tv, search_tmdb_movies


# Stream file handler with optimized error handling
async def stream_handler(request: web.Request):
    try:
        path = request.match_info["path"]
        return await media_streamer(request, path, "FAST")

    except InvalidHash as e:

        raise web.HTTPForbidden(text=e.message)

    except FIleNotFound as e:
        raise web.HTTPNotFound(text=e.message)

    except (AttributeError, BadStatusLine, ConnectionResetError):
        pass  # Handle expected errors silently
    
    except Exception as e:
        logging.error(f"Error while streaming file: {str(e)}")
        traceback.print_exc()
        raise web.HTTPInternalServerError(text=str(e))