view_video.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. {% extends 'base.html' %}
  2. {% load humanize %}
  3. {% load static %}
  4. {% block content %}
  5. <script src="{% static 'htmx/extensions/class-tools.js' %}" type="application/javascript"></script>
  6. <div id="view_video">
  7. {% if playlist.has_playlist_changed %}
  8. {% else %}
  9. <div class="alert alert-dark alert-dismissible fade show" role="alert" id="user-label-alert" style="display:none;">
  10. <form method="post" action="{% url 'add_video_user_label' video.video_id %}" class="d-flex justify-content-center">
  11. {% csrf_token %}
  12. <span class="mt-2 me-1">Enter an optional label to identify this video with:</span>
  13. <input class="form-control w-25 me-2" type="text" placeholder="Enter here" name="user_label" value="{{ video.user_label }}" aria-label="user label">
  14. <button type="submit" class="btn btn-primary">Save</button>
  15. </form>
  16. <button type="button" class="btn-close mt-2 me-2" onclick='document.getElementById("user-label-alert").style.display = "none";' aria-label="Close"></button>
  17. </div>
  18. <div class="card text-white bg-dark" style="max-width: 100%;">
  19. <div class="row g-0">
  20. <div class="col-md-4 p-3">
  21. <img class="img-fluid rounded-3" src="{{ video.thumbnail_url }}" style="max-width:100%; height: auto; object-fit: cover;">
  22. <span class="d-flex justify-content-center">
  23. <a type="submit" onclick="window.open('{{ video.thumbnail_url }}')" class="btn btn-primary mt-3"><i class="fas fa-image fa-lg me-2"></i> Download Thumbnail</a>
  24. </span>
  25. </div>
  26. <div class="col-md-8">
  27. <div class="card-body">
  28. <div class="row d-flex justify-content-between">
  29. <h2 class="card-title text-white col-10">
  30. <a href="https://www.youtube.com/watch?v={{ video.video_id }}" target="_blank" style="color: white; text-decoration: none">{{ video.name }}</a>
  31. <button class="btn btn-light btn-sm ms-2" onclick='document.getElementById("user-label-alert").style.display = "block";'>
  32. <i class="fas fa-pencil-alt" aria-hidden="true"></i>
  33. </button>
  34. <br><small class="h4">{% if video.user_label %}a.k.a <span style="border-bottom: 3px #ffffff dashed;"> {{ video.user_label }}</span>{% endif %}</small>
  35. </h2>
  36. <h4 class="col d-flex justify-content-end">
  37. <span id="notice-div">
  38. </span>
  39. <span id="">
  40. <input class="form-control me-1 visually-hidden" id="video-{{ video.video_id }}" value="https://www.youtube.com/watch?v={{ video.video_id }}">
  41. <button class="copy-btn btn btn-success me-1" data-clipboard-target="#video-{{ video.video_id }}">
  42. <i class="far fa-copy" aria-hidden="true"></i>
  43. </button>
  44. <button class="btn btn-dark" type="button" hx-get="{% url 'mark_video_favorite' video.video_id %}" hx-target="#video-fav">
  45. <div id="video-fav">
  46. {% if video.is_favorite %}
  47. <i class="fas fa-heart" style="color: #fafa06"></i>
  48. {% else %}
  49. <i class="far fa-heart"></i>
  50. {% endif %}
  51. </div>
  52. </button>
  53. </span>
  54. </h4>
  55. </div>
  56. <h6>by {{ video.channel_name }}</h6>
  57. <p class="card-text">
  58. {% if video.description %}
  59. <h5 class="overflow-auto" style="max-height: 350px;">
  60. {{ video.description|linebreaksbr|urlize }}
  61. </h5>
  62. {% else %}
  63. <h5>No description</h5>
  64. {% endif %}
  65. </p>
  66. <h6 class="h5 text-uppercase overflow-auto text-black-50">
  67. <a style="text-decoration: none" data-bs-toggle="collapse" href="#{{ video.video_id }}DurationCollapse" role="button" aria-expanded="false" aria-controls="{{ video.video_id }}DurationCollapse">
  68. <span class="badge bg-success mb-1">{{ video.duration }}</span>
  69. </a>
  70. <div class="collapse" id="{{ video.video_id }}DurationCollapse">
  71. <div class="card card-body bg-dark text-white text-capitalize border border-3 mt-2 mb-2 border-light">
  72. <div hx-get="{% url 'video_completion_times' video.video_id %}"
  73. hx-trigger="revealed"
  74. hx-swap="outerHTML">
  75. </div>
  76. </div>
  77. </div>
  78. <small>
  79. {% if video.has_cc %}<span class="badge bg-danger mb-1">CC</span>{% endif %}
  80. {% if video.published_at %}<span class="badge bg-secondary mb-1">Video uploaded on {{ video.published_at }}</span>{% endif %}
  81. <span class="badge bg-primary text-white mb-1"><i class="fas fa-eye"></i> {% if video.view_count == -1 %}HIDDEN{% else %}{{ video.view_count|intcomma }}{% endif %}</span>
  82. <span class="badge bg-warning text-black-50 mb-1"><i class="fas fa-thumbs-up"></i> {% if video.like_count == -1 %}HIDDEN{% else %}{{ video.like_count|intcomma }}{% endif %}</span>
  83. <span class="badge bg-warning text-black-50 mb-1"><i class="fas fa-thumbs-down"></i> {% if video.dislike_count == -1 %}HIDDEN{% else %}{{ video.dislike_count|intcomma }}{% endif %}</span>
  84. <span class="badge bg-info text-black-50 mb-1"><i class="fas fa-comments"></i> {% if video.comment_count == -1 %}HIDDEN{% else %}{{ video.comment_count|intcomma }}{% endif %} </span>
  85. {% if video.is_unavailable_on_yt or video.was_deleted_on_yt %}<span class="badge bg-light text-black-50 mb-1">UNAVAILABLE</span>{% endif %}
  86. <span class="badge bg-light text-black-50 mb-1"><a href="#found-in" style="text-decoration: none; color: grey"> Found in {{ video.playlists.all.count }} playlist{% if video.playlists.all.count > 1 %}s{% endif %}</a></span>
  87. {% if video.is_marked_as_watched %}
  88. <span class="badge bg-dark text-white" >
  89. <i class="fas fa-flag-checkered me-1"></i> marked watched
  90. </span>
  91. {% endif %}
  92. </small>
  93. </h6>
  94. <p class="card-text text-white-50"><small>Last updated {{ video.video_details_modified_at|naturalday }}</small> &bullet; <small>{{ video.num_of_accesses }} clicks </small></p> </div>
  95. </div>
  96. </div>
  97. </div>
  98. <br>
  99. {% endif %}
  100. </div>
  101. <div class="row">
  102. <div class="col-6">
  103. <iframe id="ytplayer" width="100%" height="100%" src="//www.youtube.com/embed/{{ video.video_id }}?enablejsapi=1" frameborder="0" style="border: solid 5px #37474F" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
  104. </div>
  105. <div class="col-6">
  106. <div class="row">
  107. <div class="col-6">
  108. <h4>Your notes for this video
  109. </h4>
  110. </div>
  111. <div class="col d-flex justify-content-end pt-2">
  112. <span id="notes-save-status" class="text-success">
  113. </span>
  114. </div>
  115. </div>
  116. <div >
  117. <textarea name="video-notes-text-area"
  118. hx-post="{% url 'video_notes' video.video_id %}"
  119. hx-trigger="keyup changed delay:1.5s"
  120. hx-target="#notes-save-status"
  121. class="form-control"
  122. id="video-notes-text-area"
  123. placeholder="Enter here"
  124. rows="13">
  125. {{ video.user_notes }}
  126. </textarea>
  127. <div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. <br>
  133. <div class="">
  134. <h3><span style="border-bottom: 3px #497ce2 dashed;">Video found in the following playlist{% if video.playlists.all.count > 1 %}s{% endif %}</span><i class="fas fa-binoculars ms-2" style="color: #4669d2"></i></h3>
  135. <div id="found-in" class="row row-cols-1 row-cols-md-4 g-4 text-dark mt-0" data-masonry='{"percentPosition": true }'>
  136. {% for playlist in video.playlists.all %}
  137. <div class="col">
  138. <div class="card" style="background-color: #EFEFEF;">
  139. <img class="bd-placeholder-img card-img-top" src="{{ playlist.thumbnail_url }}" style="max-width:100%; height: 200px; object-fit: cover;" alt="{{ playlist.name }} thumbnail">
  140. <div class="card-body">
  141. <h5 class="card-title"><a href="{% url 'playlist' playlist.playlist_id %}" class="stretched-link" style="text-decoration: none; color: black">{{ playlist.name }}</a></h5>
  142. <p class="card-text">
  143. <span class="badge bg-{% if playlist.get_watch_time_left == "0secs." %}success{% else %}primary{% endif %} text-white">{{ playlist.get_watched_videos_count }}/{{ playlist.get_watchable_videos_count }} viewed</span>
  144. {% if playlist.get_watch_time_left != "0secs." %}<span class="badge bg-dark text-white">{{ playlist.get_watch_time_left }} left</span>{% endif %}
  145. </p>
  146. <p class="card-text">
  147. {% if playlist.tags.all %}
  148. <small>
  149. <i class="fas fa-tags fa-sm" style="color: black"></i>
  150. {% for tag in playlist.tags.all %}
  151. <span class="badge rounded-pill bg-primary mb-lg-1">
  152. {{ tag.name }}
  153. </span>
  154. {% endfor %}
  155. </small>
  156. {% endif %}
  157. </p>
  158. <p class="card-text"><small class="text-muted">Last watched {{ playlist.last_watched|naturalday }}</small></p>
  159. </div>
  160. </div>
  161. </div>
  162. {% endfor %}
  163. </div>
  164. </div>
  165. <script type="text/javascript">
  166. // from https://developers.google.com/youtube/iframe_api_reference#Examples
  167. var tag = document.createElement('script');
  168. tag.id = 'iframe-demo';
  169. tag.src = 'https://www.youtube.com/iframe_api';
  170. var firstScriptTag = document.getElementsByTagName('script')[0];
  171. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  172. var player;
  173. function onYouTubeIframeAPIReady() {
  174. player = new YT.Player('ytplayer', {
  175. events: {
  176. 'onReady': onPlayerReady,
  177. 'onStateChange': onPlayerStateChange
  178. }
  179. });
  180. }
  181. function onPlayerReady(event) {
  182. document.getElementById('ytplayer').style.borderColor = '#FF6D00';
  183. }
  184. function changeBorderColor(playerStatus) {
  185. var color;
  186. if (playerStatus === -1) {
  187. color = "#37474F"; // unstarted = gray
  188. } else if (playerStatus === 0) {
  189. color = "#FFFF00"; // ended = yellow
  190. } else if (playerStatus === 1) {
  191. color = "#33691E"; // playing = green
  192. } else if (playerStatus === 2) {
  193. color = "#DD2C00"; // paused = red
  194. // console.log(player.playerInfo.currentTime + " secs elapsed!");
  195. } else if (playerStatus === 3) {
  196. color = "#AA00FF"; // buffering = purple
  197. } else if (playerStatus === 5) {
  198. color = "#FF6DOO"; // video cued = orange
  199. }
  200. if (color) {
  201. document.getElementById('ytplayer').style.borderColor = color;
  202. }
  203. }
  204. function onPlayerStateChange(event) {
  205. changeBorderColor(event.data);
  206. // can use the below info to create a stream room
  207. // player.playerInfo.currentTime returns player elapsed time
  208. // console.log(player)
  209. }
  210. </script>
  211. {% endblock %}