mirror of
https://github.com/fastogt/fastocloud_admin.git
synced 2025-03-09 23:38:52 +00:00
Init sources
This commit is contained in:
commit
92648275c3
156 changed files with 18906 additions and 0 deletions
33
scripts/create_provider.py
Executable file
33
scripts/create_provider.py
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from mongoengine import connect
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from app.home.entry import ProviderAdminUser
|
||||
|
||||
PROJECT_NAME = 'create_provider'
|
||||
|
||||
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('--email', help='Provider email')
|
||||
parser.add_argument('--password', help='Provider password')
|
||||
parser.add_argument('--country', help='Provider country', default='US')
|
||||
parser.add_argument('--language', help='Provider language', default='en')
|
||||
|
||||
argv = parser.parse_args()
|
||||
email = argv.email
|
||||
password = argv.password
|
||||
|
||||
mongo = connect(host=argv.mongo_uri)
|
||||
if not mongo:
|
||||
sys.exit(1)
|
||||
|
||||
new_user = ProviderAdminUser.make_provider(email=email.lower(), password=password, country=argv.country,
|
||||
language=argv.language)
|
||||
new_user.status = ProviderAdminUser.Status.ACTIVE
|
||||
new_user.save()
|
||||
print('Successfully created provider email: {0}, password: {1}'.format(email, password))
|
||||
52
scripts/import_from_xtream.py
Executable file
52
scripts/import_from_xtream.py
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from mongoengine import connect
|
||||
import mysql.connector
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from app.service.service import ServiceSettings
|
||||
from scripts.migrate.xtream.subscribers import import_subscribers_to_server
|
||||
from scripts.migrate.xtream.streams import import_streams_to_server
|
||||
from scripts.migrate.xtream.resellers import import_resellers_to_server
|
||||
|
||||
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='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
|
||||
|
||||
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'
|
||||
)
|
||||
|
||||
import_streams_to_server(db, server)
|
||||
import_subscribers_to_server(db, server)
|
||||
import_resellers_to_server(db, server)
|
||||
db.close()
|
||||
48
scripts/import_resellers_from_xtream.py
Executable file
48
scripts/import_resellers_from_xtream.py
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from mongoengine import connect
|
||||
import mysql.connector
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from app.service.service import ServiceSettings
|
||||
from scripts.migrate.xtream.resellers import import_resellers_to_server
|
||||
|
||||
PROJECT_NAME = 'import_resellers_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='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
|
||||
|
||||
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_resellers_to_server(d, ser)
|
||||
d.close()
|
||||
48
scripts/import_streams_from_xtream.py
Executable file
48
scripts/import_streams_from_xtream.py
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from mongoengine import connect
|
||||
import mysql.connector
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from app.service.service import ServiceSettings
|
||||
from scripts.migrate.xtream.streams import import_streams_to_server
|
||||
|
||||
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='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
|
||||
|
||||
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_streams_to_server(d, ser)
|
||||
d.close()
|
||||
49
scripts/import_subscribers_from_xtream.py
Executable file
49
scripts/import_subscribers_from_xtream.py
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from mongoengine import connect
|
||||
import mysql.connector
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from app.service.service import ServiceSettings
|
||||
|
||||
PROJECT_NAME = 'import_subscribers_from_xtream'
|
||||
|
||||
from scripts.migrate.xtream.subscribers import import_subscribers_to_server
|
||||
|
||||
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
|
||||
|
||||
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()
|
||||
0
scripts/migrate/__init__.py
Normal file
0
scripts/migrate/__init__.py
Normal file
22
scripts/migrate/xtream/resellers.py
Executable file
22
scripts/migrate/xtream/resellers.py
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
from app.home.entry import ProviderUser
|
||||
from app.service.service import ServiceSettings, ProviderPair
|
||||
|
||||
|
||||
def import_resellers_to_server(db, server: ServiceSettings):
|
||||
cursor = db.cursor(dictionary=True)
|
||||
sql = 'SELECT username,email,password from reg_users'
|
||||
cursor.execute(sql)
|
||||
sql_providers = cursor.fetchall()
|
||||
|
||||
for sql_entry in sql_providers:
|
||||
email = sql_entry['email']
|
||||
password = sql_entry['email']
|
||||
new_user = ProviderUser.make_provider(email=email, password=password, country='US', language='en')
|
||||
new_user.status = ProviderUser.Status.ACTIVE
|
||||
new_user.save()
|
||||
|
||||
admin = ProviderPair(new_user.id, ProviderPair.Roles.ADMIN)
|
||||
server.add_provider(admin)
|
||||
new_user.add_server(server)
|
||||
|
||||
cursor.close()
|
||||
35
scripts/migrate/xtream/streams.py
Executable file
35
scripts/migrate/xtream/streams.py
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
import json
|
||||
|
||||
from pyfastocloud_models.stream.entry import ProxyStream
|
||||
from app.service.service import ServiceSettings
|
||||
from pyfastocloud_models.utils.utils import is_valid_http_url
|
||||
import pyfastocloud_models.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()
|
||||
31
scripts/migrate/xtream/subscribers.py
Executable file
31
scripts/migrate/xtream/subscribers.py
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
from datetime import datetime
|
||||
|
||||
from pyfastocloud_models.subscriber.entry import Subscriber
|
||||
from pyfastocloud_models.subscriber.entry import Device
|
||||
from app.service.service import ServiceSettings
|
||||
|
||||
|
||||
def import_subscribers_to_server(db, server: ServiceSettings):
|
||||
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 = Subscriber.make_subscriber(email=sql_entry['username'], first_name=sql_entry['username'],
|
||||
last_name=sql_entry['username'], password=sql_entry['password'],
|
||||
country='US', language='US')
|
||||
new_user.status = Subscriber.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()
|
||||
25
scripts/parse_json_out.py
Normal file
25
scripts/parse_json_out.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
import json
|
||||
|
||||
if __name__ == '__main__':
|
||||
f = open("out.m3u", "w")
|
||||
f.write('#EXTM3U\n')
|
||||
with open('test.json') as json_file:
|
||||
data = json.load(json_file)
|
||||
idx = 0
|
||||
for p in data:
|
||||
name = p['name']
|
||||
icon = p['icon']
|
||||
group = p['group']
|
||||
sid = p['input']['urls'][0]['id']
|
||||
input = p['input']['urls'][0]['uri']
|
||||
f.write('#EXTINF:{0} tvg-id="{1}" tvg-name="" tvg-logo="{3}" group-title="{4}",{2}\n{5}\n'.format(
|
||||
idx,
|
||||
sid,
|
||||
name,
|
||||
icon,
|
||||
group,
|
||||
input))
|
||||
idx += 1
|
||||
|
||||
f.close()
|
||||
27
scripts/parse_streams_collection.py
Executable file
27
scripts/parse_streams_collection.py
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from mongoengine import connect
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
PROJECT_NAME = 'parse_streams_collection'
|
||||
|
||||
from pyfastocloud_models.stream.entry import IStream
|
||||
|
||||
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')
|
||||
|
||||
argv = parser.parse_args()
|
||||
|
||||
mongo = connect(host=argv.mongo_uri)
|
||||
if mongo:
|
||||
streams = IStream.objects()
|
||||
f = open("out.m3u", "w")
|
||||
f.write('#EXTM3U\n')
|
||||
idx = 0
|
||||
for stream in streams:
|
||||
f.write(stream.generate_input_playlist(False))
|
||||
f.close()
|
||||
34
scripts/test_life.py
Executable file
34
scripts/test_life.py
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from mongoengine import connect
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from pyfastocloud_models.stream.entry import TestLifeStream
|
||||
from pyfastocloud_models.service.entry import ServiceSettings
|
||||
from pyfastocloud_models.utils.m3u_parser import M3uParser
|
||||
|
||||
PROJECT_NAME = 'test_life'
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(prog=PROJECT_NAME, usage='%(prog)s [options]')
|
||||
parser.add_argument('uri', help='Uri to m3u8 list')
|
||||
parser.add_argument('mongo_uri', help='MongoDB credentials')
|
||||
|
||||
argv = parser.parse_args()
|
||||
|
||||
mongo = connect(argv.mongo_uri)
|
||||
if mongo:
|
||||
service_settings = ServiceSettings.objects().first()
|
||||
m3u_parser = M3uParser()
|
||||
m3u_parser.read_m3u(argv.uri)
|
||||
m3u_parser.parse()
|
||||
for file in m3u_parser.files:
|
||||
stream = TestLifeStream.make_stream(service_settings)
|
||||
stream.input.urls[0].uri = file['link']
|
||||
stream.name = '{0}({1})'.format(file['tvg-group'], file['title'])
|
||||
service_settings.streams.append(stream)
|
||||
|
||||
service_settings.save()
|
||||
Loading…
Add table
Add a link
Reference in a new issue