2
0

view_video.html 11 KB

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