ImportPlaylists.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <script setup lang="ts">
  2. import { useStore } from "vuex";
  3. import { computed } from "vue";
  4. import Toast from "toasters";
  5. import { useModalState } from "@/vuex_helpers";
  6. import useSearchYoutube from "@/composables/useSearchYoutube";
  7. const props = defineProps({
  8. modalUuid: { type: String, default: "" }
  9. });
  10. const store = useStore();
  11. const { socket } = store.state.websockets;
  12. const modalState = useModalState("modals/editPlaylist/MODAL_UUID", {
  13. modalUuid: props.modalUuid
  14. });
  15. const playlist = computed(() => modalState.playlist);
  16. const setJob = payload => store.dispatch("longJobs/setJob", payload);
  17. const { youtubeSearch } = useSearchYoutube();
  18. const importPlaylist = () => {
  19. let id;
  20. let title;
  21. // import query is blank
  22. if (!youtubeSearch.value.playlist.query)
  23. return new Toast("Please enter a YouTube playlist URL.");
  24. const regex = /[\\?&]list=([^&#]*)/;
  25. const splitQuery = regex.exec(youtubeSearch.value.playlist.query);
  26. if (!splitQuery) {
  27. return new Toast({
  28. content: "Please enter a valid YouTube playlist URL.",
  29. timeout: 4000
  30. });
  31. }
  32. return socket.dispatch(
  33. "playlists.addSetToPlaylist",
  34. youtubeSearch.value.playlist.query,
  35. playlist.value._id,
  36. youtubeSearch.value.playlist.isImportingOnlyMusic,
  37. {
  38. cb: () => {},
  39. onProgress: res => {
  40. if (res.status === "started") {
  41. id = res.id;
  42. title = res.title;
  43. }
  44. if (id)
  45. setJob({
  46. id,
  47. name: title,
  48. ...res
  49. });
  50. }
  51. }
  52. );
  53. };
  54. </script>
  55. <template>
  56. <div class="youtube-tab section">
  57. <label class="label"> Search for a playlist from YouTube </label>
  58. <div class="control is-grouped input-with-button">
  59. <p class="control is-expanded">
  60. <input
  61. class="input"
  62. type="text"
  63. placeholder="Enter YouTube Playlist URL here..."
  64. v-model="youtubeSearch.playlist.query"
  65. @keyup.enter="importPlaylist()"
  66. />
  67. </p>
  68. <p class="control has-addons">
  69. <span class="select" id="playlist-import-type">
  70. <select
  71. v-model="youtubeSearch.playlist.isImportingOnlyMusic"
  72. >
  73. <option :value="false">Import all</option>
  74. <option :value="true">Import only music</option>
  75. </select>
  76. </span>
  77. <button
  78. class="button is-info"
  79. @click.prevent="importPlaylist()"
  80. >
  81. <i class="material-icons icon-with-button">publish</i>Import
  82. </button>
  83. </p>
  84. </div>
  85. </div>
  86. </template>
  87. <style lang="less" scoped>
  88. #playlist-import-type select {
  89. border-radius: 0;
  90. }
  91. @media screen and (max-width: 1300px) {
  92. .youtube-tab #song-query-results,
  93. .section {
  94. max-width: 100% !important;
  95. }
  96. }
  97. </style>