Added support for proxy for each channel. Added rai 4,rai 5 and rai premium

This commit is contained in:
2025-02-28 21:03:26 -06:00
parent b333851e37
commit 3d1e65f17a
2 changed files with 31 additions and 6 deletions

View File

@@ -64,6 +64,24 @@
"id": "13",
"name": "Nove",
"url": "https://cachehsi1a.netplus.ch/live/eds/nove/browser-dash/nove.mpd"
},
{
"id": "14",
"name": "Rai 4",
"url": "https://raiplay.it/dirette/rai4",
"proxy": "https://G6mnrdkzmBGy1xo5PsewoKQy:VCLFhoWnbrNrUkAu74mvt8yU@it132.nordvpn.com:89"
},
{
"id": "15",
"name": "Rai 5",
"url": "https://raiplay.it/dirette/rai5",
"proxy": "https://G6mnrdkzmBGy1xo5PsewoKQy:VCLFhoWnbrNrUkAu74mvt8yU@it132.nordvpn.com:89"
},
{
"id": "16",
"name": "Premium",
"url": "https://raiplay.it/dirette/raipremium",
"proxy": "https://G6mnrdkzmBGy1xo5PsewoKQy:VCLFhoWnbrNrUkAu74mvt8yU@it132.nordvpn.com:89"
}
]
}

View File

@@ -35,7 +35,7 @@ def load_channels():
with open(channels_path, 'r') as f:
return {str(c['id']): c for c in json.load(f)['channels']}
async def generate_streamlink_process(url, headers=None) -> Process:
async def generate_streamlink_process(url, headers=None, proxy=None) -> Process:
"""
Run Streamlink as an async subprocess and pipe its output to the response.
Args:
@@ -53,6 +53,10 @@ async def generate_streamlink_process(url, headers=None) -> Process:
'--ringbuffer-size', '32M',
]
# Add proxy if specified
if proxy:
cmd.extend(['--http-proxy', proxy])
# Add headers if specified
if headers:
for key, value in headers.items():
@@ -67,14 +71,14 @@ async def generate_streamlink_process(url, headers=None) -> Process:
)
return process
async def stream_generator(process: Process, url: str, headers=None):
async def stream_generator(process: Process, url: str, headers=None, proxy=None):
"""Generate streaming content asynchronously"""
CHUNK_SIZE = 32768
try:
while True:
if process.returncode is not None:
# Process has terminated, restart it
process = await generate_streamlink_process(url, headers)
process = await generate_streamlink_process(url, headers, proxy)
continue
try:
@@ -90,7 +94,7 @@ async def stream_generator(process: Process, url: str, headers=None):
process.terminate()
except:
pass
process = await generate_streamlink_process(url, headers)
process = await generate_streamlink_process(url, headers, proxy)
finally:
try:
process.terminate()
@@ -123,10 +127,13 @@ async def stream_channel(channel_id: str, auth: bool = Depends(verify_credential
if 'referer' in channel:
headers['Referer'] = channel['referer']
# Get proxy if specified
proxy = channel.get('proxy')
try:
process = await generate_streamlink_process(url, headers if headers else None)
process = await generate_streamlink_process(url, headers if headers else None, proxy if proxy else None)
return StreamingResponse(
stream_generator(process, url, headers if headers else None),
stream_generator(process, url, headers if headers else None, proxy if proxy else None),
media_type='video/mp2t'
)
except Exception as e: