AddSongs.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, watch } from "vue";
  3. import { storeToRefs } from "pinia";
  4. import { useSearchYoutube } from "@/composables/useSearchYoutube";
  5. import { useSearchMusare } from "@/composables/useSearchMusare";
  6. import { useYoutubeDirect } from "@/composables/useYoutubeDirect";
  7. import { useSoundcloudDirect } from "@/composables/useSoundcloudDirect";
  8. import { useSpotifyDirect } from "@/composables/useSpotifyDirect";
  9. import { useConfigStore } from "@/stores/config";
  10. import { useEditPlaylistStore } from "@/stores/editPlaylist";
  11. const SongItem = defineAsyncComponent(
  12. () => import("@/components/SongItem.vue")
  13. );
  14. const SearchQueryItem = defineAsyncComponent(
  15. () => import("@/components/SearchQueryItem.vue")
  16. );
  17. const props = defineProps({
  18. modalUuid: { type: String, required: true }
  19. });
  20. const configStore = useConfigStore();
  21. const editPlaylistStore = useEditPlaylistStore({ modalUuid: props.modalUuid });
  22. const { playlist } = storeToRefs(editPlaylistStore);
  23. const {
  24. youtubeSearch,
  25. searchForSongs,
  26. loadMoreSongs,
  27. addYouTubeSongToPlaylist
  28. } = useSearchYoutube();
  29. const {
  30. musareSearch,
  31. resultsLeftCount,
  32. nextPageResultsCount,
  33. searchForMusareSongs,
  34. addMusareSongToPlaylist
  35. } = useSearchMusare();
  36. const { youtubeDirect, addToPlaylist } = useYoutubeDirect();
  37. const { soundcloudDirect, addToPlaylist: soundcloudAddToPlaylist } =
  38. useSoundcloudDirect();
  39. const { spotifyDirect, addToPlaylist: spotifyAddToPlaylist } =
  40. useSpotifyDirect();
  41. watch(
  42. () => youtubeSearch.value.songs.results,
  43. songs => {
  44. songs.forEach((searchItem, index) =>
  45. playlist.value.songs.find(song => {
  46. if (
  47. song.mediaSource === "youtube:" &&
  48. song.mediaSource.split(":")[1] === searchItem.id
  49. )
  50. youtubeSearch.value.songs.results[index].isAddedToQueue =
  51. true;
  52. return (
  53. song.mediaSource === "youtube:" &&
  54. song.mediaSource.split(":")[1] === searchItem.id
  55. );
  56. })
  57. );
  58. }
  59. );
  60. watch(
  61. () => musareSearch.value.results,
  62. songs => {
  63. songs.forEach((searchItem, index) =>
  64. playlist.value.songs.find(song => {
  65. if (song._id === searchItem._id)
  66. musareSearch.value.results[index].isAddedToQueue = true;
  67. return song._id === searchItem._id;
  68. })
  69. );
  70. }
  71. );
  72. watch(
  73. () => playlist.value.songs,
  74. () => {
  75. youtubeSearch.value.songs.results.forEach((searchItem, index) =>
  76. playlist.value.songs.find(song => {
  77. youtubeSearch.value.songs.results[index].isAddedToQueue = false;
  78. if (
  79. song.mediaSource === "youtube:" &&
  80. song.mediaSource.split(":")[1] === searchItem.id
  81. )
  82. youtubeSearch.value.songs.results[index].isAddedToQueue =
  83. true;
  84. return (
  85. song.mediaSource === "youtube:" &&
  86. song.mediaSource.split(":")[1] === searchItem.id
  87. );
  88. })
  89. );
  90. musareSearch.value.results.forEach((searchItem, index) =>
  91. playlist.value.songs.find(song => {
  92. musareSearch.value.results[index].isAddedToQueue = false;
  93. if (
  94. song.mediaSource === "youtube:" &&
  95. song.mediaSource.split(":")[1] === searchItem.youtubeId
  96. )
  97. musareSearch.value.results[index].isAddedToQueue = true;
  98. return (
  99. song.mediaSource === "youtube:" &&
  100. song.mediaSource.split(":")[1] === searchItem.youtubeId
  101. );
  102. })
  103. );
  104. }
  105. );
  106. </script>
  107. <template>
  108. <div class="youtube-tab section">
  109. <div>
  110. <label class="label">
  111. Search for a song on {{ configStore.get("sitename") }}</label
  112. >
  113. <div class="control is-grouped input-with-button">
  114. <p class="control is-expanded">
  115. <input
  116. class="input"
  117. type="text"
  118. placeholder="Enter your song query here..."
  119. v-model="musareSearch.query"
  120. @keyup.enter="searchForMusareSongs(1)"
  121. />
  122. </p>
  123. <p class="control">
  124. <a class="button is-info" @click="searchForMusareSongs(1)"
  125. ><i class="material-icons icon-with-button">search</i
  126. >Search</a
  127. >
  128. </p>
  129. </div>
  130. <div
  131. v-if="musareSearch.results.length > 0"
  132. class="song-query-results"
  133. >
  134. <song-item
  135. v-for="(song, index) in musareSearch.results"
  136. :key="song._id"
  137. :song="song"
  138. >
  139. <template #actions>
  140. <transition
  141. name="musare-search-query-actions"
  142. mode="out-in"
  143. >
  144. <i
  145. v-if="song.isAddedToQueue"
  146. class="material-icons added-to-playlist-icon"
  147. content="Song is already in playlist"
  148. v-tippy
  149. >done</i
  150. >
  151. <i
  152. v-else
  153. class="material-icons add-to-playlist-icon"
  154. content="Add Song to Playlist"
  155. v-tippy
  156. @click="
  157. addMusareSongToPlaylist(
  158. playlist._id,
  159. song.mediaSource,
  160. index
  161. )
  162. "
  163. >playlist_add</i
  164. >
  165. </transition>
  166. </template>
  167. </song-item>
  168. <button
  169. v-if="resultsLeftCount > 0"
  170. class="button is-primary load-more-button"
  171. @click="searchForMusareSongs(musareSearch.page + 1)"
  172. >
  173. Load {{ nextPageResultsCount }} more results
  174. </button>
  175. </div>
  176. </div>
  177. <br v-if="musareSearch.results.length > 0" />
  178. <label class="label"> Add a YouTube song from a URL </label>
  179. <div class="control is-grouped input-with-button">
  180. <p class="control is-expanded">
  181. <input
  182. class="input"
  183. type="text"
  184. placeholder="Enter your YouTube song URL here..."
  185. v-model="youtubeDirect"
  186. @keyup.enter="addToPlaylist(playlist._id)"
  187. />
  188. </p>
  189. <p class="control">
  190. <a class="button is-info" @click="addToPlaylist(playlist._id)"
  191. ><i class="material-icons icon-with-button">add</i>Add</a
  192. >
  193. </p>
  194. </div>
  195. <div v-if="!configStore.get('experimental.disable_youtube_search')">
  196. <label class="label"> Search for a song from YouTube </label>
  197. <div class="control is-grouped input-with-button">
  198. <p class="control is-expanded">
  199. <input
  200. class="input"
  201. type="text"
  202. placeholder="Enter your YouTube query here..."
  203. v-model="youtubeSearch.songs.query"
  204. autofocus
  205. @keyup.enter="searchForSongs()"
  206. />
  207. </p>
  208. <p class="control">
  209. <button
  210. class="button is-info"
  211. @click.prevent="searchForSongs()"
  212. >
  213. <i class="material-icons icon-with-button">search</i
  214. >Search
  215. </button>
  216. </p>
  217. </div>
  218. <div
  219. v-if="youtubeSearch.songs.results.length > 0"
  220. class="song-query-results"
  221. >
  222. <search-query-item
  223. v-for="(result, index) in youtubeSearch.songs.results"
  224. :key="result.id"
  225. :result="result"
  226. >
  227. <template #actions>
  228. <transition
  229. name="youtube-search-query-actions"
  230. mode="out-in"
  231. >
  232. <i
  233. v-if="result.isAddedToQueue"
  234. class="material-icons added-to-playlist-icon"
  235. content="Song is already in playlist"
  236. v-tippy
  237. >done</i
  238. >
  239. <i
  240. v-else
  241. class="material-icons add-to-playlist-icon"
  242. content="Add Song to Playlist"
  243. v-tippy
  244. @click="
  245. addYouTubeSongToPlaylist(
  246. playlist._id,
  247. result.id,
  248. index
  249. )
  250. "
  251. >playlist_add</i
  252. >
  253. </transition>
  254. </template>
  255. </search-query-item>
  256. <button
  257. class="button is-primary load-more-button"
  258. @click.prevent="loadMoreSongs()"
  259. >
  260. Load more...
  261. </button>
  262. </div>
  263. </div>
  264. <template v-if="configStore.get('experimental.soundcloud')">
  265. <label class="label"> Add a SoundCloud song from a URL </label>
  266. <div class="control is-grouped input-with-button">
  267. <p class="control is-expanded">
  268. <input
  269. class="input"
  270. type="text"
  271. placeholder="Enter your SoundCloud song URL here..."
  272. v-model="soundcloudDirect"
  273. @keyup.enter="soundcloudAddToPlaylist(playlist._id)"
  274. />
  275. </p>
  276. <p class="control">
  277. <a
  278. class="button is-info"
  279. @click="soundcloudAddToPlaylist(playlist._id)"
  280. ><i class="material-icons icon-with-button">add</i
  281. >Add</a
  282. >
  283. </p>
  284. </div>
  285. </template>
  286. <template v-if="configStore.get('experimental.spotify')">
  287. <label class="label"> Add a Spotify song from a URL </label>
  288. <div class="control is-grouped input-with-button">
  289. <p class="control is-expanded">
  290. <input
  291. class="input"
  292. type="text"
  293. placeholder="Enter your Spotify song URL here..."
  294. v-model="spotifyDirect"
  295. @keyup.enter="spotifyAddToPlaylist(playlist._id)"
  296. />
  297. </p>
  298. <p class="control">
  299. <a
  300. class="button is-info"
  301. @click="spotifyAddToPlaylist(playlist._id)"
  302. ><i class="material-icons icon-with-button">add</i
  303. >Add</a
  304. >
  305. </p>
  306. </div>
  307. </template>
  308. </div>
  309. </template>
  310. <style lang="less" scoped>
  311. .youtube-tab {
  312. .song-query-results {
  313. margin-top: 10px;
  314. max-width: 565px;
  315. .search-query-item:not(:last-of-type) {
  316. margin-bottom: 10px;
  317. }
  318. }
  319. .load-more-button {
  320. width: 100%;
  321. margin-top: 10px;
  322. }
  323. }
  324. @media screen and (max-width: 1300px) {
  325. .youtube-tab .song-query-results,
  326. .section {
  327. max-width: 100% !important;
  328. }
  329. }
  330. </style>