diff --git a/app/__init__.py b/app/__init__.py index e8f3e30..db58b07 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -96,7 +96,7 @@ from app.provider.view import ProviderView from app.stream.view import StreamView from app.service.view import ServiceView from app.subscriber.view import SubscriberView -from app.autofill.view import M3uParseView +from app.autofill.view import M3uParseStreamsView from app.epg.view import EpgView HomeView.register(app) @@ -104,5 +104,5 @@ ProviderView.register(app) StreamView.register(app) ServiceView.register(app) SubscriberView.register(app) -M3uParseView.register(app) +M3uParseStreamsView.register(app) EpgView.register(app) diff --git a/app/autofill/entry.py b/app/autofill/entry.py index 170c419..2aa3c2c 100644 --- a/app/autofill/entry.py +++ b/app/autofill/entry.py @@ -3,13 +3,20 @@ from mongoengine import Document, StringField, ListField import pyfastocloud_models.constants as constants -class M3uParse(Document): - NAME_FIELD = 'name' - - meta = {'allow_inheritance': False, 'collection': 'm3uparse', 'auto_create_index': False} +class M3uParseStreams(Document): + meta = {'allow_inheritance': False, 'collection': 'm3uparse_streams', 'auto_create_index': False} name = StringField(unique=True, max_length=constants.MAX_STREAM_NAME_LENGTH, min_length=constants.MIN_STREAM_NAME_LENGTH, required=True) tvg_id = ListField(StringField(unique=True), default=[]) tvg_logo = ListField(StringField(unique=True), default=[]) group = ListField(StringField(unique=True), default=[]) + + +class M3uParseVods(Document): + meta = {'allow_inheritance': False, 'collection': 'm3uparse_vods', 'auto_create_index': False} + name = StringField(unique=True, max_length=constants.MAX_STREAM_NAME_LENGTH, + min_length=constants.MIN_STREAM_NAME_LENGTH, + required=True) + tvg_logo = ListField(StringField(unique=True), default=[]) + group = ListField(StringField(unique=True), default=[]) diff --git a/app/autofill/view.py b/app/autofill/view.py index f9ad59a..f8e4a28 100644 --- a/app/autofill/view.py +++ b/app/autofill/view.py @@ -5,27 +5,27 @@ from flask_login import login_required from pyfastocloud_models.utils.m3u_parser import M3uParser from app.common.service.forms import UploadM3uForm import pyfastocloud_models.constants as constants -from app.autofill.entry import M3uParse +from app.autofill.entry import M3uParseStreams, M3uParseVods from pyfastocloud_models.utils.utils import is_valid_http_url # routes -class M3uParseView(FlaskView): - route_base = '/m3uparse/' +class M3uParseStreamsView(FlaskView): + route_base = '/m3uparse_streams/' @login_required def show(self): - m3u = M3uParse.objects() - return render_template('autofill/show.html', m3u=m3u) + m3u = M3uParseStreams.objects() + return render_template('autofill/show_streams.html', m3u=m3u) @login_required def show_anonim(self): - m3u = M3uParse.objects() - return render_template('autofill/show_anonim.html', m3u=m3u) + m3u = M3uParseStreams.objects() + return render_template('autofill/show_streams_anonim.html', m3u=m3u) @route('/search/', methods=['GET']) def search(self, sid): - lines = M3uParse.objects(id=sid) + lines = M3uParseStreams.objects(id=sid) line = lines.first() if line: return jsonify(status='ok', line=line), 200 @@ -49,9 +49,9 @@ class M3uParseView(FlaskView): if len(title) > constants.MAX_STREAM_NAME_LENGTH: continue - line = M3uParse.objects(name=title).first() + line = M3uParseStreams.objects(name=title).first() if not line: - line = M3uParse(name=title) + line = M3uParseStreams(name=title) tvg_id = file['tvg-id'] if len(tvg_id) and len(tvg_id) < constants.MAX_STREAM_TVG_ID_LENGTH: @@ -68,10 +68,74 @@ class M3uParseView(FlaskView): line.save() - return redirect(url_for('M3uParseView:show')) + return redirect(url_for('M3uParseStreamsView:show')) @login_required @route('/upload_m3u', methods=['POST', 'GET']) def upload_m3u(self): form = UploadM3uForm() - return render_template('autofill/upload_m3u.html', form=form) + return render_template('autofill/upload_m3u_streams.html', form=form) + + +# routes +class M3uParseVodsView(FlaskView): + route_base = '/m3uparse_vods/' + + @login_required + def show(self): + m3u = M3uParseVods.objects() + return render_template('autofill/show_vods.html', m3u=m3u) + + @login_required + def show_anonim(self): + m3u = M3uParseVods.objects() + return render_template('autofill/show_vods_anonim.html', m3u=m3u) + + @route('/search/', methods=['GET']) + def search(self, sid): + lines = M3uParseVods.objects(id=sid) + line = lines.first() + if line: + return jsonify(status='ok', line=line), 200 + + return jsonify(status='failed', error='Not found'), 404 + + @route('/upload_files', methods=['POST']) + @login_required + 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 file in m3u_parser.files: + title = file['title'] + if len(title) > constants.MAX_STREAM_NAME_LENGTH: + continue + + line = M3uParseVods.objects(name=title).first() + if not line: + line = M3uParseVods(name=title) + + tvg_group = file['tvg-group'] + if len(tvg_group) and len(tvg_group) < constants.MAX_STREAM_GROUP_TITLE_LENGTH: + line.group.append(tvg_group) + + tvg_logo = file['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')) + + @login_required + @route('/upload_m3u', methods=['POST', 'GET']) + def upload_m3u(self): + form = UploadM3uForm() + return render_template('autofill/upload_m3u_vods.html', form=form) diff --git a/app/templates/autofill/show.html b/app/templates/autofill/show_streams.html similarity index 92% rename from app/templates/autofill/show.html rename to app/templates/autofill/show_streams.html index fe677d1..739c772 100644 --- a/app/templates/autofill/show.html +++ b/app/templates/autofill/show_streams.html @@ -66,7 +66,7 @@ M3U | {{ config['PUBLIC_CONFIG'].site.title }} {{ loop.index }} {{ line.name }} - Show @@ -79,7 +79,7 @@ M3U | {{ config['PUBLIC_CONFIG'].site.title }}
diff --git a/app/templates/autofill/show_anonim.html b/app/templates/autofill/show_streams_anonim.html similarity index 94% rename from app/templates/autofill/show_anonim.html rename to app/templates/autofill/show_streams_anonim.html index bf7f64b..74b879e 100644 --- a/app/templates/autofill/show_anonim.html +++ b/app/templates/autofill/show_streams_anonim.html @@ -49,7 +49,7 @@ M3U | {{ config['PUBLIC_CONFIG'].site.title }} {{ loop.index }} {{ line.name }} - Show diff --git a/app/templates/autofill/upload_m3u_streams.html b/app/templates/autofill/upload_m3u_streams.html new file mode 100644 index 0000000..37547f8 --- /dev/null +++ b/app/templates/autofill/upload_m3u_streams.html @@ -0,0 +1,45 @@ +{% extends 'layouts/layout_home.html' %} +{% block title %} +Upload m3u | {{ config['PUBLIC_CONFIG'].site.title }} +{% endblock %} + + +{% block content %} +
+
+

+ +
Version: {{ config['PUBLIC_CONFIG'].project.version }}
+

+
+
+
+
+

Upload m3u files

+

Note: Please upload m3u files for service.

+ {{ util.flashed_messages(dismissible=True, container=False) }} +
+ {{ form.hidden_tag() }} +
+ {{ form.files }} +
+
+ Type: {{ form.type }} +
+
+ {{ form_field(form.upload, class="btn btn-success") }} +
+
+
+ +
+
+
+{%- endblock %} \ No newline at end of file diff --git a/app/templates/autofill/upload_m3u.html b/app/templates/autofill/upload_m3u_vods.html similarity index 92% rename from app/templates/autofill/upload_m3u.html rename to app/templates/autofill/upload_m3u_vods.html index 2e2e08b..1b1719d 100644 --- a/app/templates/autofill/upload_m3u.html +++ b/app/templates/autofill/upload_m3u_vods.html @@ -20,7 +20,7 @@ Upload m3u | {{ config['PUBLIC_CONFIG'].site.title }}

Upload m3u files

Note: Please upload m3u files for service.

{{ util.flashed_messages(dismissible=True, container=False) }} -
{{ form.hidden_tag() }}
diff --git a/app/templates/index.html b/app/templates/index.html index 8554d7a..9d5a7db 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -13,14 +13,17 @@
-
+ -
+ -
diff --git a/app/templates/provider/dashboard.html b/app/templates/provider/dashboard.html index f8ef94e..2b3d138 100644 --- a/app/templates/provider/dashboard.html +++ b/app/templates/provider/dashboard.html @@ -70,7 +70,7 @@ Dashboard | {{ config['PUBLIC_CONFIG'].site.title }}
-
+

Welcome {{ current_user.email }}

@@ -87,9 +87,15 @@ Dashboard | {{ config['PUBLIC_CONFIG'].site.title }}
{% endif %} +