From 0ec6558282ecddcbc4b540872b6c6105be3533fd Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 21 Jul 2022 17:15:36 +0700 Subject: [PATCH] jump to timestamp from full search --- tubearchivist/home/src/ta/helper.py | 12 ++++++++++ tubearchivist/home/templates/home/video.html | 6 ++++- tubearchivist/home/views.py | 4 +++- tubearchivist/static/script.js | 23 +++++++++++++++----- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/tubearchivist/home/src/ta/helper.py b/tubearchivist/home/src/ta/helper.py index 3a7164d..bc943ec 100644 --- a/tubearchivist/home/src/ta/helper.py +++ b/tubearchivist/home/src/ta/helper.py @@ -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""" diff --git a/tubearchivist/home/templates/home/video.html b/tubearchivist/home/templates/home/video.html index 1aa9590..b7af89c 100644 --- a/tubearchivist/home/templates/home/video.html +++ b/tubearchivist/home/templates/home/video.html @@ -125,7 +125,11 @@ {% endblock content %} diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 85fe41e..c5a30e3 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -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) diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index abc8588..ddb96db 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -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 = ` - +
`