SearchYoutube.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <script>
  2. import Toast from "toasters";
  3. export default {
  4. data() {
  5. return {
  6. search: {
  7. songs: {
  8. results: [],
  9. query: "",
  10. nextPageToken: ""
  11. },
  12. playlist: {
  13. query: "",
  14. isImportingOnlyMusic: true
  15. }
  16. }
  17. };
  18. },
  19. methods: {
  20. searchForSongs() {
  21. let { query } = this.search.songs;
  22. if (query.indexOf("&index=") !== -1) {
  23. query = query.split("&index=");
  24. query.pop();
  25. query = query.join("");
  26. }
  27. if (query.indexOf("&list=") !== -1) {
  28. query = query.split("&list=");
  29. query.pop();
  30. query = query.join("");
  31. }
  32. this.socket.dispatch("apis.searchYoutube", query, res => {
  33. if (res.status === "success") {
  34. this.search.songs.nextPageToken = res.data.nextPageToken;
  35. this.search.songs.results = [];
  36. res.data.items.forEach(result => {
  37. this.search.songs.results.push({
  38. id: result.id.videoId,
  39. url: `https://www.youtube.com/watch?v=${this.id}`,
  40. title: result.snippet.title,
  41. thumbnail: result.snippet.thumbnails.default.url,
  42. isAddedToQueue: false
  43. });
  44. });
  45. } else if (res.status === "error") new Toast(res.message);
  46. });
  47. },
  48. loadMoreSongs() {
  49. this.socket.dispatch(
  50. "apis.searchYoutubeForPage",
  51. this.search.songs.query,
  52. this.search.songs.nextPageToken,
  53. res => {
  54. if (res.status === "success") {
  55. this.search.songs.nextPageToken =
  56. res.data.nextPageToken;
  57. res.data.items.forEach(result => {
  58. this.search.songs.results.push({
  59. id: result.id.videoId,
  60. url: `https://www.youtube.com/watch?v=${this.id}`,
  61. title: result.snippet.title,
  62. thumbnail:
  63. result.snippet.thumbnails.default.url,
  64. isAddedToQueue: false
  65. });
  66. });
  67. } else if (res.status === "error") new Toast(res.message);
  68. }
  69. );
  70. }
  71. }
  72. };
  73. </script>