refactor match_progress to use SearchProcess
This commit is contained in:
parent
c6458c6ec1
commit
879f5ab52f
|
@ -56,7 +56,7 @@ class SearchProcess:
|
||||||
processed.update(
|
processed.update(
|
||||||
{
|
{
|
||||||
"_index": index,
|
"_index": index,
|
||||||
"_score": round(result.get("_score", 0), 2),
|
"_score": round(result.get("_score") or 0, 2),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,14 @@
|
||||||
<div class="video-list {{ view_style }} {% if view_style == "grid" %}grid-{{ grid_items }}{% endif %}">
|
<div class="video-list {{ view_style }} {% if view_style == "grid" %}grid-{{ grid_items }}{% endif %}">
|
||||||
{% for video in continue_vids %}
|
{% for video in continue_vids %}
|
||||||
<div class="video-item {{ view_style }}">
|
<div class="video-item {{ view_style }}">
|
||||||
<a href="#player" data-id="{{ video.source.youtube_id }}" onclick="createPlayer(this)">
|
<a href="#player" data-id="{{ video.youtube_id }}" onclick="createPlayer(this)">
|
||||||
<div class="video-thumb-wrap {{ view_style }}">
|
<div class="video-thumb-wrap {{ view_style }}">
|
||||||
<div class="video-thumb">
|
<div class="video-thumb">
|
||||||
<img src="{{ video.source.vid_thumb_url }}" alt="video-thumb">
|
<img src="{{ video.vid_thumb_url }}" alt="video-thumb">
|
||||||
{% if video.source.player.progress %}
|
{% if video.player.progress %}
|
||||||
<div class="video-progress-bar" id="progress-{{ video.source.youtube_id }}" style="width: {{video.source.player.progress}}%;"></div>
|
<div class="video-progress-bar" id="progress-{{ video.youtube_id }}" style="width: {{video.player.progress}}%;"></div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="video-progress-bar" id="progress-{{ video.source.youtube_id }}" style="width: 0%;"></div>
|
<div class="video-progress-bar" id="progress-{{ video.youtube_id }}" style="width: 0%;"></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="video-play">
|
<div class="video-play">
|
||||||
|
@ -25,17 +25,17 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<div class="video-desc {{ view_style }}">
|
<div class="video-desc {{ view_style }}">
|
||||||
<div class="video-desc-player" id="video-info-{{ video.source.youtube_id }}">
|
<div class="video-desc-player" id="video-info-{{ video.youtube_id }}">
|
||||||
{% if video.source.player.watched %}
|
{% if video.player.watched %}
|
||||||
<img src="{% static 'img/icon-seen.svg' %}" alt="seen-icon" data-id="{{ video.source.youtube_id }}" data-status="watched" onclick="updateVideoWatchStatus(this)" class="watch-button" title="Mark as unwatched">
|
<img src="{% static 'img/icon-seen.svg' %}" alt="seen-icon" data-id="{{ video.youtube_id }}" data-status="watched" onclick="updateVideoWatchStatus(this)" class="watch-button" title="Mark as unwatched">
|
||||||
{% else %}
|
{% else %}
|
||||||
<img src="{% static 'img/icon-unseen.svg' %}" alt="unseen-icon" data-id="{{ video.source.youtube_id }}" data-status="unwatched" onclick="updateVideoWatchStatus(this)" class="watch-button" title="Mark as watched">
|
<img src="{% static 'img/icon-unseen.svg' %}" alt="unseen-icon" data-id="{{ video.youtube_id }}" data-status="unwatched" onclick="updateVideoWatchStatus(this)" class="watch-button" title="Mark as watched">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span>{{ video.source.published }} | {{ video.source.player.duration_str }}</span>
|
<span>{{ video.published }} | {{ video.player.duration_str }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a href="{% url 'channel_id' video.source.channel.channel_id %}"><h3>{{ video.source.channel.channel_name }}</h3></a>
|
<a href="{% url 'channel_id' video.channel.channel_id %}"><h3>{{ video.channel.channel_name }}</h3></a>
|
||||||
<a class="video-more" href="{% url 'video' video.source.youtube_id %}"><h2>{{ video.source.title }}</h2></a>
|
<a class="video-more" href="{% url 'video' video.youtube_id %}"><h2>{{ video.title }}</h2></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -216,21 +216,20 @@ class ArchivistResultsView(ArchivistViewConfig):
|
||||||
"query": {"bool": {"should": ids}},
|
"query": {"bool": {"should": ids}},
|
||||||
"sort": [{"published": {"order": "desc"}}],
|
"sort": [{"published": {"order": "desc"}}],
|
||||||
}
|
}
|
||||||
search = SearchHandler(
|
response, _ = ElasticWrap("ta_video/_search").get(data)
|
||||||
"ta_video/_search", self.default_conf, data=data
|
videos = SearchProcess(response).process()
|
||||||
)
|
|
||||||
videos = search.get_data()
|
|
||||||
if not videos:
|
if not videos:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for video in videos:
|
for video in videos:
|
||||||
youtube_id = video["source"]["youtube_id"]
|
youtube_id = video["youtube_id"]
|
||||||
matched = [i for i in results if i["youtube_id"] == youtube_id]
|
matched = [i for i in results if i["youtube_id"] == youtube_id]
|
||||||
played_sec = matched[0]["position"]
|
played_sec = matched[0]["position"]
|
||||||
total = video["source"]["player"]["duration"]
|
total = video["player"]["duration"]
|
||||||
if not total:
|
if not total:
|
||||||
total = matched[0].get("position") * 2
|
total = matched[0].get("position") * 2
|
||||||
video["source"]["player"]["progress"] = 100 * (played_sec / total)
|
video["player"]["progress"] = 100 * (played_sec / total)
|
||||||
|
|
||||||
return videos
|
return videos
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue