mirror of
https://github.com/fastogt/fastocloud_admin.git
synced 2025-03-09 23:38:52 +00:00
Meta for streams
This commit is contained in:
parent
2389a5b098
commit
d0d1660037
6 changed files with 241 additions and 0 deletions
|
@ -96,6 +96,7 @@ from app.provider.view import ProviderView
|
||||||
from app.stream.view import StreamView
|
from app.stream.view import StreamView
|
||||||
from app.service.view import ServiceView
|
from app.service.view import ServiceView
|
||||||
from app.subscriber.view import SubscriberView
|
from app.subscriber.view import SubscriberView
|
||||||
|
from app.autofill.view import M3uParseView
|
||||||
from app.epg.view import EpgView
|
from app.epg.view import EpgView
|
||||||
|
|
||||||
HomeView.register(app)
|
HomeView.register(app)
|
||||||
|
@ -103,4 +104,5 @@ ProviderView.register(app)
|
||||||
StreamView.register(app)
|
StreamView.register(app)
|
||||||
ServiceView.register(app)
|
ServiceView.register(app)
|
||||||
SubscriberView.register(app)
|
SubscriberView.register(app)
|
||||||
|
M3uParseView.register(app)
|
||||||
EpgView.register(app)
|
EpgView.register(app)
|
||||||
|
|
15
app/autofill/entry.py
Normal file
15
app/autofill/entry.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
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}
|
||||||
|
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=[])
|
73
app/autofill/view.py
Normal file
73
app/autofill/view.py
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
from flask_classy import FlaskView, route
|
||||||
|
from flask import request, jsonify, render_template, redirect, url_for
|
||||||
|
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 pyfastocloud_models.utils.utils import is_valid_http_url
|
||||||
|
|
||||||
|
|
||||||
|
# routes
|
||||||
|
class M3uParseView(FlaskView):
|
||||||
|
route_base = '/m3uparse/'
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def show(self):
|
||||||
|
m3u = M3uParse.objects()
|
||||||
|
return render_template('autofill/show.html', m3u=m3u)
|
||||||
|
|
||||||
|
@route('/search/<sid>', methods=['GET'])
|
||||||
|
@login_required
|
||||||
|
def search(self, sid):
|
||||||
|
lines = M3uParse.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 = M3uParse.objects(name=title).first()
|
||||||
|
if not line:
|
||||||
|
line = M3uParse(name=title)
|
||||||
|
|
||||||
|
tvg_id = file['tvg-id']
|
||||||
|
if len(tvg_id) < constants.MAX_STREAM_TVG_ID_LENGTH:
|
||||||
|
line.tvg_id.append(tvg_id)
|
||||||
|
|
||||||
|
tvg_group = file['tvg-group']
|
||||||
|
if len(tvg_group) < constants.MAX_STREAM_GROUP_TITLE_LENGTH:
|
||||||
|
line.group.append(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):
|
||||||
|
line.tvg_logo.append(tvg_logo)
|
||||||
|
|
||||||
|
line.save()
|
||||||
|
|
||||||
|
return redirect(url_for('M3uParseView:show'))
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@route('/upload_m3u', methods=['POST', 'GET'])
|
||||||
|
def upload_m3u(self):
|
||||||
|
form = UploadM3uForm()
|
||||||
|
return render_template('autofill/upload_m3u.html', form=form)
|
100
app/templates/autofill/show.html
Normal file
100
app/templates/autofill/show.html
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
{% extends 'layouts/layout_user.html' %}
|
||||||
|
{% from 'bootstrap/wtf.html' import form_field %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
M3U | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
|
{% endblock %}
|
||||||
|
{% block styles %}
|
||||||
|
<style>
|
||||||
|
table {
|
||||||
|
table-layout: fixed;
|
||||||
|
}
|
||||||
|
th.number {
|
||||||
|
width: 2%;
|
||||||
|
}
|
||||||
|
th.name {
|
||||||
|
width: 88%;
|
||||||
|
}
|
||||||
|
th.actions {
|
||||||
|
width: 10%;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</style>
|
||||||
|
{{super()}}
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h1 class="panel-title">
|
||||||
|
<div class="col-md-11">
|
||||||
|
<a href="{{ url_for('HomeView:index') }}">{{ config['PUBLIC_CONFIG'].site.title }}</a>
|
||||||
|
</div>
|
||||||
|
<div>Version: {{ config['PUBLIC_CONFIG'].project.version }}</div>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row well">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<p>M3u</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<a href="{{ url_for('ProviderView:dashboard') }}" role="button" class="btn btn-info">
|
||||||
|
Dashboard
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<a href="{{ url_for('ProviderView:logout') }}" class="btn btn-warning" role="button">
|
||||||
|
Logout
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row well">
|
||||||
|
<div class="row">
|
||||||
|
<table id='m3u_table' class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="number">#</th>
|
||||||
|
<th class="name">Name</th>
|
||||||
|
<th class="actions">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for line in m3u %}
|
||||||
|
<tr id='{{ line.id }}'>
|
||||||
|
<td>{{ loop.index }}</td>
|
||||||
|
<td>{{ line.name }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('M3uParseView:search', sid=line.id) }}" role="button"
|
||||||
|
target="_blank" class="btn btn-success btn-xs">
|
||||||
|
Show
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<a href="{{ url_for('M3uParseView:upload_m3u') }}" role="button" class="btn btn-success">
|
||||||
|
Upload urls
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="epg_dialog" class="modal fade" tabindex=-1 role="dialog">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
{{ super() }}
|
||||||
|
{% endblock %}
|
45
app/templates/autofill/upload_m3u.html
Normal file
45
app/templates/autofill/upload_m3u.html
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{% extends 'layouts/layout_home.html' %}
|
||||||
|
{% block title %}
|
||||||
|
Upload m3u | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h1 class="panel-title">
|
||||||
|
<div class="col-md-11">
|
||||||
|
<a href="{{ url_for('HomeView:index') }}">{{ config['PUBLIC_CONFIG'].site.title }}</a>
|
||||||
|
</div>
|
||||||
|
<div>Version: {{ config['PUBLIC_CONFIG'].project.version }}</div>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row well">
|
||||||
|
<h3>Upload m3u files</h3>
|
||||||
|
<p>Note: Please upload m3u files for service.</p>
|
||||||
|
{{ util.flashed_messages(dismissible=True, container=False) }}
|
||||||
|
<form action="{{ url_for('M3uParseView:upload_files') }}" method="POST" class="form" role="form"
|
||||||
|
enctype="multipart/form-data">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
<div class="col-md-3">
|
||||||
|
{{ form.files }}
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
Type: {{ form.type }}
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
{{ form_field(form.upload, class="btn btn-success") }}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<a href="{{ url_for('ProviderView:dashboard') }}" role="button" class="btn btn-info">
|
||||||
|
Dashboard
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{%- endblock %}
|
|
@ -86,6 +86,12 @@ Dashboard | {{ config['PUBLIC_CONFIG'].site.title }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<div class="col-md-1">
|
||||||
|
<a href="{{ url_for('M3uParseView:show') }}" class="btn btn-warning"
|
||||||
|
role="button">
|
||||||
|
Meta
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<div class="col-md-1">
|
<div class="col-md-1">
|
||||||
<a href="{{ url_for('ProviderView:logout') }}" class="btn btn-warning" role="button">
|
<a href="{{ url_for('ProviderView:logout') }}" class="btn btn-warning" role="button">
|
||||||
Logout
|
Logout
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue