mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2024-12-21 09:20:12 +00:00
jump to timestamp from full search
This commit is contained in:
parent
52d31f9cca
commit
0ec6558282
@ -105,6 +105,18 @@ def date_praser(timestamp):
|
||||
return datetime.strftime(date_obj, "%d %b, %Y")
|
||||
|
||||
|
||||
def time_parser(timestamp):
|
||||
"""return seconds from timestamp, false on empty"""
|
||||
if not timestamp:
|
||||
return False
|
||||
|
||||
if timestamp.isnumeric():
|
||||
return int(timestamp)
|
||||
|
||||
hours, minutes, seconds = timestamp.split(":", maxsplit=3)
|
||||
return int(hours) * 60 * 60 + int(minutes) * 60 + float(seconds)
|
||||
|
||||
|
||||
class UrlListParser:
|
||||
"""take a multi line string and detect valid youtube ids"""
|
||||
|
||||
|
@ -125,7 +125,11 @@
|
||||
<script>
|
||||
var videoData = getVideoData('{{ video.youtube_id }}');
|
||||
sponsorBlock = videoData.data.sponsorblock;
|
||||
var videoProgress = getVideoProgress('{{ video.youtube_id }}').position;
|
||||
{% if position %}
|
||||
var videoProgress = {{ position }}
|
||||
{% else %}
|
||||
var videoProgress = getVideoProgress('{{ video.youtube_id }}').position;
|
||||
{% endif %}
|
||||
window.onload = insertVideoTag(videoData, videoProgress);
|
||||
</script>
|
||||
{% endblock content %}
|
||||
|
@ -35,7 +35,7 @@ from home.src.index.channel import channel_overwrites
|
||||
from home.src.index.generic import Pagination
|
||||
from home.src.index.playlist import YoutubePlaylist
|
||||
from home.src.ta.config import AppConfig, ScheduleBuilder
|
||||
from home.src.ta.helper import UrlListParser
|
||||
from home.src.ta.helper import UrlListParser, time_parser
|
||||
from home.src.ta.ta_redis import RedisArchivist
|
||||
from home.tasks import extrac_dl, index_channel_playlists, subscribe_to
|
||||
from rest_framework.authtoken.models import Token
|
||||
@ -771,6 +771,7 @@ class VideoView(View):
|
||||
def get(self, request, video_id):
|
||||
"""get single video"""
|
||||
config_handler = AppConfig(request.user.id)
|
||||
position = time_parser(request.GET.get("t"))
|
||||
path = f"ta_video/_doc/{video_id}"
|
||||
look_up = SearchHandler(path, config=False)
|
||||
video_hit = look_up.get_data()
|
||||
@ -796,6 +797,7 @@ class VideoView(View):
|
||||
"cast": config_handler.config["application"]["enable_cast"],
|
||||
"version": settings.TA_VERSION,
|
||||
"config": config_handler.config,
|
||||
"position": position,
|
||||
}
|
||||
return render(request, "home/video.html", context)
|
||||
|
||||
|
@ -336,10 +336,18 @@ function cancelDelete() {
|
||||
document.getElementById("delete-item").style.display = 'block';
|
||||
}
|
||||
|
||||
// get seconds from hh:mm:ss.ms timestamp
|
||||
function getSeconds(timestamp) {
|
||||
var elements = timestamp.split(":", 3);
|
||||
var secs = parseInt(elements[0]) * 60 * 60 + parseInt(elements[1]) * 60 + parseFloat(elements[2])
|
||||
return secs
|
||||
}
|
||||
|
||||
// player
|
||||
var sponsorBlock = [];
|
||||
function createPlayer(button) {
|
||||
var videoId = button.getAttribute('data-id');
|
||||
var videoPosition = button.getAttribute('data-position');
|
||||
var videoData = getVideoData(videoId);
|
||||
|
||||
var sponsorBlockElements = '';
|
||||
@ -363,8 +371,11 @@ function createPlayer(button) {
|
||||
} else {
|
||||
sponsorBlock = null;
|
||||
}
|
||||
|
||||
var videoProgress = getVideoProgress(videoId).position;
|
||||
if (videoPosition) {
|
||||
var videoProgress = getSeconds(videoPosition)
|
||||
} else {
|
||||
var videoProgress = getVideoProgress(videoId).position;
|
||||
}
|
||||
var videoName = videoData.data.title;
|
||||
|
||||
var videoTag = createVideoTag(videoData, videoProgress);
|
||||
@ -761,7 +772,9 @@ function removePlayer() {
|
||||
playerElement.innerHTML = '';
|
||||
// append played status
|
||||
var videoInfo = document.getElementById('video-info-' + youtubeId);
|
||||
videoInfo.insertBefore(playedStatus, videoInfo.firstChild);
|
||||
if (videoInfo) {
|
||||
videoInfo.insertBefore(playedStatus, videoInfo.firstChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1022,7 +1035,7 @@ function createFulltext(fullText) {
|
||||
const subtitle_start = fullText.source.subtitle_start.split(".")[0];
|
||||
const subtitle_end = fullText.source.subtitle_end.split(".")[0];
|
||||
const markup = `
|
||||
<a href="#player" data-id="${videoId}" onclick="createPlayer(this)">
|
||||
<a href="#player" data-id="${videoId}" data-position="${subtitle_start}" onclick="createPlayer(this)">
|
||||
<div class="video-thumb-wrap list">
|
||||
<div class="video-thumb">
|
||||
<img src="${thumbUrl}" alt="video-thumb">
|
||||
@ -1037,7 +1050,7 @@ function createFulltext(fullText) {
|
||||
<p>${subtitleLine}</p>
|
||||
<div>
|
||||
<a href="/channel/${channelId}/"><h3>${channelName}</h3></a>
|
||||
<a class="video-more" href="/video/${videoId}/"><h2>${videoTitle}</h2></a>
|
||||
<a class="video-more" href="/video/${videoId}/?t=${subtitle_start}"><h2>${videoTitle}</h2></a>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user