Beispiel #1
0
 def disconnect(self):
     server = current_user.get_current_server()
     if server:
         server.disconnect()
     return redirect(url_for('ProviderView:dashboard'))
Beispiel #2
0
 def stop(self):
     server = current_user.get_current_server()
     if server:
         server.stop(1)
     return redirect(url_for('ProviderView:dashboard'))
Beispiel #3
0
 def get_log(self):
     server = current_user.get_current_server()
     if server:
         server.get_log_service()
     return redirect(url_for('ProviderView:dashboard'))
Beispiel #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 = []
                default_logo_path = self.default_logo_url()
                for file in m3u_parser.files:
                    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()

                    input_url = file['link']
                    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

                    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'))
Beispiel #5
0
    def edit(self, sid):
        server = current_user.get_current_server()
        if server:
            stream = server.find_stream_by_id(sid)
            if stream:
                type = stream.get_type()
                if type == constants.StreamType.PROXY:
                    form = ProxyStreamForm(obj=stream)

                    if request.method == 'POST' and form.validate_on_submit():
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template('stream/proxy/edit.html', form=form)
                elif type == constants.StreamType.RELAY:
                    form = RelayStreamForm(obj=stream)

                    if request.method == 'POST' and form.validate_on_submit():
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/relay/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir())
                elif type == constants.StreamType.ENCODE:
                    form = EncodeStreamForm(obj=stream)

                    if request.method == 'POST' and form.validate_on_submit():
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/encode/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir())
                elif type == constants.StreamType.TIMESHIFT_RECORDER:
                    form = TimeshiftRecorderStreamForm(obj=stream)

                    if request.method == 'POST':  # FIXME form.validate_on_submit()
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/timeshift_recorder/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir(),
                        timeshift_dir=stream.generate_timeshift_dir())
                elif type == constants.StreamType.CATCHUP:
                    form = CatchupStreamForm(obj=stream)

                    if request.method == 'POST':  # FIXME form.validate_on_submit()
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/catchup/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir(),
                        timeshift_dir=stream.generate_timeshift_dir())
                elif type == constants.StreamType.TIMESHIFT_PLAYER:
                    form = TimeshiftPlayerStreamForm(obj=stream)

                    if request.method == 'POST' and form.validate_on_submit():
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/timeshift_player/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir())
                elif type == constants.StreamType.TEST_LIFE:
                    form = TestLifeStreamForm(obj=stream)

                    if request.method == 'POST':  # FIXME form.validate_on_submit()
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/test_life/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir())
                elif type == constants.StreamType.VOD_RELAY:
                    form = VodRelayStreamForm(obj=stream)

                    if request.method == 'POST' and form.validate_on_submit():
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/vod_relay/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir())
                elif type == constants.StreamType.VOD_ENCODE:
                    form = VodEncodeStreamForm(obj=stream)

                    if request.method == 'POST' and form.validate_on_submit():
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/vod_encode/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir())
                elif type == constants.StreamType.COD_RELAY:
                    form = CodRelayStreamForm(obj=stream)

                    if request.method == 'POST' and form.validate_on_submit():
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/cod_relay/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir())
                elif type == constants.StreamType.COD_ENCODE:
                    form = CodEncodeStreamForm(obj=stream)

                    if request.method == 'POST' and form.validate_on_submit():
                        stream = form.update_entry(stream)
                        server.update_stream(stream)
                        return jsonify(status='ok'), 200

                    return render_template(
                        'stream/cod_encode/edit.html',
                        form=form,
                        feedback_dir=stream.generate_feedback_dir())

        return jsonify(status='failed'), 404
Beispiel #6
0
 def start_all_streams(self):
     server = current_user.get_current_server()
     if server:
         server.start_all_streams()
         return jsonify(status='ok'), 200
     return jsonify(status='failed'), 404
Beispiel #7
0
 def view_playlist(self):
     server = current_user.get_current_server()
     if server:
         return '<pre>{0}</pre>'.format(server.view_playlist())
     return '''<pre>Not found, please create server firstly.</pre>'''
Beispiel #8
0
 def ping(self):
     server = current_user.get_current_server()
     if server:
         server.ping()
     return redirect(url_for('UserView:dashboard'))
Beispiel #9
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()
                read = file.read()
                data = read.decode(encoding='utf-8', errors='ignore')
                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(server.settings)
                        server.add_stream(stream)

        return redirect(url_for('ProviderView:dashboard'))