useSearchSoundcloud.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { ref } from "vue";
  2. import Toast from "toasters";
  3. import { useWebsocketsStore } from "@/stores/websockets";
  4. export const useSearchSoundcloud = () => {
  5. const soundcloudSearch = ref({
  6. songs: {
  7. results: [],
  8. query: "",
  9. nextPageToken: ""
  10. },
  11. playlist: {
  12. query: ""
  13. }
  14. });
  15. const { socket } = useWebsocketsStore();
  16. const searchForSongs = () => {
  17. // let { query } = soundcloudSearch.value.songs;
  18. // if (query.indexOf("&index=") !== -1) {
  19. // const splitQuery = query.split("&index=");
  20. // splitQuery.pop();
  21. // query = splitQuery.join("");
  22. // }
  23. // if (query.indexOf("&list=") !== -1) {
  24. // const splitQuery = query.split("&list=");
  25. // splitQuery.pop();
  26. // query = splitQuery.join("");
  27. // }
  28. // socket.dispatch("apis.searchSoundcloud", query, res => {
  29. // if (res.status === "success") {
  30. // soundcloudSearch.value.songs.nextPageToken =
  31. // res.data.nextPageToken;
  32. // soundcloudSearch.value.songs.results = [];
  33. // res.data.items.forEach(result => {
  34. // soundcloudSearch.value.songs.results.push({
  35. // id: result.id.videoId,
  36. // url: `https://www.soundcloud.com/watch?v=${result.id.videoId}`,
  37. // title: result.snippet.title,
  38. // thumbnail: result.snippet.thumbnails.default.url,
  39. // channelId: result.snippet.channelId,
  40. // channelTitle: result.snippet.channelTitle,
  41. // isAddedToQueue: false
  42. // });
  43. // });
  44. // } else if (res.status === "error") new Toast(res.message);
  45. // });
  46. };
  47. const loadMoreSongs = () => {
  48. // socket.dispatch(
  49. // "apis.searchSoundcloudForPage",
  50. // soundcloudSearch.value.songs.query,
  51. // soundcloudSearch.value.songs.nextPageToken,
  52. // res => {
  53. // if (res.status === "success") {
  54. // soundcloudSearch.value.songs.nextPageToken =
  55. // res.data.nextPageToken;
  56. // res.data.items.forEach(result => {
  57. // soundcloudSearch.value.songs.results.push({
  58. // id: result.id.videoId,
  59. // url: `https://www.soundcloud.com/watch?v=${result.id.videoId}`,
  60. // title: result.snippet.title,
  61. // thumbnail: result.snippet.thumbnails.default.url,
  62. // channelId: result.snippet.channelId,
  63. // channelTitle: result.snippet.channelTitle,
  64. // isAddedToQueue: false
  65. // });
  66. // });
  67. // } else if (res.status === "error") new Toast(res.message);
  68. // }
  69. // );
  70. };
  71. const addSoundcloudSongToPlaylist = (playlistId, id, index) => {
  72. socket.dispatch(
  73. "playlists.addSongToPlaylist",
  74. false,
  75. id,
  76. playlistId,
  77. res => {
  78. new Toast(res.message);
  79. if (res.status === "success")
  80. soundcloudSearch.value.songs.results[index].isAddedToQueue =
  81. true;
  82. }
  83. );
  84. };
  85. return {
  86. soundcloudSearch,
  87. searchForSongs,
  88. loadMoreSongs,
  89. addSoundcloudSongToPlaylist
  90. };
  91. };