示例#1
0
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[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()
示例#2
0
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()
示例#3
0
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:
        new_user = ProviderUser.make_provider(email=sql_entry['email'],
                                              password=sql_entry['email'],
                                              country='US')
        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()
    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()
示例#5
0
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from app.stream.stream_entry import make_test_life_stream
from app.service.service import ServiceSettings
from app.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 = make_test_life_stream(service_settings.feedback_directory)
            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()