示例#1
0
    def upload_files(self):
        form = UploadM3uForm()
        if form.validate_on_submit():
            files = request.files.getlist("files")
            for file in files:
                m3u_parser = M3uParser()
                data = file.read().decode('utf-8')
                m3u_parser.load_content(data)
                m3u_parser.parse()

                for entry in m3u_parser.files:
                    title = entry['title']
                    if len(title) > constants.MAX_STREAM_NAME_LENGTH:
                        continue

                    line = _get_m3u_vod_by_name(title)
                    if not line:
                        line = M3uParseVods(name=title)

                    tvg_group = entry['tvg-group']
                    if len(tvg_group) and len(
                            tvg_group
                    ) < constants.MAX_STREAM_GROUP_TITLE_LENGTH:
                        line.group.append(tvg_group)

                    tvg_logo = entry['tvg-logo']
                    if len(tvg_logo
                           ) and len(tvg_logo) < constants.MAX_URL_LENGTH:
                        if is_valid_http_url(tvg_logo, timeout=0.1):
                            line.tvg_logo.append(tvg_logo)

                    line.save()

        return redirect(url_for('M3uParseVodsView:show'))
示例#2
0
    def upload_files(self):
        form = UploadM3uForm()
        if form.validate_on_submit():
            files = request.files.getlist("files")
            for file in files:
                m3u_parser = M3uParser()
                m3u_parser.load_content(file.read().decode('utf-8'))
                m3u_parser.parse()

                default_logo_path = constants.DEFAULT_STREAM_PREVIEW_ICON_URL
                for file in m3u_parser.files:
                    if form.type.data == constants.StreamType.PROXY:
                        stream = ProxyStream.make_stream(None)
                    else:
                        stream = ProxyVodStream.make_stream(None)

                    input_url = file['link']
                    stream.output.urls[0].uri = input_url

                    stream.tvg_logo = default_logo_path

                    title = file['title']
                    if len(title) < constants.MAX_STREAM_NAME_LENGTH:
                        stream.name = title

                    tvg_id = file['tvg-id']
                    if len(tvg_id) < constants.MAX_STREAM_TVG_ID_LENGTH:
                        stream.tvg_id = tvg_id

                    tvg_name = file['tvg-name']
                    if len(tvg_name) < constants.MAX_STREAM_NAME_LENGTH:
                        stream.tvg_name = tvg_name

                    tvg_group = file['tvg-group']
                    if len(tvg_group
                           ) < constants.MAX_STREAM_GROUP_TITLE_LENGTH:
                        stream.group = tvg_group

                    tvg_logo = file['tvg-logo']
                    if len(tvg_logo) < constants.MAX_URL_LENGTH:
                        if is_valid_http_url(tvg_logo, timeout=0.1):
                            stream.tvg_logo = tvg_logo
                    stream.save()
                    current_user.add_own_stream(stream)

        return redirect(url_for('SubscriberView:my_channels'))
示例#3
0
    def upload_files(self):
        form = UploadM3uForm()
        server = current_user.get_current_server()
        if server and form.validate_on_submit():
            stream_type = form.type.data
            files = request.files.getlist("files")
            for file in files:
                m3u_parser = M3uParser()
                m3u_parser.load_content(file.read().decode('utf-8'))
                m3u_parser.parse()

                streams = []
                default_logo_path = self.default_logo_url()
                for file in m3u_parser.files:
                    if stream_type == constants.StreamType.PROXY:
                        stream = server.make_proxy_stream()
                    elif stream_type == constants.StreamType.VOD_PROXY:
                        stream = server.make_proxy_vod()
                    elif stream_type == constants.StreamType.RELAY:
                        stream = server.make_relay_stream()
                        stream.output.urls[0] = stream.generate_http_link(
                            constants.HlsType.HLS_PULL)
                    elif stream_type == constants.StreamType.ENCODE:
                        stream = server.make_encode_stream()
                        stream.output.urls[0] = stream.generate_http_link(
                            constants.HlsType.HLS_PULL)
                    elif stream_type == constants.StreamType.VOD_RELAY:
                        stream = server.make_vod_relay_stream()
                        stream.output.urls[0] = stream.generate_vod_link(
                            constants.HlsType.HLS_PULL)
                    elif stream_type == constants.StreamType.VOD_ENCODE:
                        stream = server.make_vod_encode_stream()
                        stream.output.urls[0] = stream.generate_vod_link(
                            constants.HlsType.HLS_PULL)
                    elif stream_type == constants.StreamType.COD_RELAY:
                        stream = server.make_cod_relay_stream()
                        stream.output.urls[0] = stream.generate_cod_link(
                            constants.HlsType.HLS_PULL)
                    elif stream_type == constants.StreamType.COD_ENCODE:
                        stream = server.make_cod_encode_stream()
                        stream.output.urls[0] = stream.generate_cod_link(
                            constants.HlsType.HLS_PULL)
                    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 or stream_type == constants.StreamType.VOD_PROXY:
                        stream.output.urls[0].uri = input_url
                    else:
                        stream.input.urls[0].uri = input_url

                    stream.tvg_logo = default_logo_path

                    title = file['title']
                    if len(title) < constants.MAX_STREAM_NAME_LENGTH:
                        stream.name = title

                    tvg_id = file['tvg-id']
                    if len(tvg_id) < constants.MAX_STREAM_TVG_ID_LENGTH:
                        stream.tvg_id = tvg_id

                    tvg_name = file['tvg-name']
                    if len(tvg_name) < constants.MAX_STREAM_NAME_LENGTH:
                        stream.tvg_name = tvg_name

                    tvg_group = file['tvg-group']
                    if len(tvg_group
                           ) < constants.MAX_STREAM_GROUP_TITLE_LENGTH:
                        stream.group = tvg_group

                    tvg_logo = file['tvg-logo']
                    if len(tvg_logo) < constants.MAX_URL_LENGTH:
                        if is_valid_http_url(tvg_logo, timeout=0.1):
                            stream.tvg_logo = tvg_logo

                    stream.save()
                    streams.append(stream)

                server.add_streams(streams)

        return redirect(url_for('ProviderView:dashboard'))
示例#4
0
    def upload_files(self):
        form = UploadM3uForm()
        server = current_user.get_current_server()
        if server and form.validate_on_submit():
            stream_type = form.type.data
            files = request.files.getlist("files")
            for file in files:
                m3u_parser = M3uParser()
                data = file.read().decode('utf-8')
                m3u_parser.load_content(data)
                m3u_parser.parse()

                streams = []
                for mfile in m3u_parser.files:
                    input_url = mfile['link']
                    if not is_valid_url(input_url):
                        logging.warning('Skipped invalid url: %s', input_url)
                        continue

                    if stream_type == constants.StreamType.PROXY:
                        stream_object = server.make_proxy_stream()
                        stream = stream_object.stream()
                    elif stream_type == constants.StreamType.VOD_PROXY:
                        stream_object = server.make_proxy_vod()
                        stream = stream_object.stream()
                    elif stream_type == constants.StreamType.RELAY:
                        stream_object = server.make_relay_stream()
                        stream = stream_object.stream()
                        sid = stream.output[0].id
                        stream.output = [stream_object.generate_http_link(constants.HlsType.HLS_PULL, oid=sid)]
                    elif stream_type == constants.StreamType.ENCODE:
                        stream_object = server.make_encode_stream()
                        stream = stream_object.stream()
                        sid = stream.output[0].id
                        stream.output = [stream_object.generate_http_link(constants.HlsType.HLS_PULL, oid=sid)]
                    elif stream_type == constants.StreamType.VOD_RELAY:
                        stream_object = server.make_vod_relay_stream()
                        stream = stream_object.stream()
                        sid = stream.output[0].id
                        stream.output = [stream_object.generate_vod_link(constants.HlsType.HLS_PULL, oid=sid)]
                    elif stream_type == constants.StreamType.VOD_ENCODE:
                        stream_object = server.make_vod_encode_stream()
                        stream = stream_object.stream()
                        sid = stream.output[0].id
                        stream.output = [stream_object.generate_vod_link(constants.HlsType.HLS_PULL, oid=sid)]
                    elif stream_type == constants.StreamType.COD_RELAY:
                        stream_object = server.make_cod_relay_stream()
                        stream = stream_object.stream()
                        sid = stream.output[0].id
                        stream.output = [stream_object.generate_cod_link(constants.HlsType.HLS_PULL, oid=sid)]
                    elif stream_type == constants.StreamType.COD_ENCODE:
                        stream_object = server.make_cod_encode_stream()
                        stream = stream_object.stream()
                        sid = stream.output[0].id
                        stream.output = [stream_object.generate_cod_link(constants.HlsType.HLS_PULL, oid=sid)]
                    elif stream_type == constants.StreamType.CATCHUP:
                        stream_object = server.make_catchup_stream()
                        stream = stream_object.stream()
                    else:
                        stream_object = server.make_test_life_stream()
                        stream = stream_object.stream()

                    if stream_type == constants.StreamType.PROXY or stream_type == constants.StreamType.VOD_PROXY:
                        stream.output[0].uri = input_url
                    else:
                        stream.input[0].uri = input_url

                    title = mfile['title']
                    if len(title) < constants.MAX_STREAM_NAME_LENGTH:
                        stream.name = title

                    tvg_id = mfile['tvg-id']
                    if tvg_id and len(tvg_id) < constants.MAX_STREAM_TVG_ID_LENGTH:
                        stream.tvg_id = tvg_id

                    tvg_name = mfile['tvg-name']
                    if tvg_name and len(tvg_name) < constants.MAX_STREAM_NAME_LENGTH:
                        stream.tvg_name = tvg_name

                    tvg_group = mfile['tvg-group']
                    if tvg_group:
                        stream.groups = [tvg_group]

                    tvg_logo = mfile['tvg-logo']
                    if tvg_logo and len(tvg_logo) < constants.MAX_URI_LENGTH:
                        if is_valid_http_url(tvg_logo, timeout=0.05):
                            stream.tvg_logo = tvg_logo

                    is_valid_stream = stream.is_valid()
                    if is_valid_stream:
                        stream.save()
                        streams.append(stream)

                server.add_streams(streams)

        return redirect(url_for('ProviderView:dashboard'))
示例#5
0
def _get_server_by_id(sid: str):
    try:
        server = ServiceSettings.objects.get({'_id': ObjectId(sid)})
    except ServiceSettings.DoesNotExist:
        return None
    else:
        return server


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.get({})
        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[0].uri = file['link']
            stream.name = '{0}({1})'.format(file['tvg-group'], file['title'])
            service_settings.streams.append(stream)

        service_settings.save()