view_video.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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"></i></a>
  24. <a href="https://www.youtube.com/watch?v={{ video.video_id }}" class="btn btn-info ms-2 mt-3" target="_blank" id="share_link" style=""><i class="fas fa-external-link-alt" aria-hidden="true"></i></a>
  25. <input class="form-control me-1 visually-hidden" id="video-{{ video.video_id }}" value="https://www.youtube.com/watch?v={{ video.video_id }}">
  26. <button class="copy-btn btn btn-success ms-2 mt-3" data-clipboard-target="#video-{{ video.video_id }}">
  27. <i class="far fa-copy" aria-hidden="true"></i>
  28. </button>
  29. <button class="btn btn-dark mt-3 ms-2" type="button" hx-get="{% url 'mark_video_favorite' video.video_id %}" hx-target="#video-fav">
  30. <div id="video-fav">
  31. {% if video.is_favorite %}
  32. <i class="fas fa-heart" style="color: #fafa06"></i>
  33. {% else %}
  34. <i class="far fa-heart"></i>
  35. {% endif %}
  36. </div>
  37. </button>
  38. </span>
  39. </div>
  40. <div class="col-md-8">
  41. <div class="card-body">
  42. <div class="row d-flex justify-content-between">
  43. <h2 class="card-title text-white col-10">
  44. <a href="https://www.youtube.com/watch?v={{ video.video_id }}" target="_blank" style="color: white; text-decoration: none">{{ video.name }}</a>
  45. <button class="btn btn-light btn-sm ms-2" onclick='document.getElementById("user-label-alert").style.display = "block";'>
  46. <i class="fas fa-pencil-alt" aria-hidden="true"></i>
  47. </button>
  48. <br><small class="h4">{% if video.user_label %}a.k.a <span style="border-bottom: 3px #ffffff dashed;"> {{ video.user_label }}</span>{% endif %}</small>
  49. </h2>
  50. </div>
  51. <h6>by <a href="{% url 'search' %}?mode=videos&channel={{ video.channel_name }}" style="text-decoration: none; color: white"><span style="border-bottom: 3px #e35959 dashed;">{{ video.channel_name }}</span></a></h6>
  52. <p class="card-text">
  53. {% if video.description %}
  54. <h5 class="overflow-auto" style="max-height: 350px;">
  55. {{ video.description|linebreaksbr|urlize }}
  56. </h5>
  57. {% else %}
  58. <h5>No description</h5>
  59. {% endif %}
  60. </p>
  61. <h6 class="h5 text-uppercase overflow-auto text-black-50">
  62. <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">
  63. <span class="badge bg-success mb-1">{{ video.duration }}</span>
  64. </a>
  65. <div class="collapse" id="{{ video.video_id }}DurationCollapse">
  66. <div class="card card-body bg-dark text-white text-capitalize border border-3 mt-2 mb-2 border-light">
  67. <div hx-get="{% url 'video_completion_times' video.video_id %}"
  68. hx-trigger="revealed"
  69. hx-swap="outerHTML">
  70. </div>
  71. </div>
  72. </div>
  73. <small>
  74. {% if video.has_cc %}<span class="badge bg-danger mb-1">CC</span>{% endif %}
  75. {% if video.published_at %}<span class="badge bg-secondary mb-1">Video uploaded on {{ video.published_at }}</span>{% endif %}
  76. <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>
  77. <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>
  78. <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>
  79. <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>
  80. {% 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 %}
  81. <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>
  82. {% if video.is_marked_as_watched %}
  83. <span class="badge bg-dark text-white" >
  84. <i class="fas fa-flag-checkered me-1"></i> marked watched
  85. </span>
  86. {% endif %}
  87. </small>
  88. </h6>
  89. <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>
  90. </div>
  91. </div>
  92. </div>
  93. <br>
  94. {% endif %}
  95. </div>
  96. <div class="row">
  97. <div class="col-6">
  98. <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>
  99. </div>
  100. <div class="col-6">
  101. <div class="row">
  102. <div class="col-6">
  103. <h4>Your notes for this video
  104. </h4>
  105. </div>
  106. <div class="col d-flex justify-content-end pt-2">
  107. <span id="notes-save-status" class="text-success">
  108. </span>
  109. </div>
  110. </div>
  111. <div >
  112. <textarea name="video-notes-text-area"
  113. hx-post="{% url 'video_notes' video.video_id %}"
  114. hx-trigger="keyup changed delay:1.5s"
  115. hx-target="#notes-save-status"
  116. class="form-control"
  117. id="video-notes-text-area"
  118. placeholder="Enter here"
  119. rows="13">
  120. {{ video.user_notes }}
  121. </textarea>
  122. <div>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. <br>
  128. <div class="">
  129. <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>
  130. <div id="found-in" class="row row-cols-1 row-cols-md-4 g-4 text-dark mt-0" data-masonry='{"percentPosition": true }'>
  131. {% include 'intercooler/playlists.html' with playlists=video.playlists.all watching=False bg_color="#357779" show_controls=True %}
  132. </div>
  133. </div>
  134. <script type="text/javascript">
  135. // from https://developers.google.com/youtube/iframe_api_reference#Examples
  136. var tag = document.createElement('script');
  137. tag.id = 'iframe-demo';
  138. tag.src = 'https://www.youtube.com/iframe_api';
  139. var firstScriptTag = document.getElementsByTagName('script')[0];
  140. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  141. var player;
  142. function onYouTubeIframeAPIReady() {
  143. player = new YT.Player('ytplayer', {
  144. events: {
  145. 'onReady': onPlayerReady,
  146. 'onStateChange': onPlayerStateChange
  147. }
  148. });
  149. }
  150. function onPlayerReady(event) {
  151. document.getElementById('ytplayer').style.borderColor = '#FF6D00';
  152. }
  153. function changeBorderColor(playerStatus) {
  154. var color;
  155. if (playerStatus === -1) {
  156. color = "#37474F"; // unstarted = gray
  157. } else if (playerStatus === 0) {
  158. color = "#FFFF00"; // ended = yellow
  159. } else if (playerStatus === 1) {
  160. color = "#33691E"; // playing = green
  161. } else if (playerStatus === 2) {
  162. color = "#DD2C00"; // paused = red
  163. // console.log(player.playerInfo.currentTime + " secs elapsed!");
  164. } else if (playerStatus === 3) {
  165. color = "#AA00FF"; // buffering = purple
  166. } else if (playerStatus === 5) {
  167. color = "#FF6DOO"; // video cued = orange
  168. }
  169. if (color) {
  170. document.getElementById('ytplayer').style.borderColor = color;
  171. }
  172. }
  173. function onPlayerStateChange(event) {
  174. changeBorderColor(event.data);
  175. // can use the below info to create a stream room
  176. // player.playerInfo.currentTime returns player elapsed time
  177. // console.log(player)
  178. }
  179. </script>
  180. {% endblock %}