home.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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{% if user.playlists.count == 0 %}: You have no playlists in your UnTube!{% endif %}</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. <small> <a class="btn btn-sm btn-success ms-2" href="#continue-watching">View</a></small>
  56. {% else %}
  57. Watching: Mark playlists as watching to view their completeness % here!
  58. {% endif %}
  59. </h6>
  60. <div class="d-flex align-items-center mb-3">
  61. <canvas id="watching-playlists-percent-distribution" data-url="{% url 'watching_playlists_percent_distribution' %}">
  62. </canvas>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <div class="row" ><!--data-masonry='{"percentPosition": true }'-->
  69. {% for playlist in user_playlists|slice:"0:3" %}
  70. <div class="col-sm-6 col-lg-4 mb-4">
  71. <div class="card card-cover h-100 overflow-hidden text-white gradient-bg-3 rounded-5 shadow-lg" style="">
  72. <div class="d-flex flex-column h-100 p-5 pb-3 text-white text-shadow-1">
  73. <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>
  74. <ul class="d-flex list-unstyled mt-auto">
  75. <li class="me-auto">
  76. <h3>
  77. <i class="fas fa-thumbtack" style="color: red"></i>
  78. </h3>
  79. </li>
  80. <li class="d-flex align-items-center me-3">
  81. <small>by {{ playlist.channel_name }}</small>
  82. </li>
  83. <li class="d-flex align-items-center">
  84. <i class="fas fa-eye me-1"></i>
  85. <small>{{ playlist.num_of_accesses }} clicks</small>
  86. </li>
  87. </ul>
  88. </div>
  89. </div>
  90. </div>
  91. {% endfor %}
  92. <!-- FULL IMAGE CARD: might be useful
  93. <div class="col-sm-6 col-lg-4 mb-4">
  94. <div class="card">
  95. <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>
  96. </div>
  97. </div>
  98. -->
  99. </div>
  100. <br>
  101. <div class="row text-dark mt-0 align-items-center">
  102. <div class="col">
  103. <div class="card card-cover h-100 overflow-hidden text-white bg-dark rounded-5 shadow-lg" style="">
  104. <div class="d-flex flex-column h-100 p-5 pb-3 text-white text-shadow-1">
  105. <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>
  106. </div>
  107. </div>
  108. <!-- Implement later
  109. <div class="row mt-3">
  110. <div class="col">
  111. </div>
  112. <div class="col-6">
  113. <div class="card">
  114. <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">
  115. <div class="card-body">
  116. <div class="d-flex justify-content-center h1">
  117. <i class="fas fa-history"></i>
  118. </div>
  119. <div class="d-flex justify-content-center h1">
  120. YOUR
  121. </div>
  122. <div class="d-flex justify-content-center h1">
  123. ACTIVITY
  124. </div>
  125. </div>
  126. </a>
  127. </div>
  128. </div>
  129. <div class="col">
  130. </div>
  131. </div>
  132. -->
  133. </div>
  134. <div class="col-8">
  135. <div class="card bg-transparent border border-0 text-black">
  136. <div class="card-body">
  137. <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>
  138. {% if user_playlists %}
  139. <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
  140. {% for playlist in user_playlists|slice:"0:3" %}
  141. <div class="col">
  142. <div class="card overflow-auto" style="background-color: #4790c7;">
  143. <a href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item bg-transparent list-group-item-action" aria-current="true">
  144. <div class="card-body">
  145. <h5 class="card-title">
  146. #{{ forloop.counter }} <br><br>{{ playlist.name }}
  147. {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
  148. {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
  149. </h5>
  150. <small>
  151. <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
  152. <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
  153. <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
  154. </small>
  155. </div>
  156. </a>
  157. </div>
  158. </div>
  159. {% endfor %}
  160. </div>
  161. {% else %}
  162. <br>
  163. <h5>Nothing to see here... yet.</h5>
  164. {% endif %}
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. <br>
  170. {% if watching %}
  171. <div class="d-flex justify-content-between" id="continue-watching">
  172. <h3>
  173. <span style="border-bottom: 3px #e24949 dashed;">Continue Watching</span>
  174. <i class="fas fa-fire-alt ms-2" style="color: #d24646"></i>
  175. </h3>
  176. {% if watching.count > 5 %}
  177. <h3 class="ms-2 me-1">
  178. <a href="{% url 'all_playlists' 'watching' %}" style="text-decoration: none; color: #4675d2">
  179. <i class="fas fa-search" style="color: #4675d2"></i>
  180. </a>
  181. </h3>
  182. {% endif %}
  183. </div>
  184. <br>
  185. {% if watching.count > 4 %}
  186. <div class="container-fluid overflow-auto border border-5 rounded-3 border-primary p-3">
  187. <div class="row flex-row g-3 flex-nowrap">
  188. {% for playlist in watching %}
  189. <div class="col">
  190. <div class="card" style="background-color: #EFEFEF; width: 275px; height: auto">
  191. <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">
  192. <div class="card-body">
  193. <h5 class="card-title"><a href="{% url 'playlist' playlist.playlist_id %}" class="stretched-link" style="text-decoration: none; color: black">{{ playlist.name }}</a></h5>
  194. <p class="card-text">
  195. <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>
  196. {% if playlist.get_watch_time_left != "0secs." %}<span class="badge bg-dark text-white">{{ playlist.get_watch_time_left }} left</span>{% endif %}
  197. </p>
  198. <!--
  199. <p class="card-text">
  200. {% if playlist.tags.all %}
  201. <small>
  202. <i class="fas fa-tags fa-sm" style="color: black"></i>
  203. {% for tag in playlist.tags.all %}
  204. <span class="badge rounded-pill bg-primary mb-lg-1">
  205. {{ tag.name }}
  206. </span>
  207. {% endfor %}
  208. </small>
  209. {% endif %}
  210. </p>
  211. -->
  212. <p class="card-text"><small class="text-muted">Last watched {{ playlist.last_watched|naturaltime }}</small></p>
  213. </div>
  214. </div>
  215. </div>
  216. <!--
  217. <div class="col">
  218. <div class="card">
  219. <a style="background-color: #7e89c2;" href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item list-group-item-action" aria-current="true">
  220. <div class="card-body">
  221. <h5 class="card-title">
  222. {{ playlist.name }}
  223. {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
  224. {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
  225. </h5>
  226. <p class="card-text">
  227. <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>
  228. {% if playlist.get_watch_time_left != "0secs." %}<span class="badge bg-dark text-white">{{ playlist.get_watch_time_left }} left</span>{% endif %}
  229. </p>
  230. {% if playlist.tags.all %}
  231. <small>
  232. <i class="fas fa-tags fa-sm" style="color: yellow"></i>
  233. {% for tag in playlist.tags.all %}
  234. <span class="badge rounded-pill bg-primary mb-lg-1">
  235. {{ tag.name }}
  236. </span>
  237. {% endfor %}
  238. </small>
  239. {% endif %}
  240. </div>
  241. </a>
  242. </div>
  243. </div> -->
  244. <!--
  245. {% if forloop.counter == 3 %}
  246. {% if watching.count|add:"-3" != 0 %}
  247. <div class="col">
  248. <div class="card">
  249. <a style="background-color: #7e89c2;" href="{% url 'all_playlists' 'watching' %}" class="list-group-item list-group-item-action" aria-current="true">
  250. <div class="card-body">
  251. <p class="card-text">
  252. <h3>+ {{ watching.count|add:"-3" }} more</h3>
  253. </p>
  254. </div>
  255. </a>
  256. </div>
  257. </div>
  258. {% endif %}
  259. {% endif %}
  260. -->
  261. {% endfor %}
  262. </div>
  263. </div>
  264. {% else %}
  265. <div class="container-fluid overflow-auto border border-5 rounded-3 border-primary pb-4">
  266. <div class="row row-cols-1 row-cols-md-4 g-4 text-dark mt-0">
  267. {% for playlist in watching %}
  268. <div class="col">
  269. <div class="card" style="background-color: #EFEFEF;">
  270. <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">
  271. <div class="card-body">
  272. <h5 class="card-title"><a href="{% url 'playlist' playlist.playlist_id %}" class="stretched-link" style="text-decoration: none; color: black">{{ playlist.name }}</a></h5>
  273. <p class="card-text">
  274. <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>
  275. {% if playlist.get_watch_time_left != "0secs." %}<span class="badge bg-dark text-white">{{ playlist.get_watch_time_left }} left</span>{% endif %}
  276. </p>
  277. <p class="card-text"><small class="text-muted">Last watched {{ playlist.last_watched|naturaltime }}</small></p>
  278. </div>
  279. </div>
  280. </div>
  281. {% endfor %}
  282. </div>
  283. </div>
  284. {% endif %}
  285. <br>
  286. {% endif %}
  287. <br>
  288. <div class="row text-dark mt-0 d-flex justify-content-evenly">
  289. <div class="col">
  290. <h3><span style="border-bottom: 3px #e24949 dashed;">Recently Added</span> <i class="fas fa-plus-square" style="color:#972727;"></i></h3>
  291. {% if recently_added_playlists %}
  292. <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
  293. {% for playlist in recently_added_playlists %}
  294. <div class="col">
  295. <div class="card overflow-auto" style="background-color: #958a44;">
  296. <a href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item bg-transparent list-group-item-action" aria-current="true">
  297. <div class="card-body">
  298. <h5 class="card-title">
  299. {{ playlist.name }}
  300. {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
  301. {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
  302. </h5>
  303. <small>
  304. <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
  305. <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
  306. <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
  307. </small>
  308. </div>
  309. </a>
  310. </div>
  311. </div>
  312. {% endfor %}
  313. </div>
  314. {% else %}
  315. <br>
  316. <h5>You have no playlists ;-;</h5>
  317. {% endif %}
  318. </div>
  319. <div class="col">
  320. <h3><span style="border-bottom: 3px #e24949 dashed;">Recently Accessed</span> <i class="fas fa-redo fa-sm" style="color: #3c3fd2"></i></h3>
  321. {% if recently_accessed_playlists %}
  322. <div class="row row-cols-1 row-cols-md-3 g-4 text-dark mt-0">
  323. {% for playlist in recently_accessed_playlists %}
  324. <div class="col">
  325. <div class="card overflow-auto" style="background-color: #357779;">
  326. <a href="{% url 'playlist' playlist.playlist_id %}" class="list-group-item bg-transparent list-group-item-action" aria-current="true">
  327. <div class="card-body">
  328. <h5 class="card-title">
  329. {{ playlist.name }}
  330. {% if playlist.is_private_on_yt %}<small><span class="badge bg-light text-dark">Private</span></small> {% endif %}
  331. {% if playlist.is_from_yt %}<small><span class="badge bg-danger text-dark">YT</span></small> {% endif %}
  332. </h5>
  333. <small>
  334. <span class="badge bg-primary rounded-pill">{{ playlist.video_count }} videos</span>
  335. <span class="badge bg-primary rounded-pill">{{ playlist.playlist_duration }} </span>
  336. <span class="badge bg-secondary rounded-pill">{{ playlist.num_of_accesses }} clicks </span>
  337. </small>
  338. </div>
  339. </a>
  340. </div>
  341. </div>
  342. {% endfor %}
  343. </div>
  344. {% else %}
  345. <br>
  346. <h5>Nothing to see here... yet.</h5>
  347. {% endif %}
  348. </div>
  349. </div>
  350. <br>
  351. <br>
  352. <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>
  353. <script type="application/javascript">
  354. $(function () {
  355. var $overallPlaylists = $("#overall-playlists-distribution");
  356. $.ajax({
  357. url: $overallPlaylists.data("url"),
  358. success: function (data) {
  359. var ctx = $overallPlaylists[0].getContext("2d");
  360. var coloR = [];
  361. var dynamicColors = function() { // generate random color
  362. var r = Math.floor(Math.random() * 255);
  363. var g = Math.floor(Math.random() * 255);
  364. var b = Math.floor(Math.random() * 255);
  365. return "rgb(" + r + "," + g + "," + b + ")";
  366. };
  367. for (var i in data.labels) {
  368. if (data.labels)
  369. coloR.push(dynamicColors());
  370. }
  371. new Chart(ctx, {
  372. type: 'pie',
  373. data: {
  374. labels: data.labels,
  375. datasets: [{
  376. label: 'Playlist Types',
  377. backgroundColor: coloR,
  378. data: data.data
  379. }]
  380. },
  381. options: {
  382. responsive: true,
  383. legend: {
  384. position: 'right',
  385. display: true
  386. },
  387. title: {
  388. display: false,
  389. text: 'Video Count Distribution per Channel',
  390. fontSize: 20,
  391. fontColor: '#fff',
  392. },
  393. tooltips: {
  394. callbacks: {
  395. label: function(tooltipItem, object) {
  396. return object['labels'][tooltipItem['index']] + ": " + object['datasets'][0]['data'][tooltipItem['index']] + ' playlists';
  397. }
  398. }
  399. }
  400. }
  401. });
  402. }
  403. });
  404. var $watchingPlaylists = $("#watching-playlists-percent-distribution");
  405. $.ajax({
  406. url: $watchingPlaylists.data("url"),
  407. success: function (data) {
  408. var ctx = $watchingPlaylists[0].getContext("2d");
  409. var coloR = [];
  410. var dynamicColors = function() { // generate random color
  411. var r = Math.floor(Math.random() * 255);
  412. var g = Math.floor(Math.random() * 255);
  413. var b = Math.floor(Math.random() * 255);
  414. return "rgb(" + r + "," + g + "," + b + ")";
  415. };
  416. for (var i in data.labels) {
  417. if (data.labels)
  418. coloR.push(dynamicColors());
  419. }
  420. new Chart(ctx, {
  421. type: 'polarArea',
  422. data: {
  423. labels: data.labels,
  424. datasets: [{
  425. label: 'Playlist Types',
  426. backgroundColor: coloR,
  427. data: data.data
  428. }]
  429. },
  430. options: {
  431. scale: {
  432. reverse: false,
  433. ticks: {
  434. min: -10,
  435. max: 100,
  436. interval: 10,
  437. }
  438. },
  439. responsive: true,
  440. legend: {
  441. position: 'right',
  442. display: {% if watching.count <= 10 %}true{% else %}false{% endif %},
  443. },
  444. title: {
  445. display: false,
  446. },
  447. tooltips: {
  448. callbacks: {
  449. label: function(tooltipItem, object) {
  450. return object['labels'][tooltipItem['index']] + ": " + object['datasets'][0]['data'][tooltipItem['index']] + '% complete';
  451. }
  452. }
  453. }
  454. }
  455. });
  456. }
  457. });
  458. });
  459. </script>
  460. {% endif %}
  461. {% endblock %}