1
0
Fork 0
mirror of https://github.com/fastogt/fastocloud_admin.git synced 2025-03-09 23:38:52 +00:00
fastocloud_admin/scripts/migrate/xtream/streams.py
2019-09-22 03:06:31 -04:00

35 lines
1.1 KiB
Python
Executable file

import json
from app.common.stream.entry import ProxyStream
from app.service.service import ServiceSettings
from app.common.utils.utils import is_valid_http_url
import app.common.constants as constants
def import_streams_to_server(db, server: ServiceSettings):
cursor = db.cursor(dictionary=True)
sql = 'SELECT stream_source, stream_display_name, stream_icon, channel_id from streams'
cursor.execute(sql)
sql_streams = cursor.fetchall()
for sql_entry in sql_streams:
stream = ProxyStream.make_stream(server)
urls = json.loads(sql_entry['stream_source'])
if not len(urls):
continue
stream.output.urls[0].uri = urls[0]
stream.name = sql_entry['stream_display_name']
tvg_logo = sql_entry['stream_icon']
if len(tvg_logo) < constants.MAX_URL_LENGTH:
if is_valid_http_url(tvg_logo, timeout=0.1):
stream.tvg_logo = tvg_logo
epg_id = sql_entry['channel_id']
if epg_id:
stream.tvg_id = epg_id
stream.save()
server.streams.append(stream)
server.save()
cursor.close()