Jump video to timestamp in description or comments
This commit is contained in:
parent
e9989af03a
commit
753f6c5389
@ -2,6 +2,7 @@ from youtube import util
|
|||||||
import flask
|
import flask
|
||||||
import settings
|
import settings
|
||||||
import traceback
|
import traceback
|
||||||
|
import re
|
||||||
from sys import exc_info
|
from sys import exc_info
|
||||||
yt_app = flask.Flask(__name__)
|
yt_app = flask.Flask(__name__)
|
||||||
yt_app.url_map.strict_slashes = False
|
yt_app.url_map.strict_slashes = False
|
||||||
@ -34,6 +35,22 @@ def commatize(num):
|
|||||||
num = int(num)
|
num = int(num)
|
||||||
return '{:,}'.format(num)
|
return '{:,}'.format(num)
|
||||||
|
|
||||||
|
def timestamp_replacement(match):
|
||||||
|
time_seconds = 0
|
||||||
|
for part in match.group(0).split(':'):
|
||||||
|
time_seconds = 60*time_seconds + int(part)
|
||||||
|
return (
|
||||||
|
'<a href="#" onclick="document.querySelector(\'video\').currentTime='
|
||||||
|
+ str(time_seconds)
|
||||||
|
+ '">' + match.group(0)
|
||||||
|
+ '</a>'
|
||||||
|
)
|
||||||
|
|
||||||
|
TIMESTAMP_RE = re.compile(r'\b(\d?\d:)?\d?\d:\d\d\b')
|
||||||
|
@yt_app.template_filter('timestamps')
|
||||||
|
def timestamps(text):
|
||||||
|
return TIMESTAMP_RE.sub(timestamp_replacement, text)
|
||||||
|
|
||||||
@yt_app.errorhandler(500)
|
@yt_app.errorhandler(500)
|
||||||
def error_page(e):
|
def error_page(e):
|
||||||
if (exc_info()[0] == util.FetchError
|
if (exc_info()[0] == util.FetchError
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{% import "common_elements.html" as common_elements %}
|
{% import "common_elements.html" as common_elements %}
|
||||||
|
|
||||||
{% macro render_comment(comment, include_avatar) %}
|
{% macro render_comment(comment, include_avatar, timestamp_links=False) %}
|
||||||
<div class="comment-container">
|
<div class="comment-container">
|
||||||
<div class="comment">
|
<div class="comment">
|
||||||
<a class="author-avatar" href="{{ comment['author_url'] }}" title="{{ comment['author'] }}">
|
<a class="author-avatar" href="{{ comment['author_url'] }}" title="{{ comment['author'] }}">
|
||||||
@ -14,7 +14,11 @@
|
|||||||
<a class="permalink" href="{{ comment['permalink'] }}" title="permalink">
|
<a class="permalink" href="{{ comment['permalink'] }}" title="permalink">
|
||||||
<time datetime="">{{ comment['time_published'] }}</time>
|
<time datetime="">{{ comment['time_published'] }}</time>
|
||||||
</a>
|
</a>
|
||||||
<span class="text">{{ common_elements.text_runs(comment['text']) }}</span>
|
{% if timestamp_links %}
|
||||||
|
<span class="text">{{ common_elements.text_runs(comment['text'])|timestamps|safe }}</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="text">{{ common_elements.text_runs(comment['text']) }}</span>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<span class="likes">{{ comment['likes_text'] if comment['like_count'] else ''}}</span>
|
<span class="likes">{{ comment['likes_text'] if comment['like_count'] else ''}}</span>
|
||||||
<div class="bottom-row">
|
<div class="bottom-row">
|
||||||
@ -36,7 +40,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="comments">
|
<div class="comments">
|
||||||
{% for comment in comments_info['comments'] %}
|
{% for comment in comments_info['comments'] %}
|
||||||
{{ render_comment(comment, comments_info['include_avatars']) }}
|
{{ render_comment(comment, comments_info['include_avatars'], True) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% if 'more_comments_url' is in comments_info %}
|
{% if 'more_comments_url' is in comments_info %}
|
||||||
|
@ -401,7 +401,7 @@ Reload without invidious (for usage of new identity button).</a>
|
|||||||
<input class="checkbox" name="video_info_list" value="{{ video_info }}" form="playlist-edit" type="checkbox">
|
<input class="checkbox" name="video_info_list" value="{{ video_info }}" form="playlist-edit" type="checkbox">
|
||||||
|
|
||||||
|
|
||||||
<span class="description">{{ common_elements.text_runs(description)|urlize }}</span>
|
<span class="description">{{ common_elements.text_runs(description)|escape|urlize|timestamps|safe }}</span>
|
||||||
<div class="music-list">
|
<div class="music-list">
|
||||||
{% if music_list.__len__() != 0 %}
|
{% if music_list.__len__() != 0 %}
|
||||||
<hr>
|
<hr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user