ImportPlaylists.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="youtube-tab section">
  3. <label class="label">
  4. Search for a playlist from YouTube
  5. </label>
  6. <div class="control is-grouped input-with-button">
  7. <p class="control is-expanded">
  8. <input
  9. class="input"
  10. type="text"
  11. placeholder="Enter YouTube Playlist URL here..."
  12. v-model="search.playlist.query"
  13. @keyup.enter="importPlaylist()"
  14. />
  15. </p>
  16. <p class="control has-addons">
  17. <span class="select" id="playlist-import-type">
  18. <select v-model="search.playlist.isImportingOnlyMusic">
  19. <option :value="false">Import all</option>
  20. <option :value="true">
  21. Import only music
  22. </option>
  23. </select>
  24. </span>
  25. <a
  26. class="button is-info"
  27. @click.prevent="importPlaylist()"
  28. href="#"
  29. ><i class="material-icons icon-with-button">publish</i
  30. >Import</a
  31. >
  32. </p>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import { mapState, mapGetters } from "vuex";
  38. import Toast from "toasters";
  39. import SearchYoutube from "@/mixins/SearchYoutube.vue";
  40. export default {
  41. mixins: [SearchYoutube],
  42. data() {
  43. return {};
  44. },
  45. computed: {
  46. ...mapState("modals/editPlaylist", {
  47. playlist: state => state.playlist
  48. }),
  49. ...mapGetters({
  50. socket: "websockets/getSocket"
  51. })
  52. },
  53. methods: {
  54. importPlaylist() {
  55. let isImportingPlaylist = true;
  56. // import query is blank
  57. if (!this.search.playlist.query)
  58. return new Toast("Please enter a YouTube playlist URL.");
  59. const regex = new RegExp(`[\\?&]list=([^&#]*)`);
  60. const splitQuery = regex.exec(this.search.playlist.query);
  61. if (!splitQuery) {
  62. return new Toast({
  63. content: "Please enter a valid YouTube playlist URL.",
  64. timeout: 4000
  65. });
  66. }
  67. // don't give starting import message instantly in case of instant error
  68. setTimeout(() => {
  69. if (isImportingPlaylist) {
  70. new Toast(
  71. "Starting to import your playlist. This can take some time to do."
  72. );
  73. }
  74. }, 750);
  75. return this.socket.dispatch(
  76. "playlists.addSetToPlaylist",
  77. this.search.playlist.query,
  78. this.playlist._id,
  79. this.search.playlist.isImportingOnlyMusic,
  80. res => {
  81. new Toast({ content: res.message, timeout: 20000 });
  82. if (res.status === "success") {
  83. isImportingPlaylist = false;
  84. if (this.search.playlist.isImportingOnlyMusic) {
  85. new Toast({
  86. content: `${res.data.stats.songsInPlaylistTotal} of the ${res.data.stats.videosInPlaylistTotal} videos in the playlist were songs.`,
  87. timeout: 20000
  88. });
  89. }
  90. }
  91. }
  92. );
  93. }
  94. }
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. #playlist-import-type select {
  99. border-radius: 0;
  100. }
  101. @media screen and (max-width: 1300px) {
  102. .youtube-tab #song-query-results,
  103. .section {
  104. max-width: 100% !important;
  105. }
  106. }
  107. </style>