Exemplo n.º 1
0
    def upload_file(self):
        form = UploadM3uForm()
        server = current_user.get_current_server()
        if server and form.validate_on_submit():
            stream_type = form.type.data
            file_handle = form.file.data
            m3u_parser = M3uParser()
            m3u_parser.load_content(file_handle.read().decode('utf-8'))
            m3u_parser.parse()

            for file in m3u_parser.files:
                if stream_type == constants.StreamType.PROXY:
                    stream = server.make_proxy_stream()
                elif stream_type == constants.StreamType.RELAY:
                    stream = server.make_relay_stream()
                    stream.output.urls[0] = stream.generate_http_link()
                elif stream_type == constants.StreamType.ENCODE:
                    stream = server.make_encode_stream()
                    stream.output.urls[0] = stream.generate_http_link()
                elif stream_type == constants.StreamType.VOD_RELAY:
                    stream = server.make_vod_relay_stream()
                    stream.output.urls[0] = stream.generate_vod_link()
                elif stream_type == constants.StreamType.VOD_ENCODE:
                    stream = server.make_vod_encode_stream()
                    stream.output.urls[0] = stream.generate_vod_link()
                elif stream_type == constants.StreamType.CATCHUP:
                    stream = server.make_catchup_stream()
                else:
                    stream = server.make_test_life_stream()

                input_url = file['link']
                if stream_type == constants.StreamType.PROXY:
                    stream.output.urls[0].uri = input_url
                else:
                    stream.input.urls[0].uri = input_url

                if file['title'] and len(
                        file['title']) < constants.MAX_STREAM_NAME_LENGTH:
                    stream.name = file['title']
                if file['tvg-id'] and len(
                        file['tvg-id']) < constants.MAX_STREAM_TVG_ID_LENGTH:
                    stream.tvg_id = file['tvg-id']
                if file['tvg-name'] and len(
                        file['tvg-name']) < constants.MAX_STREAM_NAME_LENGTH:
                    stream.tvg_name = file['tvg-name']
                if file['tvg-group'] and len(
                        file['tvg-group']
                ) < constants.MAX_STREAM_GROUP_TITLE_LENGTH:
                    stream.group_title = file['tvg-group']
                if file['tvg-logo'] and len(
                        file['tvg-logo']) < constants.MAX_URL_LENGTH:
                    logo_url = file['tvg-logo']
                    if is_valid_http_url(logo_url):
                        stream.tvg_logo = logo_url
                stream.save()
                server.add_stream(stream)

        return redirect(url_for('ProviderView:dashboard'))
Exemplo n.º 2
0
from mongoengine import connect

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from app.common.stream.entry import TestLifeStream
from app.service.service import ServiceSettings
from app.common.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()