Example #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()
Example #2
0
    def add_own_proxy_stream(self):
        stream = ProxyStream.make_stream(None)
        form = ProxyStreamForm(obj=stream)
        form.price.validators = []
        if request.method == 'POST' and form.validate_on_submit():
            new_entry = form.make_entry()
            new_entry.save()
            current_user.add_own_stream(new_entry)
            return jsonify(status='ok'), 200

        return render_template('stream/proxy/add.html', form=form)
Example #3
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'))
Example #4
0
 def make_stream(cls, settings):
     proxy = ProxyStream(name=IStreamObject.DEFAULT_STREAM_NAME)
     proxy.output = [OutputUrl.make_stub()]
     IStreamObject.fill_defaults(proxy)
     return cls(proxy, settings)
Example #5
0
 def make_proxy_stream(self) -> ProxyStream:
     return ProxyStream.make_stream(self._settings)
Example #6
0
 def make_entry(self):
     return self.update_entry(ProxyStream())
Example #7
0
 def make_stream(cls, settings):
     proxy = ProxyStream()
     proxy.output = [OutputUrl(id=OutputUrl.generate_id())]
     return cls(proxy, settings)
Example #8
0
 def make_stream(cls, settings):
     proxy = ProxyStream(name=IStreamObject.DEFAULT_STREAM_NAME)
     proxy.output = [OutputUrl(id=OutputUrl.generate_id())]
     return cls(proxy, settings)