2
0

home.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. {% extends 'base.html' %}
  2. {% load humanize %}
  3. {% block content %}
  4. {% if user.playlists.all.count == 0 %}
  5. <div class="alert alert-success" role="alert">
  6. <h4 class="alert-heading">It's empty in here</h4>
  7. <p>
  8. There's no playlists in your UnTube right now. You can change that by heading over to <a href="{% url 'manage_playlists' %}" class="btn btn-sm btn-primary">Manage</a> to import some public playlists into your UnTube.
  9. {% if not user.profile.imported_yt_playlists %}
  10. Or you could always head over to your <a href="{% url 'profile' %}" class="btn btn-sm btn-primary">Profile</a> to import all of your public/private YouTube playlists.
  11. {% else %}
  12. Keep in mind that your own YouTube playlists will automatically be imported into UnTube.
  13. {% endif %}
  14. </p>
  15. </div>
  16. {% endif %}
  17. {% if import_successful %}
  18. <br>
  19. <br>
  20. <div class="d-flex justify-content-center pt-3 pb-2 mb-3">
  21. <h1>Welcome to UnTube, {{ user.username|capfirst }}</h1>
  22. </div>
  23. <div class="d-flex justify-content-center pt-3 pb-2 mb-3">
  24. <h2>{{ user.playlists.all.count }} playlists from YouTube have been successfully imported.</h2>
  25. </div>
  26. <div class="d-flex justify-content-center pt-3 pb-2 mb-3">
  27. <h3>You'll now be notified on the Dashboard whenever there's any new un-exported playlists on YouTube :)</h3>
  28. </div>
  29. <div class="d-flex justify-content-center pt-3 pb-2 mb-3">
  30. <a href="{% url 'home' %}" class="btn btn-lg btn-success">Go to Dashboard</a>
  31. </div>
  32. {% else %}
  33. {% if user.profile.imported_yt_playlists %}
  34. <div hx-get="{% url 'user_playlists_updates' 'check-for-updates' %}" hx-trigger="load" hx-swap="outerHTML">
  35. </div>
  36. {% endif %}
  37. <div class="row">
  38. <div class="col-6 mb-4">
  39. <div class="card bg-transparent text-dark">
  40. <div class="card-body">
  41. <h6 class="d-flex align-items-center mb-3"><span class="text-primary me-2">{{ user.playlists.count }}</span>Playlists Statistics</h6>
  42. <div class="d-flex align-items-center mb-3">
  43. <canvas id="overall-playlists-distribution" data-url="{% url 'overall_playlists_distribution' %}">
  44. </canvas>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="col-6 mb-4">
  50. <div class="card bg-transparent text-dark">
  51. <div class="card-body">
  52. <h6 class="d-flex align-items-center mb-3"><span class="text-primary me-2">{{ watching.count }}</span>
  53. {% if watching.count > 0 %}
  54. Playlist{% if watching.count > 1 %}s{% endif %} Watching: Percent Complete Chart
  55. {% else %}
  56. Watching: Mark playlists as watching to view their completeness % here!
  57. {% endif %}
  58. </h6>
  59. <div class="d-flex align-items-center mb-3">
  60. <canvas id="watching-playlists-percent-distribution" data-url="{% url 'watching_playlists_percent_distribution' %}">
  61. </canvas>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="row" ><!--data-masonry='{"percentPosition": true }'-->
  68. {% for playlist in user_playlists|slice:"0:3" %}
  69. <div class="col-sm-6 col-lg-4 mb-4">
  70. <div class="card card-cover h-100 overflow-hidden text-white gradient-bg-3 rounded-5 shadow-lg" style="">
  71. <div class="d-flex flex-column h-100 p-5 pb-3 text-white text-shadow-1">
  72. <h2 class="pt-5 mt-5 mb-4 display-6 lh-1 fw-bold"><a href="{% url 'playlist' playlist.playlist_id %}" class="stretched-link" style="text-decoration: none; color: #fafafa">{{ playlist.name }}</a> </h2>
  73. <ul class="d-flex list-unstyled mt-auto">
  74. <li class="me-auto">
  75. <img src="{{ playlist.thumbnail_url }}" alt="Bootstrap" width="32" height="32" class="rounded-circle border border-white">
  76. </li>
  77. <li class="d-flex align-items-center me-3">
  78. <small>by {{ playlist.channel_name }}</small>
  79. </li>
  80. <li class="d-flex align-items-center">
  81. <i class="fas fa-eye me-1"></i>
  82. <small>{{ playlist.num_of_accesses }} clicks</small>
  83. </li>
  84. </ul>
  85. </div>
  86. </div>
  87. </div>
  88. {% endfor %}
  89. <!-- FULL IMAGE CARD: might be useful
  90. <div class="col-sm-6 col-lg-4 mb-4">
  91. <div class="card">
  92. <svg class="bd-placeholder-img card-img" width="100%" height="260" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Card image" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"/><text x="50%" y="50%" fill="#dee2e6" dy=".3em">Card image</text></svg>
  93. </div>
  94. </div>
  95. -->
  96. </div>
  97. <br>
  98. <div class="row text-dark mt-0 align-items-center">
  99. <div class="col">
  100. <div class="card card-cover h-100 overflow-hidden text-white bg-dark rounded-5 shadow-lg" style="">
  101. <div class="d-flex flex-column h-100 p-5 pb-3 text-white text-shadow-1">
  102. <h2 class="pt-5 mt-5 mb-4 display-6 lh-1 fw-bold">All/Your Pins <i class="fas fa-thumbtack" style="color: red"></i> </h2>
  103. </div>
  104. </div>
  105. <!-- Implement later
  106. <div class="row mt-3">
  107. <div class="col">
  108. </div>
  109. <div class="col-6">
  110. <div class="card">
  111. <a style="background: linear-gradient(-45deg, #e2b968, #68af5b, #8a97bc, #d69ab2); background-size: 400% 400%; animation: gradient 7s ease infinite;" href="#" class="list-group-item list-group-item-action" aria-current="true">
  112. <div class="card-body">
  113. <div class="d-flex justify-content-center h1">
  114. <i class="fas fa-history"></i>
  115. </div>
  116. <div class="d-flex justify-content-center h1">
  117. YOUR
  118. </div>
  119. <div class="d-flex justify-content-center h1">
  120. ACTIVITY
  121. </div>
  122. </div>
  123. </a>
  124. </div>
  125. </div>
  126. <div class="col">
  127. </div>
  128. </div>
  129. -->
  130. </div>
  131. <div class="col-8">
  132. <div class="card bg-transparent border border-0 text-black">
  133. <div class="card-body">
  134. <h3><span style="border-bottom: 3px #a35a5a dashed;">Most viewed playlists</span> <a href="{% url 'all_playlists' 'all' %}" class="pt-1"><i class="fas fa-binoculars"></i> </a></h3>
  135. {% if user_playlists %}
  136. <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
  137. {% for playlist in user_playlists|slice:"0:3" %}
  138. <div class="col">
  139. <div class="card overflow-auto" style="background-color: #4790c7;">
  140. <a href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item bg-transparent list-group-item-action" aria-current="true">
  141. <div class="card-body">
  142. <h5 class="card-title">
  143. #{{ forloop.counter }} <br><br>{{ playlist.name }}
  144. {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
  145. {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
  146. </h5>
  147. <small>
  148. <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
  149. <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
  150. <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
  151. </small>
  152. </div>
  153. </a>
  154. </div>
  155. </div>
  156. {% endfor %}
  157. </div>
  158. {% else %}
  159. <br>
  160. <h5>Nothing to see here... yet.</h5>
  161. {% endif %}
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. <br>
  167. {% if watching %}
  168. <div class="border border-5 rounded-3 border-primary p-3">
  169. <h3><span style="border-bottom: 3px #e24949 dashed;">Continue Watching</span><i class="fas fa-fire-alt ms-2" style="color: #d24646"></i></h3>
  170. <div class="row row-cols-1 row-cols-md-4 g-4 text-dark mt-0" data-masonry='{"percentPosition": true }'>
  171. {% for playlist in watching %}
  172. <div class="col">
  173. <div class="card" style="background-color: #EFEFEF;">
  174. <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">
  175. <div class="card-body">
  176. <h5 class="card-title"><a href="{% url 'playlist' playlist.playlist_id %}" class="stretched-link" style="text-decoration: none; color: black">{{ playlist.name }}</a></h5>
  177. <p class="card-text">
  178. <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>
  179. {% if playlist.get_watch_time_left != "0secs." %}<span class="badge bg-dark text-white">{{ playlist.get_watch_time_left }} left</span>{% endif %}
  180. </p>
  181. <p class="card-text">
  182. {% if playlist.tags.all %}
  183. <small>
  184. <i class="fas fa-tags fa-sm" style="color: black"></i>
  185. {% for tag in playlist.tags.all %}
  186. <span class="badge rounded-pill bg-primary mb-lg-1">
  187. {{ tag.name }}
  188. </span>
  189. {% endfor %}
  190. </small>
  191. {% endif %}
  192. </p>
  193. <p class="card-text"><small class="text-muted">Last watched {{ playlist.last_watched|naturalday }}</small></p>
  194. </div>
  195. </div>
  196. </div>
  197. <!--
  198. <div class="col">
  199. <div class="card">
  200. <a style="background-color: #7e89c2;" href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item list-group-item-action" aria-current="true">
  201. <div class="card-body">
  202. <h5 class="card-title">
  203. {{ playlist.name }}
  204. {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
  205. {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
  206. </h5>
  207. <p class="card-text">
  208. <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>
  209. {% if playlist.get_watch_time_left != "0secs." %}<span class="badge bg-dark text-white">{{ playlist.get_watch_time_left }} left</span>{% endif %}
  210. </p>
  211. {% if playlist.tags.all %}
  212. <small>
  213. <i class="fas fa-tags fa-sm" style="color: yellow"></i>
  214. {% for tag in playlist.tags.all %}
  215. <span class="badge rounded-pill bg-primary mb-lg-1">
  216. {{ tag.name }}
  217. </span>
  218. {% endfor %}
  219. </small>
  220. {% endif %}
  221. </div>
  222. </a>
  223. </div>
  224. </div> -->
  225. <!--
  226. {% if forloop.counter == 3 %}
  227. {% if watching.count|add:"-3" != 0 %}
  228. <div class="col">
  229. <div class="card">
  230. <a style="background-color: #7e89c2;" href="{% url 'all_playlists' 'watching' %}" class="list-group-item list-group-item-action" aria-current="true">
  231. <div class="card-body">
  232. <p class="card-text">
  233. <h3>+ {{ watching.count|add:"-3" }} more</h3>
  234. </p>
  235. </div>
  236. </a>
  237. </div>
  238. </div>
  239. {% endif %}
  240. {% endif %}
  241. -->
  242. {% endfor %}
  243. </div>
  244. </div>
  245. <br>
  246. {% endif %}
  247. <br>
  248. <div class="row text-dark mt-0 d-flex justify-content-evenly">
  249. <div class="col">
  250. <h3><span style="border-bottom: 3px #e24949 dashed;">Recently Added</span> <i class="fas fa-plus-square" style="color:#972727;"></i></h3>
  251. {% if recently_added_playlists %}
  252. <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
  253. {% for playlist in recently_added_playlists %}
  254. <div class="col">
  255. <div class="card overflow-auto" style="background-color: #958a44;">
  256. <a href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item bg-transparent list-group-item-action" aria-current="true">
  257. <div class="card-body">
  258. <h5 class="card-title">
  259. {{ playlist.name }}
  260. {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
  261. {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
  262. </h5>
  263. <small>
  264. <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
  265. <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
  266. <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
  267. </small>
  268. </div>
  269. </a>
  270. </div>
  271. </div>
  272. {% endfor %}
  273. </div>
  274. {% else %}
  275. <br>
  276. <h5>You have no playlists ;-;</h5>
  277. {% endif %}
  278. </div>
  279. <div class="col">
  280. <h3><span style="border-bottom: 3px #e24949 dashed;">Recently Accessed</span> <i class="fas fa-redo fa-sm" style="color: #3c3fd2"></i></h3>
  281. {% if recently_accessed_playlists %}
  282. <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
  283. {% for playlist in recently_accessed_playlists %}
  284. <div class="col">
  285. <div class="card overflow-auto" style="background-color: #357779;">
  286. <a href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item bg-transparent list-group-item-action" aria-current="true">
  287. <div class="card-body">
  288. <h5 class="card-title">
  289. {{ playlist.name }}
  290. {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
  291. {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
  292. </h5>
  293. <small>
  294. <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
  295. <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
  296. <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
  297. </small>
  298. </div>
  299. </a>
  300. </div>
  301. </div>
  302. {% endfor %}
  303. </div>
  304. {% else %}
  305. <br>
  306. <h5>Nothing to see here... yet.</h5>
  307. {% endif %}
  308. </div>
  309. </div>
  310. <br>
  311. <br>
  312. <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>
  313. <script type="application/javascript">
  314. $(function () {
  315. var $overallPlaylists = $("#overall-playlists-distribution");
  316. $.ajax({
  317. url: $overallPlaylists.data("url"),
  318. success: function (data) {
  319. var ctx = $overallPlaylists[0].getContext("2d");
  320. var coloR = [];
  321. var dynamicColors = function() { // generate random color
  322. var r = Math.floor(Math.random() * 255);
  323. var g = Math.floor(Math.random() * 255);
  324. var b = Math.floor(Math.random() * 255);
  325. return "rgb(" + r + "," + g + "," + b + ")";
  326. };
  327. for (var i in data.labels) {
  328. if (data.labels)
  329. coloR.push(dynamicColors());
  330. }
  331. new Chart(ctx, {
  332. type: 'pie',
  333. data: {
  334. labels: data.labels,
  335. datasets: [{
  336. label: 'Playlist Types',
  337. backgroundColor: coloR,
  338. data: data.data
  339. }]
  340. },
  341. options: {
  342. responsive: true,
  343. legend: {
  344. position: 'right',
  345. display: true
  346. },
  347. title: {
  348. display: false,
  349. text: 'Video Count Distribution per Channel',
  350. fontSize: 20,
  351. fontColor: '#fff',
  352. },
  353. }
  354. });
  355. }
  356. });
  357. var $watchingPlaylists = $("#watching-playlists-percent-distribution");
  358. $.ajax({
  359. url: $watchingPlaylists.data("url"),
  360. success: function (data) {
  361. var ctx = $watchingPlaylists[0].getContext("2d");
  362. var coloR = [];
  363. var dynamicColors = function() { // generate random color
  364. var r = Math.floor(Math.random() * 255);
  365. var g = Math.floor(Math.random() * 255);
  366. var b = Math.floor(Math.random() * 255);
  367. return "rgb(" + r + "," + g + "," + b + ")";
  368. };
  369. for (var i in data.labels) {
  370. if (data.labels)
  371. coloR.push(dynamicColors());
  372. }
  373. new Chart(ctx, {
  374. type: 'polarArea',
  375. data: {
  376. labels: data.labels,
  377. datasets: [{
  378. label: 'Playlist Types',
  379. backgroundColor: coloR,
  380. data: data.data
  381. }]
  382. },
  383. options: {
  384. scale: {
  385. reverse: false,
  386. ticks: {
  387. min: 0,
  388. max: 100,
  389. interval: 10,
  390. }
  391. },
  392. responsive: true,
  393. legend: {
  394. position: 'right',
  395. display: true
  396. },
  397. title: {
  398. display: false,
  399. text: 'Video Count Distribution per Channel',
  400. fontSize: 20,
  401. fontColor: '#fff',
  402. },
  403. }
  404. });
  405. }
  406. });
  407. });
  408. </script>
  409. {% endif %}
  410. {% endblock %}