Videos.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <div class="admin-tab container">
  3. <page-metadata title="Admin | YouTube | Videos" />
  4. <div class="card tab-info">
  5. <div class="info-row">
  6. <h1>YouTube Videos</h1>
  7. <p>Manage YouTube video cache</p>
  8. </div>
  9. <div class="button-row">
  10. <run-job-dropdown :jobs="jobs" />
  11. </div>
  12. </div>
  13. <advanced-table
  14. :column-default="columnDefault"
  15. :columns="columns"
  16. :filters="filters"
  17. :events="events"
  18. data-action="youtube.getVideos"
  19. name="admin-youtube-videos"
  20. :max-width="1140"
  21. :bulk-actions="{ width: 150 }"
  22. >
  23. <template #column-options="slotProps">
  24. <div class="row-options">
  25. <button
  26. class="button is-primary icon-with-button material-icons"
  27. @click="
  28. openModal({
  29. modal: 'viewYoutubeVideo',
  30. data: {
  31. videoId: slotProps.item._id
  32. }
  33. })
  34. "
  35. :disabled="slotProps.item.removed"
  36. content="View Video"
  37. v-tippy
  38. >
  39. open_in_full
  40. </button>
  41. <button
  42. class="button is-primary icon-with-button material-icons"
  43. @click="editOne(slotProps.item)"
  44. :disabled="slotProps.item.removed"
  45. content="Create/edit song from video"
  46. v-tippy
  47. >
  48. music_note
  49. </button>
  50. <button
  51. class="button is-danger icon-with-button material-icons"
  52. @click.prevent="
  53. confirmAction({
  54. message:
  55. 'Removing this video will remove it from all playlists and cause a ratings recalculation.',
  56. action: 'removeVideos',
  57. params: slotProps.item._id
  58. })
  59. "
  60. :disabled="slotProps.item.removed"
  61. content="Delete Video"
  62. v-tippy
  63. >
  64. delete_forever
  65. </button>
  66. </div>
  67. </template>
  68. <template #column-thumbnailImage="slotProps">
  69. <song-thumbnail class="song-thumbnail" :song="slotProps.item" />
  70. </template>
  71. <template #column-youtubeId="slotProps">
  72. <a
  73. :href="
  74. 'https://www.youtube.com/watch?v=' +
  75. `${slotProps.item.youtubeId}`
  76. "
  77. target="_blank"
  78. >
  79. {{ slotProps.item.youtubeId }}
  80. </a>
  81. </template>
  82. <template #column-_id="slotProps">
  83. <span :title="slotProps.item._id">{{
  84. slotProps.item._id
  85. }}</span>
  86. </template>
  87. <template #column-title="slotProps">
  88. <span :title="slotProps.item.title">{{
  89. slotProps.item.title
  90. }}</span>
  91. </template>
  92. <template #column-author="slotProps">
  93. <span :title="slotProps.item.author">{{
  94. slotProps.item.author
  95. }}</span>
  96. </template>
  97. <template #column-duration="slotProps">
  98. <span :title="slotProps.item.duration">{{
  99. slotProps.item.duration
  100. }}</span>
  101. </template>
  102. <template #column-createdAt="slotProps">
  103. <span :title="new Date(slotProps.item.createdAt)">{{
  104. getDateFormatted(slotProps.item.createdAt)
  105. }}</span>
  106. </template>
  107. <template #bulk-actions="slotProps">
  108. <div class="bulk-actions">
  109. <i
  110. class="material-icons create-songs-icon"
  111. @click.prevent="editMany(slotProps.item)"
  112. content="Create/edit songs from videos"
  113. v-tippy
  114. tabindex="0"
  115. >
  116. music_note
  117. </i>
  118. <i
  119. class="material-icons import-album-icon"
  120. @click.prevent="importAlbum(slotProps.item)"
  121. content="Import album from videos"
  122. v-tippy
  123. tabindex="0"
  124. >
  125. album
  126. </i>
  127. <i
  128. class="material-icons delete-icon"
  129. @click.prevent="
  130. confirmAction({
  131. message:
  132. 'Removing these videos will remove them from all playlists and cause a ratings recalculation.',
  133. action: 'removeVideos',
  134. params: slotProps.item.map(video => video._id)
  135. })
  136. "
  137. content="Delete Videos"
  138. v-tippy
  139. tabindex="0"
  140. >
  141. delete_forever
  142. </i>
  143. </div>
  144. </template>
  145. </advanced-table>
  146. </div>
  147. </template>
  148. <script>
  149. import { mapActions, mapGetters } from "vuex";
  150. import Toast from "toasters";
  151. import AdvancedTable from "@/components/AdvancedTable.vue";
  152. import RunJobDropdown from "@/components/RunJobDropdown.vue";
  153. export default {
  154. components: {
  155. AdvancedTable,
  156. RunJobDropdown
  157. },
  158. data() {
  159. return {
  160. columnDefault: {
  161. sortable: true,
  162. hidable: true,
  163. defaultVisibility: "shown",
  164. draggable: true,
  165. resizable: true,
  166. minWidth: 200,
  167. maxWidth: 600
  168. },
  169. columns: [
  170. {
  171. name: "options",
  172. displayName: "Options",
  173. properties: ["_id", "youtubeId"],
  174. sortable: false,
  175. hidable: false,
  176. resizable: false,
  177. minWidth: 129,
  178. defaultWidth: 129
  179. },
  180. {
  181. name: "thumbnailImage",
  182. displayName: "Thumb",
  183. properties: ["youtubeId"],
  184. sortable: false,
  185. minWidth: 75,
  186. defaultWidth: 75,
  187. maxWidth: 75,
  188. resizable: false
  189. },
  190. {
  191. name: "youtubeId",
  192. displayName: "YouTube ID",
  193. properties: ["youtubeId"],
  194. sortProperty: "youtubeId",
  195. minWidth: 120,
  196. defaultWidth: 120
  197. },
  198. {
  199. name: "_id",
  200. displayName: "Video ID",
  201. properties: ["_id"],
  202. sortProperty: "_id",
  203. minWidth: 215,
  204. defaultWidth: 215
  205. },
  206. {
  207. name: "title",
  208. displayName: "Title",
  209. properties: ["title"],
  210. sortProperty: "title"
  211. },
  212. {
  213. name: "author",
  214. displayName: "Author",
  215. properties: ["author"],
  216. sortProperty: "author"
  217. },
  218. {
  219. name: "duration",
  220. displayName: "Duration",
  221. properties: ["duration"],
  222. sortProperty: "duration",
  223. defaultWidth: 200
  224. },
  225. {
  226. name: "createdAt",
  227. displayName: "Created At",
  228. properties: ["createdAt"],
  229. sortProperty: "createdAt",
  230. defaultWidth: 200,
  231. defaultVisibility: "hidden"
  232. }
  233. ],
  234. filters: [
  235. {
  236. name: "_id",
  237. displayName: "Video ID",
  238. property: "_id",
  239. filterTypes: ["exact"],
  240. defaultFilterType: "exact"
  241. },
  242. {
  243. name: "youtubeId",
  244. displayName: "YouTube ID",
  245. property: "youtubeId",
  246. filterTypes: ["contains", "exact", "regex"],
  247. defaultFilterType: "contains"
  248. },
  249. {
  250. name: "title",
  251. displayName: "Title",
  252. property: "title",
  253. filterTypes: ["contains", "exact", "regex"],
  254. defaultFilterType: "contains"
  255. },
  256. {
  257. name: "author",
  258. displayName: "Author",
  259. property: "author",
  260. filterTypes: ["contains", "exact", "regex"],
  261. defaultFilterType: "contains"
  262. },
  263. {
  264. name: "duration",
  265. displayName: "Duration",
  266. property: "duration",
  267. filterTypes: [
  268. "numberLesserEqual",
  269. "numberLesser",
  270. "numberGreater",
  271. "numberGreaterEqual",
  272. "numberEquals"
  273. ],
  274. defaultFilterType: "numberLesser"
  275. },
  276. {
  277. name: "createdAt",
  278. displayName: "Created At",
  279. property: "createdAt",
  280. filterTypes: ["datetimeBefore", "datetimeAfter"],
  281. defaultFilterType: "datetimeBefore"
  282. },
  283. {
  284. name: "importJob",
  285. displayName: "Import job",
  286. property: "importJob",
  287. filterTypes: ["special"],
  288. defaultFilterType: "special"
  289. }
  290. ],
  291. events: {
  292. adminRoom: "youtubeVideos",
  293. updated: {
  294. event: "admin.youtubeVideo.updated",
  295. id: "youtubeVideo._id",
  296. item: "youtubeVideo"
  297. },
  298. removed: {
  299. event: "admin.youtubeVideo.removed",
  300. id: "videoId"
  301. }
  302. },
  303. jobs: [
  304. {
  305. name: "Recalculate all ratings",
  306. socket: "media.recalculateAllRatings"
  307. }
  308. ]
  309. };
  310. },
  311. computed: {
  312. ...mapGetters({
  313. socket: "websockets/getSocket"
  314. })
  315. },
  316. methods: {
  317. editOne(song) {
  318. this.openModal({
  319. modal: "editSong",
  320. data: { song }
  321. });
  322. },
  323. editMany(selectedRows) {
  324. if (selectedRows.length === 1) this.editOne(selectedRows[0]);
  325. else {
  326. const songs = selectedRows.map(row => ({
  327. youtubeId: row.youtubeId
  328. }));
  329. this.openModal({ modal: "editSongs", data: { songs } });
  330. }
  331. },
  332. importAlbum(selectedRows) {
  333. const youtubeIds = selectedRows.map(({ youtubeId }) => youtubeId);
  334. this.socket.dispatch(
  335. "songs.getSongsFromYoutubeIds",
  336. youtubeIds,
  337. res => {
  338. if (res.status === "success") {
  339. this.openModal({
  340. modal: "importAlbum",
  341. data: { songs: res.data.songs }
  342. });
  343. } else new Toast("Could not get songs.");
  344. }
  345. );
  346. },
  347. removeVideos(videoIds) {
  348. let id;
  349. let title;
  350. this.socket.dispatch("youtube.removeVideos", videoIds, {
  351. cb: () => {},
  352. onProgress: res => {
  353. if (res.status === "started") {
  354. id = res.id;
  355. title = res.title;
  356. }
  357. if (id)
  358. this.setJob({
  359. id,
  360. name: title,
  361. ...res
  362. });
  363. }
  364. });
  365. },
  366. getDateFormatted(createdAt) {
  367. const date = new Date(createdAt);
  368. const year = date.getFullYear();
  369. const month = `${date.getMonth() + 1}`.padStart(2, 0);
  370. const day = `${date.getDate()}`.padStart(2, 0);
  371. const hour = `${date.getHours()}`.padStart(2, 0);
  372. const minute = `${date.getMinutes()}`.padStart(2, 0);
  373. return `${year}-${month}-${day} ${hour}:${minute}`;
  374. },
  375. confirmAction({ message, action, params }) {
  376. this.openModal({
  377. modal: "confirm",
  378. data: {
  379. message,
  380. action,
  381. params,
  382. onCompleted: this.handleConfirmed
  383. }
  384. });
  385. },
  386. handleConfirmed({ action, params }) {
  387. if (typeof this[action] === "function") {
  388. if (params) this[action](params);
  389. else this[action]();
  390. }
  391. },
  392. ...mapActions("modalVisibility", ["openModal"])
  393. }
  394. };
  395. </script>
  396. <style lang="less" scoped>
  397. :deep(.song-thumbnail) {
  398. width: 50px;
  399. height: 50px;
  400. min-width: 50px;
  401. min-height: 50px;
  402. margin: 0 auto;
  403. }
  404. </style>