SearchYoutube.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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")
  46. new Toast({ content: res.message, timeout: 3000 });
  47. });
  48. },
  49. loadMoreSongs() {
  50. this.socket.dispatch(
  51. "apis.searchYoutubeForPage",
  52. this.search.songs.query,
  53. this.search.songs.nextPageToken,
  54. res => {
  55. if (res.status === "success") {
  56. this.search.songs.nextPageToken =
  57. res.data.nextPageToken;
  58. res.data.items.forEach(result => {
  59. this.search.songs.results.push({
  60. id: result.id.videoId,
  61. url: `https://www.youtube.com/watch?v=${this.id}`,
  62. title: result.snippet.title,
  63. thumbnail:
  64. result.snippet.thumbnails.default.url,
  65. isAddedToQueue: false
  66. });
  67. });
  68. } else if (res.status === "error")
  69. new Toast({ content: res.message, timeout: 3000 });
  70. }
  71. );
  72. }
  73. }
  74. };
  75. </script>