Youtube: Format video descriptions

This commit is contained in:
pluja 2020-08-30 10:05:16 +02:00
parent 0f4d6e163e
commit 54f3fc2ca6
4 changed files with 35 additions and 25 deletions

View File

@ -18,6 +18,7 @@ import random, string
import time, datetime import time, datetime
import feedparser import feedparser
import requests import requests
import bleach
import urllib import urllib
import json import json
import re import re
@ -312,7 +313,7 @@ def watch():
video = { video = {
'title':data['title'], 'title':data['title'],
'description':Markup(data['description']), 'description':Markup(markupString(data['description'])),
'viewCount':data['view_count'], 'viewCount':data['view_count'],
'author':data['uploader'], 'author':data['uploader'],
'authorUrl':data['uploader_url'], 'authorUrl':data['uploader_url'],
@ -320,8 +321,18 @@ def watch():
'id':id, 'id':id,
'averageRating': str((float(data['average_rating'])/5)*100) 'averageRating': str((float(data['average_rating'])/5)*100)
} }
print(video['description'])
return render_template("video.html", video=video) return render_template("video.html", video=video)
def markupString(string):
string = string.replace("\n\n", "<br><br>").replace("\n", "<br>")
string = bleach.linkify(string)
string = string.replace("https://youtube.com/", "")
string = string.replace("https://www.youtube.com/", "")
string = string.replace("https://twitter.com/", "/u/")
print(request.url)
return string
## PROXY videos through Parasitter server to the client. ## PROXY videos through Parasitter server to the client.
@app.route('/stream', methods=['GET', 'POST']) @app.route('/stream', methods=['GET', 'POST'])
@login_required @login_required
@ -636,7 +647,7 @@ def getYoutubePosts(ids):
if time.days >= 15: if time.days >= 15:
continue continue
video = ytPost() video = ytPost()
video.date = vid.published_parsed video.date = vid.published_parsed
video.timeStamp = getTimeDiff(vid.published_parsed) video.timeStamp = getTimeDiff(vid.published_parsed)

View File

@ -1,6 +1,6 @@
<div class="ui text container"> <div class="ui center aligned text container">
<div class="ui row"> <div class="ui row">
<img class="ui medium circular image" src="{{ url_for('static',filename='img/empty.png') }}"> <img class="ui image" src="{{ url_for('static',filename='img/empty.png') }}">
</div> </div>
<div class="ui row"> <div class="ui row">

View File

@ -12,25 +12,24 @@
</div></a> </div></a>
</div> </div>
<div style="margin: 0em;" class="ui one column centered grid"> <div class="ui text container">
<div class="ui middle aligned divided list"> <div class="ui relaxed divided list">
{% for channel in channelList %} {% for channel in channelList %}
<div class="item"> <div class="item">
<div class="right floated content"> <div class="right floated content">
<p> <p>
<form action="{{ url_for('ytunfollow', channelId=channel.channelId) }}" method="post"> <form action="{{ url_for('ytunfollow', channelId=channel.channelId) }}" method="post">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ form.submit(value='Unfollow') }} {{ form.submit(value='Unfollow') }}
</form> </form>
</p> </p>
</div> </div>
<img class="ui avatar image" src="{{ url_for('static',filename='img/avatars/')}}{{range(1, 12) | random}}.png"> <div class="content">
<div class="content"> <a href="{{ url_for('channel',id=channel.channelId)}}" class="header">{{channel.channelName}}</a>
<a href="{{ url_for('channel', id=channel.channelId)}}">{{channel.channelName}}</a> </div>
</div> </div>
{% endfor %}
</div> </div>
{% endfor %}
</div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -14,8 +14,8 @@
<p>{{ form.submit() }}</p> <p>{{ form.submit() }}</p>
</form> </form>
<h3 class="ui dividing header">Users</h3> {% if channels %}
{% if channels %} <h3 class="ui dividing header">Users</h3>
<div class="ui relaxed divided list"> <div class="ui relaxed divided list">
{% for res in channels %} {% for res in channels %}
@ -51,8 +51,8 @@
<div class="ui middle aligned divided list"> <div class="ui middle aligned divided list">
<h3 class="ui dividing header">Videos</h3>
{% if videos %} {% if videos %}
<h3 class="ui dividing header">Videos</h3>
<div class="ui centered cards"> <div class="ui centered cards">
{% for video in videos %} {% for video in videos %}
{% include '_video_item.html' %} {% include '_video_item.html' %}