mirror of
https://github.com/fastogt/fastocloud_admin.git
synced 2025-03-09 23:38:52 +00:00
Import streams from xtream
This commit is contained in:
parent
de0bc0b772
commit
3a6c527ef4
1 changed files with 77 additions and 0 deletions
77
scripts/import_streams_from_xtream.py
Executable file
77
scripts/import_streams_from_xtream.py
Executable file
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from mongoengine import connect
|
||||
import mysql.connector
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
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
|
||||
|
||||
PROJECT_NAME = 'import_streams_from_xtream'
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(prog=PROJECT_NAME, usage='%(prog)s [options]')
|
||||
parser.add_argument('--mongo_uri', help='MongoDB credentials', default='mongodb://localhost:27017/iptv')
|
||||
parser.add_argument('--mysql_host', help='MySQL host', default='localhost')
|
||||
parser.add_argument('--mysql_user', help='MySQL username', default='')
|
||||
parser.add_argument('--mysql_password', help='MySQL password', default='')
|
||||
parser.add_argument('--mysql_port', help='MySQL port', default=3306)
|
||||
parser.add_argument('--server_id', help='Server ID', default='')
|
||||
|
||||
argv = parser.parse_args()
|
||||
mysql_host = argv.mysql_host
|
||||
mysql_user = argv.mysql_user
|
||||
mysql_password = argv.mysql_password
|
||||
mysql_port = argv.mysql_port
|
||||
server_id = argv.server_id
|
||||
country = argv.country
|
||||
|
||||
mongo = connect(host=argv.mongo_uri)
|
||||
if not mongo:
|
||||
sys.exit(1)
|
||||
|
||||
server = ServiceSettings.objects(id=server_id).first()
|
||||
if not server:
|
||||
sys.exit(1)
|
||||
|
||||
db = mysql.connector.connect(
|
||||
host=mysql_host,
|
||||
port=mysql_port,
|
||||
user=mysql_user,
|
||||
passwd=mysql_password,
|
||||
database='xtream_iptvpro'
|
||||
)
|
||||
|
||||
cursor = db.cursor(dictionary=True)
|
||||
|
||||
sql = 'SELECT stream_source, stream_display_name, stream_icon, direct_source, epg_id from streams'
|
||||
|
||||
cursor.execute(sql)
|
||||
|
||||
sql_streams = cursor.fetchall()
|
||||
|
||||
streams = []
|
||||
for sql_entry in sql_streams:
|
||||
#print(sql_entry)
|
||||
stream = ProxyStream.make_stream(server)
|
||||
stream.output.urls[0].uri = sql_entry['stream_source']
|
||||
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 = sql_entry['epg_id']
|
||||
stream.tvg_id = sql_entry['epg_id']
|
||||
|
||||
stream.save()
|
||||
streams.append(stream)
|
||||
|
||||
server.add_streams(streams)
|
||||
|
||||
cursor.close()
|
||||
db.close()
|
Loading…
Add table
Add a link
Reference in a new issue