scrobble_list.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. {% extends "base.html" %}
  2. {% load humanize %}
  3. {% load static %}
  4. {% load naturalduration %}
  5. {% block head_extra %}
  6. <style>
  7. .container { margin-bottom:100px; }
  8. h2 { padding-top:20px; }
  9. .image-wrapper {
  10. contain: content;
  11. }
  12. .image-wrapper :hover {
  13. background:rgba(0,0,0,0.3);
  14. }
  15. .caption {
  16. position: fixed;
  17. top: 5px;
  18. left: 5px;
  19. padding: 3px;
  20. font-size: 90%;
  21. color:white;
  22. background:rgba(0,0,0,0.4);
  23. }
  24. .caption-medium {
  25. position: fixed;
  26. top: 5px;
  27. left: 5px;
  28. padding: 3px;
  29. font-size: 75%;
  30. color:white;
  31. background:rgba(0,0,0,0.4);
  32. }
  33. .caption-small {
  34. position: fixed;
  35. top: 5px;
  36. left: 5px;
  37. padding: 3px;
  38. font-size: 60%;
  39. color:white;
  40. background:rgba(0,0,0,0.4);
  41. }
  42. </style>
  43. {% endblock %}
  44. {% block content %}
  45. <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
  46. <div
  47. class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
  48. <h1 class="h2">Dashboard</h1>
  49. <div class="btn-toolbar mb-2 mb-md-0">
  50. {% if user.is_authenticated %}
  51. <div class="btn-group me-2">
  52. {% if user.profile.lastfm_username and not user.profile.lastfm_auto_import %}
  53. <form action="{% url 'scrobbles:lastfm-import' %}" method="get">
  54. <button type="submit" class="btn btn-sm btn-outline-secondary">Last.fm Sync</button>
  55. </form>
  56. {% endif %}
  57. <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal"
  58. data-bs-target="#importModal">Import</button>
  59. <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal"
  60. data-bs-target="#exportModal">Export</button>
  61. </div>
  62. {% endif %}
  63. <div class="dropdown">
  64. <button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle" id="graphDateButton"
  65. data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  66. <div data-feather="calendar"></div>
  67. This week
  68. </button>
  69. <div class="dropdown-menu" data-bs-toggle="#graphDataChange" aria-labelledby="graphDateButton">
  70. <a class="dropdown-item" href="#">This month</a>
  71. <a class="dropdown-item" href="#">This year</a>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. {% if not user.is_authenticated %}
  77. <p>Today <b>{{counts.today}}</b> | This Week <b>{{counts.week}}</b> | This Month <b>{{counts.month}}</b> | This Year <b>{{counts.year}}</b> | All Time <b>{{counts.alltime}}</b></p>
  78. <canvas class="my-4 w-100" id="myChart" width="900" height="300"></canvas>
  79. {% endif %}
  80. <div class="container">
  81. {% if user.is_authenticated %}
  82. <div class="row">
  83. {% include "scrobbles/_quick_resume.html" %}
  84. </div>
  85. <div class="row">
  86. <h2>Last Scrobbles</h2>
  87. <p>Today <b>{{counts.today}}</b> | This Week <b>{{counts.week}}</b> | This Month <b>{{counts.month}}</b> | This Year <b>{{counts.year}}</b> | All Time <b>{{counts.alltime}}</b></p>
  88. </div>
  89. <div class="row">
  90. <ul class="nav nav-tabs" id="myTab" role="tablist">
  91. <li class="nav-item" role="presentation">
  92. <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#latest-listened"
  93. type="button" role="tab" aria-controls="home" aria-selected="true">Tracks</button>
  94. </li>
  95. <li class="nav-item" role="presentation">
  96. <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#latest-watched"
  97. type="button" role="tab" aria-controls="profile" aria-selected="false">Videos</button>
  98. </li>
  99. <li class="nav-item" role="presentation">
  100. <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#latest-podcasted"
  101. type="button" role="tab" aria-controls="profile" aria-selected="false">Podcasts</button>
  102. </li>
  103. <li class="nav-item" role="presentation">
  104. <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#latest-sports"
  105. type="button" role="tab" aria-controls="profile" aria-selected="false">Sports</button>
  106. </li>
  107. <li class="nav-item" role="presentation">
  108. <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#latest-videogames"
  109. type="button" role="tab" aria-controls="profile" aria-selected="false">Video Games</button>
  110. </li>
  111. <li class="nav-item" role="presentation">
  112. <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#latest-boardgames"
  113. type="button" role="tab" aria-controls="profile" aria-selected="false">Board Games</button>
  114. </li>
  115. </ul>
  116. <div class="tab-content" id="myTabContent2">
  117. <div class="tab-pane fade show active" id="latest-listened" role="tabpanel"
  118. aria-labelledby="latest-listened-tab">
  119. <div class="table-responsive">
  120. <table class="table table-striped table-sm">
  121. <thead>
  122. <tr>
  123. <th scope="col">Time</th>
  124. <th scope="col">Album</th>
  125. <th scope="col">Track</th>
  126. <th scope="col">Artist</th>
  127. </tr>
  128. </thead>
  129. <tbody>
  130. {% for scrobble in object_list %}
  131. <tr>
  132. <td>{{scrobble.timestamp|naturaltime}}</td>
  133. {% if scrobble.track.album.cover_image %}
  134. <td><a href="{{scrobble.track.album.get_absolute_url}}"><img src="{{scrobble.track.album.cover_image_small.url}}" width=25 height=25 style="border:1px solid black;" /></aa></td>
  135. {% else %}
  136. <td><a href="{{scrobble.track.album.get_absolute_url}}">{{scrobble.track.album.name}}</a></td>
  137. {% endif %}
  138. <td><a href="{{scrobble.track.get_absolute_url }}">{{scrobble.track.title}}</a></td>
  139. <td><a href="{{scrobble.track.artist.get_absolute_url }}">{{scrobble.track.artist.name}}</aa></td>
  140. </tr>
  141. {% endfor %}
  142. </tbody>
  143. </table>
  144. </div>
  145. </div>
  146. <div class="tab-pane fade show" id="latest-watched" role="tabpanel"
  147. aria-labelledby="latest-watched-tab">
  148. <h2>Latest watched</h2>
  149. <div class="table-responsive">
  150. <table class="table table-striped table-sm">
  151. <thead>
  152. <tr>
  153. <th scope="col">Time</th>
  154. <th scope="col">Cover</th>
  155. <th scope="col">Title</th>
  156. <th scope="col">Series</th>
  157. </tr>
  158. </thead>
  159. <tbody>
  160. {% for scrobble in video_scrobble_list %}
  161. <tr>
  162. <td>{{scrobble.timestamp|naturaltime}}</td>
  163. <td><img src="{{scrobble.media_obj.cover_medium.url}}" width=25 height=25 style="border:1px solid black;" /></td>
  164. <td><a href="{{scrobble.video.get_absolute_url }}">{% if scrobble.video.tv_series%}S{{scrobble.video.season_number}}E{{scrobble.video.episode_number}} -{%endif %} {{scrobble.video.title}}</a></td>
  165. <td><a href="{{scrobble.video.tv_series.get_absolute_url }}">{% if scrobble.video.tv_series %}{{scrobble.video.tv_series}}</a>{% endif %}
  166. </td>
  167. </tr>
  168. {% endfor %}
  169. </tbody>
  170. </table>
  171. </div>
  172. </div>
  173. <div class="tab-pane fade show" id="latest-sports" role="tabpanel" aria-labelledby="latest-sports-tab">
  174. <h2>Latest Sports</h2>
  175. <div class="table-responsive">
  176. <table class="table table-striped table-sm">
  177. <thead>
  178. <tr>
  179. <th scope="col">Date</th>
  180. <th scope="col">Title</th>
  181. <th scope="col">Round</th>
  182. <th scope="col">League</th>
  183. </tr>
  184. </thead>
  185. <tbody>
  186. {% for scrobble in sport_scrobble_list %}
  187. <tr>
  188. <td>{{scrobble.timestamp|naturaltime}}</td>
  189. <td>{{scrobble.sport_event.title}}</td>
  190. <td>{{scrobble.sport_event.round.name}}</td>
  191. <td>{{scrobble.sport_event.round.season.league}}</td>
  192. </tr>
  193. {% endfor %}
  194. </tbody>
  195. </table>
  196. </div>
  197. </div>
  198. <div class="tab-pane fade show" id="latest-podcasted" role="tabpanel"
  199. aria-labelledby="latest-podcasted-tab">
  200. <h2>Latest Podcasted</h2>
  201. <div class="table-responsive">
  202. <table class="table table-striped table-sm">
  203. <thead>
  204. <tr>
  205. <th scope="col">Date</th>
  206. <th scope="col">Title</th>
  207. <th scope="col">Podcast</th>
  208. </tr>
  209. </thead>
  210. <tbody>
  211. {% for scrobble in podcast_scrobble_list %}
  212. <tr>
  213. <td>{{scrobble.timestamp|naturaltime}}</td>
  214. <td>{{scrobble.podcast_episode.title}}</td>
  215. <td>{{scrobble.podcast_episode.podcast}}</td>
  216. </tr>
  217. {% endfor %}
  218. </tbody>
  219. </table>
  220. </div>
  221. </div>
  222. <div class="tab-pane fade show" id="latest-videogames" role="tabpanel"
  223. aria-labelledby="latest-videogames-tab">
  224. <h2>Latest Video Games</h2>
  225. <div class="table-responsive">
  226. <table class="table table-striped table-sm">
  227. <thead>
  228. <tr>
  229. <th scope="col">Date</th>
  230. <th scope="col">Cover</th>
  231. <th scope="col">Title</th>
  232. <th scope="col">Time played (mins)</th>
  233. <th scope="col">Percent complete</th>
  234. </tr>
  235. </thead>
  236. <tbody>
  237. {% for scrobble in videogame_scrobble_list %}
  238. <tr>
  239. <td>{{scrobble.timestamp|naturaltime}}</td>
  240. {% if scrobble.videogame_screenshot %}
  241. <td><img src="{{scrobble.videogame_screenshot_medium.url}}" width=25 height=25 style="border:1px solid black;" /></td>
  242. {% else %}
  243. <td><img src="{{scrobble.media_obj.cover_medium.url}}" width=25 height=25 style="border:1px solid black;" /></td>
  244. {% endif %}
  245. <td><a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a></td>
  246. <td>{{scrobble.playback_position_seconds|natural_duration}}</td>
  247. <td>{{scrobble.percent_played}}</td>
  248. </tr>
  249. {% endfor %}
  250. </tbody>
  251. </table>
  252. </div>
  253. </div>
  254. <div class="tab-pane fade show" id="latest-boardgames" role="tabpanel"
  255. aria-labelledby="latest-boardgames-tab">
  256. <h2>Latest Board Games</h2>
  257. <div class="table-responsive">
  258. <table class="table table-striped table-sm">
  259. <thead>
  260. <tr>
  261. <th scope="col">Date</th>
  262. <th scope="col">Cover</th>
  263. <th scope="col">Title</th>
  264. <th scope="col">Time played (mins)</th>
  265. </tr>
  266. </thead>
  267. <tbody>
  268. {% for scrobble in boardgame_scrobble_list %}
  269. <tr>
  270. <td>{{scrobble.timestamp|naturaltime}}</td>
  271. <td><img src="{{scrobble.media_obj.cover_medium.url}}" width=25 height=25 style="border:1px solid black;" /></td>
  272. <td><a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a></td>
  273. <td>{{scrobble.playback_position_seconds|natural_duration}}</td>
  274. </tr>
  275. {% endfor %}
  276. </tbody>
  277. </table>
  278. </div>
  279. </div>
  280. </div>
  281. {% endif %}
  282. </div>
  283. </main>
  284. <div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="importModalLabel"
  285. aria-hidden="true">
  286. <div class="modal-dialog" role="document">
  287. <div class="modal-content">
  288. <div class="modal-header">
  289. <h5 class="modal-title" id="importModalLabel">Import scrobbles</h5>
  290. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  291. <div aria-hidden="true">&times;</div>
  292. </button>
  293. </div>
  294. <form action="{% url 'scrobbles:audioscrobbler-file-upload' %}" method="post" enctype="multipart/form-data">
  295. <div class="modal-body">
  296. {% csrf_token %}
  297. <div class="form-group">
  298. <label for="tsv_file" class="col-form-label">Audioscrobbler TSV file:</label>
  299. <input type="file" name="tsv_file" class="form-control" id="id_tsv_file">
  300. </div>
  301. </div>
  302. <div class="modal-footer">
  303. <button type="submit" class="btn btn-primary">Import</button>
  304. </div>
  305. </form>
  306. <form action="{% url 'scrobbles:koreader-file-upload' %}" method="post" enctype="multipart/form-data">
  307. <div class="modal-body">
  308. {% csrf_token %}
  309. <div class="form-group">
  310. <label for="tsv_file" class="col-form-label">KOReader sqlite file:</label>
  311. <input type="file" name="sqlite_file" class="form-control" id="id_sqlite_file">
  312. </div>
  313. </div>
  314. <div class="modal-footer">
  315. <button type="submit" class="btn btn-primary">Import</button>
  316. </div>
  317. </form>
  318. </div>
  319. </div>
  320. </div>
  321. <div class="modal fade" id="exportModal" tabindex="-1" role="dialog" aria-labelledby="exportModalLabel"
  322. aria-hidden="true">
  323. <div class="modal-dialog" role="document">
  324. <div class="modal-content">
  325. <div class="modal-header">
  326. <h5 class="modal-title" id="exportModalLabel">Export scrobbles</h5>
  327. <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
  328. <div aria-hidden="true">&times;</div>
  329. </button>
  330. </div>
  331. <form action="{% url 'scrobbles:export' %}" method="get">
  332. <div class="modal-body">
  333. {% csrf_token %}
  334. <div class="form-group">
  335. {{export_form.as_div}}
  336. </div>
  337. </div>
  338. <div class="modal-footer">
  339. <button type="submit" class="btn btn-primary">Export</button>
  340. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  341. </div>
  342. </form>
  343. </div>
  344. </div>
  345. </div>
  346. {% endblock %}
  347. {% block extra_js %}
  348. <script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
  349. <script>
  350. /* globals Chart:false, feather:false */
  351. (function () {
  352. 'use strict'
  353. feather.replace({ 'aria-hidden': 'true' })
  354. // Graphs
  355. var ctx = document.getElementById('myChart')
  356. // eslint-disable-next-line no-unused-vars
  357. var myChart = new Chart(ctx, {
  358. type: 'line',
  359. data: {
  360. labels: [
  361. {% for day in weekly_data.keys %}
  362. "{{day}}"{% if not forloop.last %},{% endif %}
  363. {% endfor %}
  364. ],
  365. datasets: [{
  366. data: [
  367. {% for count in weekly_data.values %}
  368. {{count}}{% if not forloop.last %},{% endif %}
  369. {% endfor %}
  370. ],
  371. lineTension: 0,
  372. backgroundColor: 'transparent',
  373. borderColor: '#007bf0',
  374. borderWidth: 4,
  375. pointBackgroundColor: '#007bff'
  376. }]
  377. },
  378. options: {
  379. scales: {
  380. yAxes: [{
  381. ticks: {
  382. beginAtZero: true
  383. }
  384. }]
  385. },
  386. legend: {
  387. display: false
  388. }
  389. }
  390. })
  391. })()
  392. </script>
  393. {% endblock %}