1
0
Fork 0
mirror of https://github.com/fastogt/fastocloud_admin.git synced 2025-03-09 23:38:52 +00:00

Folder for migrate

This commit is contained in:
topilski 2019-09-21 11:14:18 -04:00
parent cd448cb001
commit a5647b37e5
6 changed files with 218 additions and 64 deletions

View file

@ -8,8 +8,8 @@ import mysql.connector
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from app.service.service import ServiceSettings
from .import_streams_from_xtream import import_streams_to_server
from .import_subscribers_from_xtream import import_subscribers_to_server
from migrate.xtream.subscribers import import_subscribers_to_server
from migrate.xtream.streams import import_streams_to_server
PROJECT_NAME = 'import_streams_from_xtream'

View file

@ -2,49 +2,16 @@
import argparse
import os
import sys
import json
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
from migrate.xtream.streams import import_streams_to_server
PROJECT_NAME = 'import_streams_from_xtream'
def import_streams_to_server(db, server):
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()
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')

View file

@ -2,43 +2,16 @@
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.subscriber.login.entry import SubscriberUser
from app.common.subscriber.entry import Device
from app.service.service import ServiceSettings
PROJECT_NAME = 'import_subscribers_from_xtream'
def import_subscribers_to_server(db, server):
cursor = db.cursor(dictionary=True)
sql = 'SELECT username,password,created_at,exp_date FROM users'
cursor.execute(sql)
sql_subscribers = cursor.fetchall()
for sql_entry in sql_subscribers:
new_user = SubscriberUser.make_subscriber(email=sql_entry['username'], password=sql_entry['password'],
country='US')
new_user.status = SubscriberUser.Status.ACTIVE
created_at = sql_entry['created_at']
if created_at:
new_user.created_date = datetime.fromtimestamp(created_at)
exp_date = sql_entry['exp_date']
if exp_date:
new_user.exp_date = datetime.fromtimestamp(exp_date)
dev = Device(name='Xtream')
new_user.add_device(dev)
# save
new_user.add_server(server)
server.add_subscriber(new_user)
cursor.close()
from migrate.xtream.subscribers import import_subscribers_to_server
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog=PROJECT_NAME, usage='%(prog)s [options]')

View file

@ -0,0 +1,95 @@
import os
from flask import Flask
from flask_mongoengine import MongoEngine
from flask_login import LoginManager
from flask_mail import Mail
from flask_bootstrap import Bootstrap
from flask_babel import Babel
from flask_socketio import SocketIO
from werkzeug.contrib.fixers import ProxyFix
from app.service.service_manager import ServiceManager
from app.service.subscribers_service_manager import SubscribersServiceManager
def get_app_folder():
return os.path.dirname(__file__)
def get_runtime_folder():
return os.path.join(get_app_folder(), 'runtime_folder')
def get_runtime_stream_folder():
return os.path.join(get_runtime_folder(), 'stream')
def init_project(static_folder, *args):
runtime_folder = get_runtime_folder()
if not os.path.exists(runtime_folder):
os.mkdir(runtime_folder)
runtime_stream_folder = get_runtime_stream_folder()
if not os.path.exists(runtime_stream_folder):
os.mkdir(runtime_stream_folder)
app = Flask(__name__, static_folder=static_folder)
for file in args:
app.config.from_pyfile(file, silent=False)
app.wsgi_app = ProxyFix(app.wsgi_app)
bootstrap = Bootstrap(app)
babel = Babel(app)
db = MongoEngine(app)
mail = Mail(app)
socketio = SocketIO(app)
login_manager = LoginManager(app)
login_manager.login_view = "HomeView:signin"
# socketio
@socketio.on('connect')
def connect():
pass
@socketio.on('disconnect')
def disconnect():
pass
# defaults flask
_host = '0.0.0.0'
_port = 8080
server_name = app.config.get('SERVER_NAME_FOR_POST')
sn_host, sn_port = None, None
if server_name:
sn_host, _, sn_port = server_name.partition(':')
host = sn_host or _host
port = int(sn_port or _port)
support_subscribers = app.config.get('SUBSCRIBERS_SUPPORT')
servers_manager = SubscribersServiceManager(host, port, socketio) if support_subscribers else ServiceManager(host,
port,
socketio)
return app, bootstrap, babel, db, mail, login_manager, servers_manager
app, bootstrap, babel, db, mail, login_manager, servers_manager = init_project(
'static',
'config/public_config.py',
'config/config.py',
'config/db_config.py',
'config/mail_config.py'
)
from app.home.view import HomeView
from app.provider.view import ProviderView
from app.stream.view import StreamView
from app.service.view import ServiceView
HomeView.register(app)
ProviderView.register(app)
StreamView.register(app)
ServiceView.register(app)

View file

@ -0,0 +1,42 @@
#!/usr/bin/env python3
import os
import sys
import json
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'
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()

View 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.subscriber.login.entry import SubscriberUser
from app.common.subscriber.entry import Device
from app.service.service import ServiceSettings
PROJECT_NAME = 'import_subscribers_from_xtream'
def import_subscribers_to_server(db, server):
cursor = db.cursor(dictionary=True)
sql = 'SELECT username,password,created_at,exp_date FROM users'
cursor.execute(sql)
sql_subscribers = cursor.fetchall()
for sql_entry in sql_subscribers:
new_user = SubscriberUser.make_subscriber(email=sql_entry['username'], password=sql_entry['password'],
country='US')
new_user.status = SubscriberUser.Status.ACTIVE
created_at = sql_entry['created_at']
if created_at:
new_user.created_date = datetime.fromtimestamp(created_at)
exp_date = sql_entry['exp_date']
if exp_date:
new_user.exp_date = datetime.fromtimestamp(exp_date)
dev = Device(name='Xtream')
new_user.add_device(dev)
# save
new_user.add_server(server)
server.add_subscriber(new_user)
cursor.close()
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='root')
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)
ser = ServiceSettings.objects(id=server_id).first()
if not ser:
sys.exit(1)
d = mysql.connector.connect(
host=mysql_host,
port=mysql_port,
user=mysql_user,
passwd=mysql_password,
database='xtream_iptvpro'
)
import_subscribers_to_server(d, ser)
d.close()