Added support for proxy for each channel. Added rai 4,rai 5 and rai premium
This commit is contained in:
@@ -64,6 +64,24 @@
|
|||||||
"id": "13",
|
"id": "13",
|
||||||
"name": "Nove",
|
"name": "Nove",
|
||||||
"url": "https://cachehsi1a.netplus.ch/live/eds/nove/browser-dash/nove.mpd"
|
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ def load_channels():
|
|||||||
with open(channels_path, 'r') as f:
|
with open(channels_path, 'r') as f:
|
||||||
return {str(c['id']): c for c in json.load(f)['channels']}
|
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.
|
Run Streamlink as an async subprocess and pipe its output to the response.
|
||||||
Args:
|
Args:
|
||||||
@@ -53,6 +53,10 @@ async def generate_streamlink_process(url, headers=None) -> Process:
|
|||||||
'--ringbuffer-size', '32M',
|
'--ringbuffer-size', '32M',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Add proxy if specified
|
||||||
|
if proxy:
|
||||||
|
cmd.extend(['--http-proxy', proxy])
|
||||||
|
|
||||||
# Add headers if specified
|
# Add headers if specified
|
||||||
if headers:
|
if headers:
|
||||||
for key, value in headers.items():
|
for key, value in headers.items():
|
||||||
@@ -67,14 +71,14 @@ async def generate_streamlink_process(url, headers=None) -> Process:
|
|||||||
)
|
)
|
||||||
return 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"""
|
"""Generate streaming content asynchronously"""
|
||||||
CHUNK_SIZE = 32768
|
CHUNK_SIZE = 32768
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
if process.returncode is not None:
|
if process.returncode is not None:
|
||||||
# Process has terminated, restart it
|
# Process has terminated, restart it
|
||||||
process = await generate_streamlink_process(url, headers)
|
process = await generate_streamlink_process(url, headers, proxy)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -90,7 +94,7 @@ async def stream_generator(process: Process, url: str, headers=None):
|
|||||||
process.terminate()
|
process.terminate()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
process = await generate_streamlink_process(url, headers)
|
process = await generate_streamlink_process(url, headers, proxy)
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
process.terminate()
|
process.terminate()
|
||||||
@@ -123,10 +127,13 @@ async def stream_channel(channel_id: str, auth: bool = Depends(verify_credential
|
|||||||
if 'referer' in channel:
|
if 'referer' in channel:
|
||||||
headers['Referer'] = channel['referer']
|
headers['Referer'] = channel['referer']
|
||||||
|
|
||||||
|
# Get proxy if specified
|
||||||
|
proxy = channel.get('proxy')
|
||||||
|
|
||||||
try:
|
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(
|
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'
|
media_type='video/mp2t'
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user