ConvertSpotifySongs.vue 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173
  1. <script setup lang="ts">
  2. import {
  3. defineProps,
  4. defineAsyncComponent,
  5. onMounted,
  6. ref,
  7. reactive,
  8. computed
  9. } from "vue";
  10. import Toast from "toasters";
  11. import { useModalsStore } from "@/stores/modals";
  12. import { useWebsocketsStore } from "@/stores/websockets";
  13. const Modal = defineAsyncComponent(() => import("@/components/Modal.vue"));
  14. const MediaItem = defineAsyncComponent(
  15. () => import("@/components/MediaItem.vue")
  16. );
  17. const QuickConfirm = defineAsyncComponent(
  18. () => import("@/components/QuickConfirm.vue")
  19. );
  20. const { openModal, closeCurrentModal } = useModalsStore();
  21. const { socket } = useWebsocketsStore();
  22. const TAG = "CSS";
  23. const props = defineProps({
  24. modalUuid: { type: String, required: true },
  25. playlistId: { type: String, default: null }
  26. });
  27. const playlist = ref(null);
  28. const spotifySongs = ref([]);
  29. const spotifyTracks = reactive({});
  30. const spotifyAlbums = reactive({});
  31. const spotifyArtists = reactive({});
  32. const loadingPlaylist = ref(false);
  33. const loadedPlaylist = ref(false);
  34. const loadingSpotifyTracks = ref(false);
  35. const loadedSpotifyTracks = ref(false);
  36. const loadingSpotifyAlbums = ref(false);
  37. const loadedSpotifyAlbums = ref(false);
  38. const loadingSpotifyArtists = ref(false);
  39. const loadedSpotifyArtists = ref(false);
  40. const gettingAllAlternativeMediaPerTrack = ref(false);
  41. const gotAllAlternativeMediaPerTrack = ref(false);
  42. const alternativeMediaPerTrack = reactive({});
  43. const gettingAllAlternativeAlbums = ref(false);
  44. const gotAllAlternativeAlbums = ref(false);
  45. const alternativeAlbumsPerAlbum = reactive({});
  46. const gettingAllAlternativeArtists = ref(false);
  47. const gotAllAlternativeArtists = ref(false);
  48. const alternativeArtistsPerArtist = reactive({});
  49. const alternativeMediaMap = reactive({});
  50. const alternativeMediaFailedMap = reactive({});
  51. const gettingMissingAlternativeMedia = ref(false);
  52. const replacingAllSpotifySongs = ref(false);
  53. const currentConvertType = ref<"track" | "album" | "artist">("track");
  54. const showReplaceButtonPerAlternative = ref(true);
  55. const hideSpotifySongsWithNoAlternativesFound = ref(false);
  56. const preferredAlternativeSongMode = ref<
  57. "FIRST" | "LYRICS" | "TOPIC" | "LYRICS_TOPIC" | "TOPIC_LYRICS"
  58. >("FIRST");
  59. // const singleMode = ref(false);
  60. const showExtra = ref(false);
  61. const collectAlternativeMediaSourcesOrigins = ref(false);
  62. const minimumSongsPerAlbum = ref(2);
  63. const minimumSongsPerArtist = ref(2);
  64. const sortAlbumMode = ref<
  65. "SONG_COUNT_ASC" | "SONG_COUNT_DESC" | "NAME_DESC" | "NAME_ASC"
  66. >("SONG_COUNT_ASC");
  67. const sortArtistMode = ref<
  68. "SONG_COUNT_ASC" | "SONG_COUNT_DESC" | "NAME_DESC" | "NAME_ASC"
  69. >("SONG_COUNT_ASC");
  70. const showDontConvertButton = ref(true);
  71. const replaceSongUrlMap = reactive({});
  72. const showReplacementInputs = ref(false);
  73. const youtubeVideoUrlRegex =
  74. /^(?:https?:\/\/)?(?:www\.)?(m\.)?(?:music\.)?(?:youtube\.com|youtu\.be)\/(?:watch\/?\?v=)?(?:.*&v=)?(?<youtubeId>[\w-]{11}).*$/;
  75. const youtubeVideoIdRegex = /^([\w-]{11})$/;
  76. const youtubePlaylistUrlRegex = /[\\?&]list=([^&#]*)/;
  77. const filteredSpotifySongs = computed(() =>
  78. hideSpotifySongsWithNoAlternativesFound.value
  79. ? spotifySongs.value.filter(
  80. spotifySong =>
  81. (!gettingAllAlternativeMediaPerTrack.value &&
  82. !gotAllAlternativeMediaPerTrack.value) ||
  83. (alternativeMediaPerTrack[spotifySong.mediaSource] &&
  84. alternativeMediaPerTrack[spotifySong.mediaSource]
  85. .mediaSources.length > 0)
  86. )
  87. : spotifySongs.value
  88. );
  89. const filteredSpotifyArtists = computed(() => {
  90. let artists = Object.values(spotifyArtists);
  91. artists = artists.filter(
  92. artist => artist.songs.length >= minimumSongsPerArtist.value
  93. );
  94. let sortFn = null;
  95. if (sortArtistMode.value === "SONG_COUNT_ASC")
  96. sortFn = (artistA, artistB) =>
  97. artistA.songs.length - artistB.songs.length;
  98. else if (sortArtistMode.value === "SONG_COUNT_DESC")
  99. sortFn = (artistA, artistB) =>
  100. artistB.songs.length - artistA.songs.length;
  101. else if (loadedSpotifyArtists.value && sortArtistMode.value === "NAME_ASC")
  102. sortFn = (artistA, artistB) => {
  103. const nameA = artistA.rawData?.name?.toLowerCase();
  104. const nameB = artistB.rawData?.name?.toLowerCase();
  105. if (nameA === nameB) return 0;
  106. if (nameA < nameB) return -1;
  107. if (nameA > nameB) return 1;
  108. return 0;
  109. };
  110. else if (loadedSpotifyArtists.value && sortArtistMode.value === "NAME_DESC")
  111. sortFn = (artistA, artistB) => {
  112. const nameA = artistA.rawData?.name?.toLowerCase();
  113. const nameB = artistB.rawData?.name?.toLowerCase();
  114. if (nameA === nameB) return 0;
  115. if (nameA > nameB) return -1;
  116. if (nameA < nameB) return 1;
  117. return 0;
  118. };
  119. if (sortFn) artists = artists.sort(sortFn);
  120. return artists;
  121. });
  122. const filteredSpotifyAlbums = computed(() => {
  123. let albums = Object.values(spotifyAlbums);
  124. albums = albums.filter(
  125. album => album.songs.length >= minimumSongsPerAlbum.value
  126. );
  127. let sortFn = null;
  128. if (sortAlbumMode.value === "SONG_COUNT_ASC")
  129. sortFn = (albumA, albumB) => albumA.songs.length - albumB.songs.length;
  130. else if (sortAlbumMode.value === "SONG_COUNT_DESC")
  131. sortFn = (albumA, albumB) => albumB.songs.length - albumA.songs.length;
  132. else if (loadedSpotifyAlbums.value && sortAlbumMode.value === "NAME_ASC")
  133. sortFn = (albumA, albumB) => {
  134. const nameA = albumA.rawData?.name?.toLowerCase();
  135. const nameB = albumB.rawData?.name?.toLowerCase();
  136. if (nameA === nameB) return 0;
  137. if (nameA < nameB) return -1;
  138. if (nameA > nameB) return 1;
  139. return 0;
  140. };
  141. else if (loadedSpotifyAlbums.value && sortAlbumMode.value === "NAME_DESC")
  142. sortFn = (albumA, albumB) => {
  143. const nameA = albumA.rawData?.name?.toLowerCase();
  144. const nameB = albumB.rawData?.name?.toLowerCase();
  145. if (nameA === nameB) return 0;
  146. if (nameA > nameB) return -1;
  147. if (nameA < nameB) return 1;
  148. return 0;
  149. };
  150. if (sortFn) albums = albums.sort(sortFn);
  151. return albums;
  152. });
  153. const missingMediaSources = computed(() => {
  154. const missingMediaSources = [];
  155. Object.values(alternativeMediaPerTrack).forEach(({ mediaSources }) => {
  156. mediaSources.forEach(mediaSource => {
  157. if (
  158. !alternativeMediaMap[mediaSource] &&
  159. !alternativeMediaFailedMap[mediaSource] &&
  160. missingMediaSources.indexOf(mediaSource) === -1
  161. )
  162. missingMediaSources.push(mediaSource);
  163. });
  164. });
  165. return missingMediaSources;
  166. });
  167. const preferredAlternativeSongPerTrack = computed(() => {
  168. const returnObject = {};
  169. Object.entries(alternativeMediaPerTrack).forEach(
  170. ([spotifyMediaSource, { mediaSources }]) => {
  171. returnObject[spotifyMediaSource] = null;
  172. if (mediaSources.length === 0) return;
  173. let sortFn = (mediaSourceA, mediaSourceB) => {
  174. if (preferredAlternativeSongMode.value === "FIRST") return 0;
  175. const aHasLyrics =
  176. alternativeMediaMap[mediaSourceA].title
  177. .toLowerCase()
  178. .indexOf("lyric") !== -1;
  179. const aHasTopic =
  180. alternativeMediaMap[mediaSourceA].artists[0]
  181. .toLowerCase()
  182. .indexOf("topic") !== -1;
  183. const bHasLyrics =
  184. alternativeMediaMap[mediaSourceB].title
  185. .toLowerCase()
  186. .indexOf("lyric") !== -1;
  187. const bHasTopic =
  188. alternativeMediaMap[mediaSourceB].artists[0]
  189. .toLowerCase()
  190. .indexOf("topic") !== -1;
  191. if (preferredAlternativeSongMode.value === "LYRICS") {
  192. if (aHasLyrics && bHasLyrics) return 0;
  193. if (aHasLyrics && !bHasLyrics) return -1;
  194. if (!aHasLyrics && bHasLyrics) return 1;
  195. return 0;
  196. }
  197. if (preferredAlternativeSongMode.value === "TOPIC") {
  198. if (aHasTopic && bHasTopic) return 0;
  199. if (aHasTopic && !bHasTopic) return -1;
  200. if (!aHasTopic && bHasTopic) return 1;
  201. return 0;
  202. }
  203. if (preferredAlternativeSongMode.value === "LYRICS_TOPIC") {
  204. if (aHasLyrics && bHasLyrics) return 0;
  205. if (aHasLyrics && !bHasLyrics) return -1;
  206. if (!aHasLyrics && bHasLyrics) return 1;
  207. if (aHasTopic && bHasTopic) return 0;
  208. if (aHasTopic && !bHasTopic) return -1;
  209. if (!aHasTopic && bHasTopic) return 1;
  210. return 0;
  211. }
  212. if (preferredAlternativeSongMode.value === "TOPIC_LYRICS") {
  213. if (aHasTopic && bHasTopic) return 0;
  214. if (aHasTopic && !bHasTopic) return -1;
  215. if (!aHasTopic && bHasTopic) return 1;
  216. if (aHasLyrics && bHasLyrics) return 0;
  217. if (aHasLyrics && !bHasLyrics) return -1;
  218. if (!aHasLyrics && bHasLyrics) return 1;
  219. return 0;
  220. }
  221. return 0;
  222. };
  223. if (
  224. mediaSources.length === 1 ||
  225. preferredAlternativeSongMode.value === "FIRST"
  226. )
  227. sortFn = () => 0;
  228. else if (preferredAlternativeSongMode.value === "LYRICS")
  229. sortFn = mediaSourceA => {
  230. if (!alternativeMediaMap[mediaSourceA]) return 0;
  231. if (
  232. alternativeMediaMap[mediaSourceA].title
  233. .toLowerCase()
  234. .indexOf("lyric") !== -1
  235. )
  236. return -1;
  237. return 1;
  238. };
  239. else if (preferredAlternativeSongMode.value === "TOPIC")
  240. sortFn = mediaSourceA => {
  241. if (!alternativeMediaMap[mediaSourceA]) return 0;
  242. if (
  243. alternativeMediaMap[mediaSourceA].artists[0]
  244. .toLowerCase()
  245. .indexOf("topic") !== -1
  246. )
  247. return -1;
  248. return 1;
  249. };
  250. const [firstMediaSource] = mediaSources
  251. .slice()
  252. .filter(mediaSource => !!alternativeMediaMap[mediaSource])
  253. .sort(sortFn);
  254. returnObject[spotifyMediaSource] = firstMediaSource;
  255. }
  256. );
  257. return returnObject;
  258. });
  259. const replaceAllSpotifySongs = async () => {
  260. if (replacingAllSpotifySongs.value) return;
  261. replacingAllSpotifySongs.value = true;
  262. const replaceArray = [];
  263. spotifySongs.value.forEach(spotifySong => {
  264. const spotifyMediaSource = spotifySong.mediaSource;
  265. const replacementMediaSource =
  266. preferredAlternativeSongPerTrack.value[spotifyMediaSource];
  267. if (!spotifyMediaSource || !replacementMediaSource) return;
  268. replaceArray.push([spotifyMediaSource, replacementMediaSource]);
  269. });
  270. const promises = replaceArray.map(
  271. ([spotifyMediaSource, replacementMediaSource]) =>
  272. new Promise<void>(resolve => {
  273. socket.dispatch(
  274. "playlists.replaceSongInPlaylist",
  275. spotifyMediaSource,
  276. replacementMediaSource,
  277. props.playlistId,
  278. res => {
  279. console.log(
  280. "playlists.replaceSongInPlaylist response",
  281. res
  282. );
  283. resolve();
  284. }
  285. );
  286. })
  287. );
  288. Promise.allSettled(promises).finally(() => {
  289. replacingAllSpotifySongs.value = false;
  290. });
  291. };
  292. const replaceSpotifySong = (oldMediaSource, newMediaSource) => {
  293. socket.dispatch(
  294. "playlists.replaceSongInPlaylist",
  295. oldMediaSource,
  296. newMediaSource,
  297. props.playlistId,
  298. res => {
  299. console.log("playlists.replaceSongInPlaylist response", res);
  300. }
  301. );
  302. };
  303. const openReplaceAlbumModal = (spotifyAlbumId, youtubePlaylistId) => {
  304. console.log(spotifyAlbumId, youtubePlaylistId);
  305. if (
  306. !spotifyAlbums[spotifyAlbumId] ||
  307. !spotifyAlbums[spotifyAlbumId].rawData
  308. ) {
  309. new Toast("Album hasn't loaded yet.");
  310. return;
  311. }
  312. openModal({
  313. modal: "replaceSpotifySongs",
  314. props: {
  315. playlistId: props.playlistId,
  316. youtubePlaylistId,
  317. spotifyTracks: spotifyAlbums[spotifyAlbumId].songs.map(
  318. mediaSource => spotifyTracks[mediaSource]
  319. )
  320. }
  321. });
  322. };
  323. const openReplaceAlbumModalFromUrl = spotifyAlbumId => {
  324. const replacementUrl = replaceSongUrlMap[`album:${spotifyAlbumId}`];
  325. console.log(spotifyAlbumId, replacementUrl);
  326. let youtubePlaylistId = null;
  327. const youtubePlaylistUrlRegexMatches =
  328. youtubePlaylistUrlRegex.exec(replacementUrl);
  329. if (youtubePlaylistUrlRegexMatches)
  330. [youtubePlaylistId] = youtubePlaylistUrlRegexMatches;
  331. console.log("Open modal for ", youtubePlaylistId);
  332. openReplaceAlbumModal(spotifyAlbumId, youtubePlaylistId);
  333. };
  334. const openReplaceArtistModal = (spotifyArtistId, youtubeChannelUrl) => {
  335. console.log(spotifyArtistId, youtubeChannelUrl);
  336. if (
  337. !spotifyArtists[spotifyArtistId] ||
  338. !spotifyArtists[spotifyArtistId].rawData
  339. ) {
  340. new Toast("Artist hasn't loaded yet.");
  341. return;
  342. }
  343. openModal({
  344. modal: "replaceSpotifySongs",
  345. props: {
  346. playlistId: props.playlistId,
  347. youtubeChannelUrl,
  348. spotifyTracks: spotifyArtists[spotifyArtistId].songs.map(
  349. mediaSource => spotifyTracks[mediaSource]
  350. )
  351. }
  352. });
  353. };
  354. const openReplaceArtistModalFromUrl = spotifyArtistId => {
  355. const replacementUrl = replaceSongUrlMap[`artist:${spotifyArtistId}`];
  356. console.log(spotifyArtistId, replacementUrl);
  357. // let youtubeChannelId = null;
  358. // const youtubeChannelUrlRegexMatches =
  359. // youtubeChannelUrlRegex.exec(replacementUrl);
  360. // if (youtubeChannelUrlRegexMatches)
  361. // youtubeChannelId = youtubeChannelUrlRegexMatches[0];
  362. console.log("Open modal for ", replacementUrl);
  363. openReplaceArtistModal(spotifyArtistId, replacementUrl);
  364. };
  365. const replaceSongFromUrl = spotifyMediaSource => {
  366. const replacementUrl = replaceSongUrlMap[spotifyMediaSource];
  367. console.log(spotifyMediaSource, replacementUrl);
  368. let newMediaSource = null;
  369. const youtubeVideoUrlRegexMatches =
  370. youtubeVideoUrlRegex.exec(replacementUrl);
  371. console.log(youtubeVideoUrlRegexMatches);
  372. const youtubeVideoIdRegexMatches = youtubeVideoIdRegex.exec(replacementUrl);
  373. console.log(youtubeVideoIdRegexMatches);
  374. if (youtubeVideoUrlRegexMatches)
  375. newMediaSource = `youtube:${youtubeVideoUrlRegexMatches.groups.youtubeId}`;
  376. if (youtubeVideoIdRegexMatches)
  377. newMediaSource = `youtube:${youtubeVideoIdRegexMatches[0]}`;
  378. if (!newMediaSource) {
  379. new Toast("Invalid URL/identifier specified.");
  380. return;
  381. }
  382. replaceSpotifySong(spotifyMediaSource, newMediaSource);
  383. };
  384. const getMissingAlternativeMedia = () => {
  385. if (gettingMissingAlternativeMedia.value) return;
  386. gettingMissingAlternativeMedia.value = true;
  387. const _missingMediaSources = missingMediaSources.value;
  388. console.log("Getting missing", _missingMediaSources);
  389. socket.dispatch(
  390. "media.getMediaFromMediaSources",
  391. _missingMediaSources,
  392. res => {
  393. if (res.status === "success") {
  394. const { songMap } = res.data;
  395. _missingMediaSources.forEach(missingMediaSource => {
  396. if (songMap[missingMediaSource])
  397. alternativeMediaMap[missingMediaSource] =
  398. songMap[missingMediaSource];
  399. else alternativeMediaFailedMap[missingMediaSource] = true;
  400. });
  401. }
  402. gettingMissingAlternativeMedia.value = false;
  403. }
  404. );
  405. };
  406. const getAlternativeArtists = () => {
  407. if (gettingAllAlternativeArtists.value || gotAllAlternativeArtists.value)
  408. return;
  409. gettingAllAlternativeArtists.value = true;
  410. const artistIds = filteredSpotifyArtists.value.map(
  411. artist => artist.artistId
  412. );
  413. socket.dispatch(
  414. "apis.getAlternativeArtistSourcesForArtists",
  415. artistIds,
  416. collectAlternativeMediaSourcesOrigins.value,
  417. {
  418. cb: res => {
  419. console.log(
  420. "apis.getAlternativeArtistSourcesForArtists response",
  421. res
  422. );
  423. },
  424. onProgress: data => {
  425. console.log(
  426. "apis.getAlternativeArtistSourcesForArtists onProgress",
  427. data
  428. );
  429. if (data.status === "working") {
  430. if (data.data.status === "success") {
  431. const { artistId, result } = data.data;
  432. if (!spotifyArtists[artistId]) return;
  433. alternativeArtistsPerArtist[artistId] = {
  434. youtubeChannelIds: result
  435. };
  436. }
  437. } else if (data.status === "finished") {
  438. gotAllAlternativeArtists.value = true;
  439. gettingAllAlternativeArtists.value = false;
  440. }
  441. }
  442. }
  443. );
  444. };
  445. const getAlternativeAlbums = () => {
  446. if (gettingAllAlternativeAlbums.value || gotAllAlternativeAlbums.value)
  447. return;
  448. gettingAllAlternativeAlbums.value = true;
  449. const albumIds = filteredSpotifyAlbums.value.map(album => album.albumId);
  450. socket.dispatch(
  451. "apis.getAlternativeAlbumSourcesForAlbums",
  452. albumIds,
  453. collectAlternativeMediaSourcesOrigins.value,
  454. {
  455. cb: res => {
  456. console.log(
  457. "apis.getAlternativeAlbumSourcesForAlbums response",
  458. res
  459. );
  460. },
  461. onProgress: data => {
  462. console.log(
  463. "apis.getAlternativeAlbumSourcesForAlbums onProgress",
  464. data
  465. );
  466. if (data.status === "working") {
  467. if (data.data.status === "success") {
  468. const { albumId, result } = data.data;
  469. if (!spotifyAlbums[albumId]) return;
  470. alternativeAlbumsPerAlbum[albumId] = {
  471. youtubePlaylistIds: result
  472. };
  473. }
  474. } else if (data.status === "finished") {
  475. gotAllAlternativeAlbums.value = true;
  476. gettingAllAlternativeAlbums.value = false;
  477. }
  478. }
  479. }
  480. );
  481. };
  482. const getAlternativeMedia = () => {
  483. if (
  484. gettingAllAlternativeMediaPerTrack.value ||
  485. gotAllAlternativeMediaPerTrack.value
  486. )
  487. return;
  488. gettingAllAlternativeMediaPerTrack.value = true;
  489. const mediaSources = spotifySongs.value.map(song => song.mediaSource);
  490. socket.dispatch(
  491. "apis.getAlternativeMediaSourcesForTracks",
  492. mediaSources,
  493. collectAlternativeMediaSourcesOrigins.value,
  494. {
  495. cb: res => {
  496. console.log(
  497. "apis.getAlternativeMediaSourcesForTracks response",
  498. res
  499. );
  500. },
  501. onProgress: data => {
  502. console.log(
  503. "apis.getAlternativeMediaSourcesForTracks onProgress",
  504. data
  505. );
  506. if (data.status === "working") {
  507. if (data.data.status === "success") {
  508. const { mediaSource, result } = data.data;
  509. if (!spotifyTracks[mediaSource]) return;
  510. alternativeMediaPerTrack[mediaSource] = result;
  511. }
  512. } else if (data.status === "finished") {
  513. gotAllAlternativeMediaPerTrack.value = true;
  514. gettingAllAlternativeMediaPerTrack.value = false;
  515. getMissingAlternativeMedia();
  516. }
  517. }
  518. }
  519. );
  520. };
  521. const loadSpotifyArtists = () =>
  522. new Promise<void>(resolve => {
  523. console.debug(TAG, "Loading Spotify artists");
  524. loadingSpotifyArtists.value = true;
  525. const artistIds = filteredSpotifyArtists.value.map(
  526. artist => artist.artistId
  527. );
  528. socket.dispatch("spotify.getArtistsFromIds", artistIds, res => {
  529. console.debug(TAG, "Get artists response", res);
  530. if (res.status !== "success") {
  531. new Toast(res.message);
  532. closeCurrentModal();
  533. return;
  534. }
  535. const { artists } = res.data;
  536. artists.forEach(artist => {
  537. spotifyArtists[artist.artistId].rawData = artist.rawData;
  538. });
  539. console.debug(TAG, "Loaded Spotify artists");
  540. loadedSpotifyArtists.value = true;
  541. loadingSpotifyArtists.value = false;
  542. resolve();
  543. });
  544. });
  545. const loadSpotifyAlbums = () =>
  546. new Promise<void>(resolve => {
  547. console.debug(TAG, "Loading Spotify albums");
  548. loadingSpotifyAlbums.value = true;
  549. const albumIds = filteredSpotifyAlbums.value.map(
  550. album => album.albumId
  551. );
  552. socket.dispatch("spotify.getAlbumsFromIds", albumIds, res => {
  553. console.debug(TAG, "Get albums response", res);
  554. if (res.status !== "success") {
  555. new Toast(res.message);
  556. closeCurrentModal();
  557. return;
  558. }
  559. const { albums } = res.data;
  560. albums.forEach(album => {
  561. spotifyAlbums[album.albumId].rawData = album.rawData;
  562. });
  563. console.debug(TAG, "Loaded Spotify albums");
  564. loadedSpotifyAlbums.value = true;
  565. loadingSpotifyAlbums.value = false;
  566. resolve();
  567. });
  568. });
  569. const loadSpotifyTracks = () =>
  570. new Promise<void>(resolve => {
  571. console.debug(TAG, "Loading Spotify tracks");
  572. loadingSpotifyTracks.value = true;
  573. const mediaSources = spotifySongs.value.map(song => song.mediaSource);
  574. socket.dispatch(
  575. "spotify.getTracksFromMediaSources",
  576. mediaSources,
  577. res => {
  578. console.debug(TAG, "Get tracks response", res);
  579. if (res.status !== "success") {
  580. new Toast(res.message);
  581. closeCurrentModal();
  582. return;
  583. }
  584. const { tracks } = res.data;
  585. Object.entries(tracks).forEach(([mediaSource, track]) => {
  586. spotifyTracks[mediaSource] = track;
  587. const { albumId, albumImageUrl, artistIds, artists } =
  588. track;
  589. if (albumId) {
  590. if (!spotifyAlbums[albumId])
  591. spotifyAlbums[albumId] = {
  592. albumId,
  593. albumImageUrl,
  594. songs: []
  595. };
  596. spotifyAlbums[albumId].songs.push(mediaSource);
  597. }
  598. artistIds.forEach((artistId, artistIndex) => {
  599. if (!spotifyArtists[artistId]) {
  600. spotifyArtists[artistId] = {
  601. artistId,
  602. name: artists[artistIndex],
  603. songs: [],
  604. expanded: false
  605. };
  606. }
  607. spotifyArtists[artistId].songs.push(mediaSource);
  608. });
  609. });
  610. console.debug(TAG, "Loaded Spotify tracks");
  611. loadedSpotifyTracks.value = true;
  612. loadingSpotifyTracks.value = false;
  613. resolve();
  614. }
  615. );
  616. });
  617. const loadPlaylist = () =>
  618. new Promise<void>(resolve => {
  619. console.debug(TAG, `Loading playlist ${props.playlistId}`);
  620. loadingPlaylist.value = true;
  621. socket.dispatch("playlists.getPlaylist", props.playlistId, res => {
  622. console.debug(TAG, "Get playlist response", res);
  623. if (res.status !== "success") {
  624. new Toast(res.message);
  625. closeCurrentModal();
  626. return;
  627. }
  628. playlist.value = res.data.playlist;
  629. spotifySongs.value = playlist.value.songs.filter(song =>
  630. song.mediaSource.startsWith("spotify:")
  631. );
  632. console.debug(TAG, `Loaded playlist ${props.playlistId}`);
  633. loadedPlaylist.value = true;
  634. loadingPlaylist.value = false;
  635. resolve();
  636. });
  637. });
  638. const removeAlternativeTrack = (spotifyMediaSource, alternativeMediaSource) => {
  639. alternativeMediaPerTrack[spotifyMediaSource].mediaSources =
  640. alternativeMediaPerTrack[spotifyMediaSource].mediaSources.filter(
  641. mediaSource => mediaSource !== alternativeMediaSource
  642. );
  643. };
  644. const removeSpotifyTrack = mediaSource => {
  645. const spotifyTrack = spotifyTracks[mediaSource];
  646. if (spotifyTrack) {
  647. delete spotifyTracks[mediaSource];
  648. spotifyTrack.artistIds.forEach(artistId => {
  649. const spotifyArtist = spotifyArtists[artistId];
  650. if (spotifyArtist) {
  651. if (spotifyArtist.songs.length === 1)
  652. delete spotifyArtists[artistId];
  653. else
  654. spotifyArtists[artistId].songs = spotifyArtists[
  655. artistId
  656. ].songs.filter(
  657. _mediaSource => _mediaSource !== mediaSource
  658. );
  659. }
  660. });
  661. const spotifyAlbum = spotifyAlbums[spotifyTrack.albumId];
  662. if (spotifyAlbum) {
  663. if (spotifyAlbum.songs.length === 1)
  664. delete spotifyAlbums[spotifyTrack.albumId];
  665. else
  666. spotifyAlbums[spotifyTrack.albumId].songs = spotifyAlbums[
  667. spotifyTrack.albumId
  668. ].songs.filter(_mediaSource => _mediaSource !== mediaSource);
  669. }
  670. }
  671. };
  672. const removeSpotifySong = mediaSource => {
  673. // remove song
  674. playlist.value.songs = playlist.value.songs.filter(
  675. song => song.mediaSource !== mediaSource
  676. );
  677. spotifySongs.value = spotifySongs.value.filter(
  678. song => song.mediaSource !== mediaSource
  679. );
  680. removeSpotifyTrack(mediaSource);
  681. delete alternativeMediaMap[mediaSource];
  682. delete alternativeMediaFailedMap[mediaSource];
  683. };
  684. onMounted(() => {
  685. console.debug(TAG, "On mounted start");
  686. loadPlaylist().then(loadSpotifyTracks);
  687. socket.on(
  688. "event:playlist.song.removed",
  689. res => {
  690. console.log("SONG REMOVED", res);
  691. if (
  692. loadedPlaylist.value &&
  693. playlist.value._id === res.data.playlistId
  694. ) {
  695. const { oldMediaSource } = res.data;
  696. removeSpotifySong(oldMediaSource);
  697. }
  698. },
  699. { modalUuid: props.modalUuid }
  700. );
  701. socket.on(
  702. "event:playlist.song.replaced",
  703. res => {
  704. console.log(
  705. "SONG REPLACED",
  706. res,
  707. playlist.value._id === res.data.playlistId
  708. );
  709. if (
  710. loadedPlaylist.value &&
  711. playlist.value._id === res.data.playlistId
  712. ) {
  713. const { oldMediaSource } = res.data;
  714. removeSpotifySong(oldMediaSource);
  715. }
  716. },
  717. { modalUuid: props.modalUuid }
  718. );
  719. console.debug(TAG, "On mounted end");
  720. });
  721. </script>
  722. <template>
  723. <div>
  724. <modal
  725. title="Convert Spotify Songs"
  726. class="convert-spotify-songs-modal"
  727. size="wide"
  728. @closed="closeCurrentModal()"
  729. >
  730. <template #body>
  731. <template v-if="loadedPlaylist && spotifySongs.length === 0">
  732. <h2>All Spotify songs have been converted</h2>
  733. <button
  734. class="button is-primary is-fullwidth"
  735. @click="closeCurrentModal()"
  736. >
  737. Close modal
  738. </button>
  739. </template>
  740. <template v-else>
  741. <div class="buttons-options-info-row">
  742. <div class="buttons">
  743. <quick-confirm
  744. v-if="
  745. gotAllAlternativeMediaPerTrack &&
  746. missingMediaSources.length === 0 &&
  747. !replacingAllSpotifySongs
  748. "
  749. placement="top"
  750. @confirm="replaceAllSpotifySongs()"
  751. >
  752. <button class="button is-primary is-fullwidth">
  753. Replace all available songs with provided
  754. prefer settings
  755. </button>
  756. </quick-confirm>
  757. <button
  758. v-if="
  759. loadedSpotifyTracks &&
  760. !gettingAllAlternativeMediaPerTrack &&
  761. !gotAllAlternativeMediaPerTrack &&
  762. currentConvertType === 'track'
  763. "
  764. class="button is-primary"
  765. @click="getAlternativeMedia()"
  766. >
  767. Get alternative media
  768. </button>
  769. <button
  770. v-if="
  771. currentConvertType === 'track' &&
  772. gotAllAlternativeMediaPerTrack &&
  773. !gettingMissingAlternativeMedia &&
  774. missingMediaSources.length > 0
  775. "
  776. class="button is-primary"
  777. @click="getMissingAlternativeMedia()"
  778. >
  779. Get missing alternative media
  780. </button>
  781. <button
  782. v-if="
  783. loadedSpotifyTracks &&
  784. !loadingSpotifyAlbums &&
  785. !loadedSpotifyAlbums &&
  786. currentConvertType === 'album'
  787. "
  788. class="button is-primary"
  789. @click="loadSpotifyAlbums()"
  790. >
  791. Get Spotify albums
  792. </button>
  793. <button
  794. v-if="
  795. loadedSpotifyTracks &&
  796. loadedSpotifyAlbums &&
  797. !gettingAllAlternativeAlbums &&
  798. !gotAllAlternativeAlbums &&
  799. currentConvertType === 'album'
  800. "
  801. class="button is-primary"
  802. @click="getAlternativeAlbums()"
  803. >
  804. Get alternative albums
  805. </button>
  806. <button
  807. v-if="
  808. loadedSpotifyTracks &&
  809. !loadingSpotifyArtists &&
  810. !loadedSpotifyArtists &&
  811. currentConvertType === 'artist'
  812. "
  813. class="button is-primary"
  814. @click="loadSpotifyArtists()"
  815. >
  816. Get Spotify artists
  817. </button>
  818. <button
  819. v-if="
  820. loadedSpotifyTracks &&
  821. loadedSpotifyArtists &&
  822. !gettingAllAlternativeArtists &&
  823. !gotAllAlternativeArtists &&
  824. currentConvertType === 'artist'
  825. "
  826. class="button is-primary"
  827. @click="getAlternativeArtists()"
  828. >
  829. Get alternative artists
  830. </button>
  831. </div>
  832. <div class="options">
  833. <p class="is-expanded checkbox-control">
  834. <label class="switch">
  835. <input
  836. type="checkbox"
  837. id="show-extra"
  838. v-model="showExtra"
  839. />
  840. <span class="slider round"></span>
  841. </label>
  842. <label for="show-extra">
  843. <p>Show extra info</p>
  844. </label>
  845. </p>
  846. <p class="is-expanded checkbox-control">
  847. <label class="switch">
  848. <input
  849. type="checkbox"
  850. id="collect-alternative-media-sources-origins"
  851. v-model="
  852. collectAlternativeMediaSourcesOrigins
  853. "
  854. />
  855. <span class="slider round"></span>
  856. </label>
  857. <label
  858. for="collect-alternative-media-sources-origins"
  859. >
  860. <p>
  861. Collect alternative media sources
  862. origins
  863. </p>
  864. </label>
  865. </p>
  866. <p class="is-expanded checkbox-control">
  867. <label class="switch">
  868. <input
  869. type="checkbox"
  870. id="show-replace-button-per-alternative"
  871. v-model="
  872. showReplaceButtonPerAlternative
  873. "
  874. />
  875. <span class="slider round"></span>
  876. </label>
  877. <label
  878. for="show-replace-button-per-alternative"
  879. >
  880. <p>Show replace button per alternative</p>
  881. </label>
  882. </p>
  883. <p class="is-expanded checkbox-control">
  884. <label class="switch">
  885. <input
  886. type="checkbox"
  887. id="showDontConvertButton"
  888. v-model="showDontConvertButton"
  889. />
  890. <span class="slider round"></span>
  891. </label>
  892. <label for="showDontConvertButton">
  893. <p>Show don't convert buttons</p>
  894. </label>
  895. </p>
  896. <p class="is-expanded checkbox-control">
  897. <label class="switch">
  898. <input
  899. type="checkbox"
  900. id="showReplacementInputs"
  901. v-model="showReplacementInputs"
  902. />
  903. <span class="slider round"></span>
  904. </label>
  905. <label for="showReplacementInputs">
  906. <p>Show replacement inputs</p>
  907. </label>
  908. </p>
  909. <p class="is-expanded checkbox-control">
  910. <label class="switch">
  911. <input
  912. type="checkbox"
  913. id="hide-spotify-songs-with-no-alternatives-found"
  914. v-model="
  915. hideSpotifySongsWithNoAlternativesFound
  916. "
  917. />
  918. <span class="slider round"></span>
  919. </label>
  920. <label
  921. for="hide-spotify-songs-with-no-alternatives-found"
  922. >
  923. <p>
  924. Hide Spotify songs with no alternatives
  925. found
  926. </p>
  927. </label>
  928. </p>
  929. <div class="control">
  930. <label class="label"
  931. >Get alternatives per</label
  932. >
  933. <p class="control is-expanded select">
  934. <select
  935. v-model="currentConvertType"
  936. :disabled="
  937. gettingAllAlternativeMediaPerTrack
  938. "
  939. >
  940. <option value="track">Track</option>
  941. <option value="artist">Artist</option>
  942. <option value="album">Album</option>
  943. </select>
  944. </p>
  945. </div>
  946. <div
  947. class="control"
  948. v-if="currentConvertType === 'track'"
  949. >
  950. <label class="label"
  951. >Preferred track mode</label
  952. >
  953. <p class="control is-expanded select">
  954. <select
  955. v-model="preferredAlternativeSongMode"
  956. :disabled="false"
  957. >
  958. <option value="FIRST">
  959. First song
  960. </option>
  961. <option value="LYRICS">
  962. First song with lyrics in title
  963. </option>
  964. <option value="TOPIC">
  965. First song from topic channel
  966. (YouTube only)
  967. </option>
  968. <option value="LYRICS_TOPIC">
  969. First song with lyrics in title, or
  970. from topic channel (YouTube only)
  971. </option>
  972. <option value="TOPIC_LYRICS">
  973. First song from topic channel
  974. (YouTube only), or with lyrics in
  975. title
  976. </option>
  977. </select>
  978. </p>
  979. </div>
  980. <div
  981. class="small-section"
  982. v-if="currentConvertType === 'album'"
  983. >
  984. <label class="label"
  985. >Minimum songs per album</label
  986. >
  987. <div class="control is-expanded">
  988. <input
  989. class="input"
  990. type="number"
  991. min="1"
  992. v-model="minimumSongsPerAlbum"
  993. />
  994. </div>
  995. </div>
  996. <div
  997. class="small-section"
  998. v-if="currentConvertType === 'artist'"
  999. >
  1000. <label class="label"
  1001. >Minimum songs per artist</label
  1002. >
  1003. <div class="control is-expanded">
  1004. <input
  1005. class="input"
  1006. type="number"
  1007. min="1"
  1008. v-model="minimumSongsPerArtist"
  1009. />
  1010. </div>
  1011. </div>
  1012. <div
  1013. class="control"
  1014. v-if="currentConvertType === 'album'"
  1015. >
  1016. <label class="label">Sort album mode</label>
  1017. <p class="control is-expanded select">
  1018. <select v-model="sortAlbumMode">
  1019. <option value="SONG_COUNT_ASC">
  1020. Song count (ascending)
  1021. </option>
  1022. <option value="SONG_COUNT_DESC">
  1023. Song count (descending)
  1024. </option>
  1025. <option value="NAME_ASC">
  1026. Name (ascending)
  1027. </option>
  1028. <option value="NAME_DESC">
  1029. Name (descending)
  1030. </option>
  1031. </select>
  1032. </p>
  1033. </div>
  1034. <div
  1035. class="control"
  1036. v-if="currentConvertType === 'artist'"
  1037. >
  1038. <label class="label">Sort artist mode</label>
  1039. <p class="control is-expanded select">
  1040. <select v-model="sortArtistMode">
  1041. <option value="SONG_COUNT_ASC">
  1042. Song count (ascending)
  1043. </option>
  1044. <option value="SONG_COUNT_DESC">
  1045. Song count (descending)
  1046. </option>
  1047. <option value="NAME_ASC">
  1048. Name (ascending)
  1049. </option>
  1050. <option value="NAME_DESC">
  1051. Name (descending)
  1052. </option>
  1053. </select>
  1054. </p>
  1055. </div>
  1056. </div>
  1057. <div class="info">
  1058. <h6>Status</h6>
  1059. <p>Loading playlist: {{ loadingPlaylist }}</p>
  1060. <p>Loaded playlist: {{ loadedPlaylist }}</p>
  1061. <p>
  1062. Spotify songs in playlist:
  1063. {{ spotifySongs.length }}
  1064. </p>
  1065. <p>Converting by {{ currentConvertType }}</p>
  1066. <hr />
  1067. <p>
  1068. Loading Spotify tracks:
  1069. {{ loadingSpotifyTracks }}
  1070. </p>
  1071. <p>
  1072. Loaded Spotify tracks: {{ loadedSpotifyTracks }}
  1073. </p>
  1074. <p>
  1075. Spotify tracks loaded:
  1076. {{ Object.keys(spotifyTracks).length }}
  1077. </p>
  1078. <p>
  1079. Loading Spotify albums:
  1080. {{ loadingSpotifyAlbums }}
  1081. </p>
  1082. <p>
  1083. Loaded Spotify albums: {{ loadedSpotifyAlbums }}
  1084. </p>
  1085. <p>
  1086. Spotify albums:
  1087. {{ Object.keys(spotifyAlbums).length }}
  1088. </p>
  1089. <p>
  1090. Spotify artists:
  1091. {{ Object.keys(spotifyArtists).length }}
  1092. </p>
  1093. <p>
  1094. Getting missing alternative media:
  1095. {{ gettingMissingAlternativeMedia }}
  1096. </p>
  1097. <p>
  1098. Getting all alternative media per track:
  1099. {{ gettingAllAlternativeMediaPerTrack }}
  1100. </p>
  1101. <p>
  1102. Got all alternative media per track:
  1103. {{ gotAllAlternativeMediaPerTrack }}
  1104. </p>
  1105. <hr />
  1106. <p>
  1107. Alternative media loaded:
  1108. {{ Object.keys(alternativeMediaMap).length }}
  1109. </p>
  1110. <p>
  1111. Alternative media that failed to load:
  1112. {{
  1113. Object.keys(alternativeMediaFailedMap)
  1114. .length
  1115. }}
  1116. </p>
  1117. <hr />
  1118. <p>
  1119. Replacing all Spotify songs:
  1120. {{ replacingAllSpotifySongs }}
  1121. </p>
  1122. </div>
  1123. </div>
  1124. <br />
  1125. <hr />
  1126. <div
  1127. class="convert-table convert-song-by-track"
  1128. v-if="currentConvertType === 'track'"
  1129. >
  1130. <h4>Spotify songs</h4>
  1131. <h4>Alternative songs</h4>
  1132. <template
  1133. v-for="spotifySong in filteredSpotifySongs"
  1134. :key="spotifySong.mediaSource"
  1135. >
  1136. <div
  1137. class="convert-table-cell convert-table-cell-left"
  1138. >
  1139. <media-item :song="spotifySong">
  1140. <template #leftIcon>
  1141. <a
  1142. :href="`https://open.spotify.com/track/${
  1143. spotifySong.mediaSource.split(
  1144. ':'
  1145. )[1]
  1146. }`"
  1147. target="_blank"
  1148. >
  1149. <div
  1150. class="spotify-icon left-icon"
  1151. ></div>
  1152. </a>
  1153. </template>
  1154. </media-item>
  1155. <template v-if="showExtra">
  1156. <p>
  1157. Media source:
  1158. {{ spotifySong.mediaSource }}
  1159. </p>
  1160. <p v-if="loadedSpotifyTracks">
  1161. ISRC:
  1162. {{
  1163. spotifyTracks[
  1164. spotifySong.mediaSource
  1165. ].externalIds.isrc
  1166. }}
  1167. </p>
  1168. </template>
  1169. <button
  1170. v-if="showDontConvertButton"
  1171. class="button is-primary is-fullwidth"
  1172. @click="
  1173. removeSpotifySong(
  1174. spotifySong.mediaSource
  1175. )
  1176. "
  1177. >
  1178. Don't convert this song
  1179. </button>
  1180. </div>
  1181. <div
  1182. class="convert-table-cell convert-table-cell-right"
  1183. >
  1184. <p
  1185. v-if="
  1186. !alternativeMediaPerTrack[
  1187. spotifySong.mediaSource
  1188. ]
  1189. "
  1190. >
  1191. Alternatives not loaded yet
  1192. </p>
  1193. <template v-else>
  1194. <div class="alternative-media-items">
  1195. <div
  1196. class="alternative-media-item"
  1197. :class="{
  1198. 'selected-alternative-song':
  1199. preferredAlternativeSongPerTrack[
  1200. spotifySong.mediaSource
  1201. ] ===
  1202. alternativeMediaSource &&
  1203. missingMediaSources.length ===
  1204. 0
  1205. }"
  1206. v-for="alternativeMediaSource in alternativeMediaPerTrack[
  1207. spotifySong.mediaSource
  1208. ].mediaSources"
  1209. :key="
  1210. spotifySong.mediaSource +
  1211. alternativeMediaSource
  1212. "
  1213. >
  1214. <p
  1215. v-if="
  1216. alternativeMediaFailedMap[
  1217. alternativeMediaSource
  1218. ]
  1219. "
  1220. >
  1221. Song
  1222. {{ alternativeMediaSource }}
  1223. failed to load
  1224. </p>
  1225. <p
  1226. v-else-if="
  1227. !alternativeMediaMap[
  1228. alternativeMediaSource
  1229. ]
  1230. "
  1231. >
  1232. Song
  1233. {{ alternativeMediaSource }}
  1234. hasn't been loaded yet
  1235. </p>
  1236. <template v-else>
  1237. <div
  1238. class="alternative-song-container"
  1239. >
  1240. <media-item
  1241. :song="
  1242. alternativeMediaMap[
  1243. alternativeMediaSource
  1244. ]
  1245. "
  1246. >
  1247. <template #leftIcon>
  1248. <a
  1249. v-if="
  1250. alternativeMediaSource.split(
  1251. ':'
  1252. )[0] ===
  1253. 'youtube'
  1254. "
  1255. :href="`https://youtu.be/${
  1256. alternativeMediaSource.split(
  1257. ':'
  1258. )[1]
  1259. }`"
  1260. target="_blank"
  1261. >
  1262. <div
  1263. class="youtube-icon left-icon"
  1264. ></div>
  1265. </a>
  1266. <a
  1267. v-if="
  1268. alternativeMediaSource.split(
  1269. ':'
  1270. )[0] ===
  1271. 'soundcloud'
  1272. "
  1273. target="_blank"
  1274. >
  1275. <div
  1276. class="soundcloud-icon left-icon"
  1277. ></div>
  1278. </a>
  1279. </template>
  1280. </media-item>
  1281. <quick-confirm
  1282. v-if="
  1283. showReplaceButtonPerAlternative
  1284. "
  1285. placement="top"
  1286. @confirm="
  1287. replaceSpotifySong(
  1288. spotifySong.mediaSource,
  1289. alternativeMediaSource
  1290. )
  1291. "
  1292. >
  1293. <button
  1294. class="button is-primary is-fullwidth"
  1295. >
  1296. Use this alternative
  1297. </button>
  1298. </quick-confirm>
  1299. <button
  1300. v-if="
  1301. showDontConvertButton
  1302. "
  1303. class="button is-primary is-fullwidth"
  1304. @click="
  1305. removeAlternativeTrack(
  1306. spotifySong.mediaSource,
  1307. alternativeMediaSource
  1308. )
  1309. "
  1310. >
  1311. Remove this alternative
  1312. </button>
  1313. </div>
  1314. <ul v-if="showExtra">
  1315. <li
  1316. v-for="origin in alternativeMediaPerTrack[
  1317. spotifySong
  1318. .mediaSource
  1319. ].mediaSourcesOrigins[
  1320. alternativeMediaSource
  1321. ]"
  1322. :key="
  1323. spotifySong.mediaSource +
  1324. alternativeMediaSource +
  1325. origin
  1326. "
  1327. >
  1328. <hr />
  1329. <ul>
  1330. <li
  1331. v-for="originItem in origin"
  1332. :key="
  1333. spotifySong.mediaSource +
  1334. alternativeMediaSource +
  1335. origin +
  1336. originItem
  1337. "
  1338. >
  1339. +
  1340. {{ originItem }}
  1341. </li>
  1342. </ul>
  1343. </li>
  1344. </ul>
  1345. </template>
  1346. </div>
  1347. </div>
  1348. <p
  1349. v-if="
  1350. alternativeMediaPerTrack[
  1351. spotifySong.mediaSource
  1352. ].mediaSources.length === 0
  1353. "
  1354. >
  1355. No alternative media sources found
  1356. </p>
  1357. </template>
  1358. <div
  1359. v-if="
  1360. showReplacementInputs ||
  1361. (alternativeMediaPerTrack[
  1362. spotifySong.mediaSource
  1363. ] &&
  1364. alternativeMediaPerTrack[
  1365. spotifySong.mediaSource
  1366. ].mediaSources.length === 0)
  1367. "
  1368. >
  1369. <div>
  1370. <label class="label">
  1371. Enter replacement song from URL
  1372. </label>
  1373. <div
  1374. class="control is-grouped input-with-button"
  1375. >
  1376. <p class="control is-expanded">
  1377. <input
  1378. class="input"
  1379. type="text"
  1380. placeholder="Enter your song URL here..."
  1381. v-model="
  1382. replaceSongUrlMap[
  1383. spotifySong
  1384. .mediaSource
  1385. ]
  1386. "
  1387. @keyup.enter="
  1388. replaceSongFromUrl(
  1389. spotifySong.mediaSource
  1390. )
  1391. "
  1392. />
  1393. </p>
  1394. <p class="control">
  1395. <a
  1396. class="button is-info"
  1397. @click="
  1398. replaceSongFromUrl(
  1399. spotifySong.mediaSource
  1400. )
  1401. "
  1402. >Replace song</a
  1403. >
  1404. </p>
  1405. </div>
  1406. </div>
  1407. </div>
  1408. </div>
  1409. </template>
  1410. </div>
  1411. <div
  1412. class="convert-table convert-song-by-album"
  1413. v-if="currentConvertType === 'album'"
  1414. >
  1415. <h4>Spotify albums</h4>
  1416. <h4>Alternative albums (playlists)</h4>
  1417. <template
  1418. v-for="spotifyAlbum in filteredSpotifyAlbums"
  1419. :key="spotifyAlbum"
  1420. >
  1421. <div
  1422. class="convert-table-cell convert-table-cell-left"
  1423. >
  1424. <p>Album ID: {{ spotifyAlbum.albumId }}</p>
  1425. <p v-if="loadingSpotifyAlbums">
  1426. Loading album info...
  1427. </p>
  1428. <p
  1429. v-else-if="
  1430. loadedSpotifyAlbums &&
  1431. !spotifyAlbum.rawData
  1432. "
  1433. >
  1434. Failed to load album info...
  1435. </p>
  1436. <template v-else-if="loadedSpotifyAlbums">
  1437. <p>Name: {{ spotifyAlbum.rawData.name }}</p>
  1438. <p>
  1439. Label: {{ spotifyAlbum.rawData.label }}
  1440. </p>
  1441. <p>
  1442. Popularity:
  1443. {{ spotifyAlbum.rawData.popularity }}
  1444. </p>
  1445. <p>
  1446. Release date:
  1447. {{ spotifyAlbum.rawData.release_date }}
  1448. </p>
  1449. <p>
  1450. Artists:
  1451. {{
  1452. spotifyAlbum.rawData.artists
  1453. .map(artist => artist.name)
  1454. .join(", ")
  1455. }}
  1456. </p>
  1457. <p>
  1458. UPC:
  1459. {{
  1460. spotifyAlbum.rawData.external_ids
  1461. .upc
  1462. }}
  1463. </p>
  1464. </template>
  1465. <media-item
  1466. v-for="spotifyMediaSource in spotifyAlbum.songs"
  1467. :key="
  1468. spotifyAlbum.albumId +
  1469. spotifyMediaSource
  1470. "
  1471. :song="{
  1472. mediaSource: spotifyMediaSource,
  1473. title: spotifyTracks[spotifyMediaSource]
  1474. .name,
  1475. artists:
  1476. spotifyTracks[spotifyMediaSource]
  1477. .artists,
  1478. duration:
  1479. spotifyTracks[spotifyMediaSource]
  1480. .duration,
  1481. thumbnail:
  1482. spotifyTracks[spotifyMediaSource]
  1483. .albumImageUrl
  1484. }"
  1485. >
  1486. <template #leftIcon>
  1487. <a
  1488. :href="`https://open.spotify.com/track/${
  1489. spotifyMediaSource.split(':')[1]
  1490. }`"
  1491. target="_blank"
  1492. >
  1493. <div
  1494. class="spotify-icon left-icon"
  1495. ></div>
  1496. </a>
  1497. </template>
  1498. </media-item>
  1499. </div>
  1500. <div
  1501. class="convert-table-cell convert-table-cell-right"
  1502. >
  1503. <p
  1504. v-if="
  1505. !alternativeAlbumsPerAlbum[
  1506. spotifyAlbum.albumId
  1507. ]
  1508. "
  1509. >
  1510. No alternatives loaded
  1511. </p>
  1512. <div
  1513. class="alternative-album-items"
  1514. v-if="
  1515. alternativeAlbumsPerAlbum[
  1516. spotifyAlbum.albumId
  1517. ]
  1518. "
  1519. >
  1520. <p
  1521. v-if="
  1522. alternativeAlbumsPerAlbum[
  1523. spotifyAlbum.albumId
  1524. ].youtubePlaylistIds.length === 0
  1525. "
  1526. >
  1527. No alternative playlists were found
  1528. </p>
  1529. <div
  1530. class="alternative-album-item"
  1531. v-for="youtubePlaylistId in alternativeAlbumsPerAlbum[
  1532. spotifyAlbum.albumId
  1533. ].youtubePlaylistIds"
  1534. :key="
  1535. spotifyAlbum.albumId +
  1536. youtubePlaylistId
  1537. "
  1538. >
  1539. <p>
  1540. YouTube Playlist
  1541. {{ youtubePlaylistId }} has been
  1542. automatically found
  1543. </p>
  1544. <button
  1545. class="button is-primary is-fullwidth"
  1546. @click="
  1547. openReplaceAlbumModal(
  1548. spotifyAlbum.albumId,
  1549. youtubePlaylistId
  1550. )
  1551. "
  1552. >
  1553. Open replace modal
  1554. </button>
  1555. </div>
  1556. </div>
  1557. <div
  1558. v-if="
  1559. showReplacementInputs ||
  1560. (alternativeAlbumsPerAlbum[
  1561. spotifyAlbum.albumId
  1562. ] &&
  1563. alternativeAlbumsPerAlbum[
  1564. spotifyAlbum.albumId
  1565. ].youtubePlaylistIds.length === 0)
  1566. "
  1567. >
  1568. <div>
  1569. <label class="label">
  1570. Enter replacement playlist URL
  1571. </label>
  1572. <div
  1573. class="control is-grouped input-with-button"
  1574. >
  1575. <p class="control is-expanded">
  1576. <input
  1577. class="input"
  1578. type="text"
  1579. placeholder="Enter your playlist URL here..."
  1580. v-model="
  1581. replaceSongUrlMap[
  1582. `album:${spotifyAlbum.albumId}`
  1583. ]
  1584. "
  1585. @keyup.enter="
  1586. openReplaceAlbumModalFromUrl(
  1587. spotifyAlbum.albumId
  1588. )
  1589. "
  1590. />
  1591. </p>
  1592. <p class="control">
  1593. <a
  1594. class="button is-info"
  1595. @click="
  1596. openReplaceAlbumModalFromUrl(
  1597. spotifyAlbum.albumId
  1598. )
  1599. "
  1600. >Open replace modal</a
  1601. >
  1602. </p>
  1603. </div>
  1604. </div>
  1605. </div>
  1606. </div>
  1607. </template>
  1608. </div>
  1609. <div
  1610. class="convert-table convert-song-by-artist"
  1611. v-if="currentConvertType === 'artist'"
  1612. >
  1613. <h4>Spotify artists</h4>
  1614. <h4>Alternative artists (channels)</h4>
  1615. <template
  1616. v-for="spotifyArtist in filteredSpotifyArtists"
  1617. :key="spotifyArtist"
  1618. >
  1619. <div
  1620. class="convert-table-cell convert-table-cell-left"
  1621. >
  1622. <p>Artist ID: {{ spotifyArtist.artistId }}</p>
  1623. <p v-if="loadingSpotifyArtists">
  1624. Loading artist info...
  1625. </p>
  1626. <p
  1627. v-else-if="
  1628. loadedSpotifyArtists &&
  1629. !spotifyArtist.rawData
  1630. "
  1631. >
  1632. Failed to load artist info...
  1633. </p>
  1634. <template v-else-if="loadedSpotifyArtists">
  1635. <p>
  1636. Name: {{ spotifyArtist.rawData.name }}
  1637. </p>
  1638. <!-- <p>
  1639. Label: {{ spotifyArtist.rawData.label }}
  1640. </p>
  1641. <p>
  1642. Popularity:
  1643. {{ spotifyArtist.rawData.popularity }}
  1644. </p>
  1645. <p>
  1646. Release date:
  1647. {{ spotifyArtist.rawData.release_date }}
  1648. </p>
  1649. <p>
  1650. Artists:
  1651. {{
  1652. spotifyArtist.rawData.artists
  1653. .map(artist => artist.name)
  1654. .join(", ")
  1655. }}
  1656. </p>
  1657. <p>
  1658. UPC:
  1659. {{
  1660. spotifyArtist.rawData.external_ids
  1661. .upc
  1662. }}
  1663. </p> -->
  1664. </template>
  1665. <media-item
  1666. v-for="spotifyMediaSource in spotifyArtist.songs"
  1667. :key="
  1668. spotifyArtist.artistId +
  1669. spotifyMediaSource
  1670. "
  1671. :song="{
  1672. mediaSource: spotifyMediaSource,
  1673. title: spotifyTracks[spotifyMediaSource]
  1674. .name,
  1675. artists:
  1676. spotifyTracks[spotifyMediaSource]
  1677. .artists,
  1678. duration:
  1679. spotifyTracks[spotifyMediaSource]
  1680. .duration,
  1681. thumbnail:
  1682. spotifyTracks[spotifyMediaSource]
  1683. .albumImageUrl
  1684. }"
  1685. >
  1686. <template #leftIcon>
  1687. <a
  1688. :href="`https://open.spotify.com/track/${
  1689. spotifyMediaSource.split(':')[1]
  1690. }`"
  1691. target="_blank"
  1692. >
  1693. <div
  1694. class="spotify-icon left-icon"
  1695. ></div>
  1696. </a>
  1697. </template>
  1698. </media-item>
  1699. </div>
  1700. <div
  1701. class="convert-table-cell convert-table-cell-right"
  1702. >
  1703. <p
  1704. v-if="
  1705. !alternativeArtistsPerArtist[
  1706. spotifyArtist.artistId
  1707. ]
  1708. "
  1709. >
  1710. No alternatives loaded
  1711. </p>
  1712. <div
  1713. class="alternative-artist-items"
  1714. v-if="
  1715. alternativeArtistsPerArtist[
  1716. spotifyArtist.artistId
  1717. ]
  1718. "
  1719. >
  1720. <p
  1721. v-if="
  1722. alternativeArtistsPerArtist[
  1723. spotifyArtist.artistId
  1724. ].youtubeChannelIds.length === 0
  1725. "
  1726. >
  1727. No alternative channels were found
  1728. </p>
  1729. <div
  1730. class="alternative-artist-item"
  1731. v-for="youtubeChannelId in alternativeArtistsPerArtist[
  1732. spotifyArtist.artistId
  1733. ].youtubeChannelIds"
  1734. :key="
  1735. spotifyArtist.artistId +
  1736. youtubeChannelId
  1737. "
  1738. >
  1739. <p>
  1740. YouTube channel
  1741. {{ youtubeChannelId }} has been
  1742. automatically found
  1743. </p>
  1744. <button
  1745. class="button is-primary is-fullwidth"
  1746. @click="
  1747. openReplaceArtistModal(
  1748. spotifyArtist.artistId,
  1749. `https://youtube.com/channel/${youtubeChannelId}`
  1750. )
  1751. "
  1752. >
  1753. Open replace modal
  1754. </button>
  1755. </div>
  1756. </div>
  1757. <div
  1758. v-if="
  1759. showReplacementInputs ||
  1760. (alternativeArtistsPerArtist[
  1761. spotifyArtist.artistId
  1762. ] &&
  1763. alternativeArtistsPerArtist[
  1764. spotifyArtist.artistId
  1765. ].youtubeChannelIds.length === 0)
  1766. "
  1767. >
  1768. <div>
  1769. <label class="label">
  1770. Enter replacement YouTube channel
  1771. URL
  1772. </label>
  1773. <div
  1774. class="control is-grouped input-with-button"
  1775. >
  1776. <p class="control is-expanded">
  1777. <input
  1778. class="input"
  1779. type="text"
  1780. placeholder="Enter your channel URL here..."
  1781. v-model="
  1782. replaceSongUrlMap[
  1783. `artist:${spotifyArtist.artistId}`
  1784. ]
  1785. "
  1786. @keyup.enter="
  1787. openReplaceArtistModalFromUrl(
  1788. spotifyArtist.artistId
  1789. )
  1790. "
  1791. />
  1792. </p>
  1793. <p class="control">
  1794. <a
  1795. class="button is-info"
  1796. @click="
  1797. openReplaceArtistModalFromUrl(
  1798. spotifyArtist.artistId
  1799. )
  1800. "
  1801. >Open replace modal</a
  1802. >
  1803. </p>
  1804. </div>
  1805. </div>
  1806. </div>
  1807. </div>
  1808. </template>
  1809. </div>
  1810. </template>
  1811. </template>
  1812. </modal>
  1813. </div>
  1814. </template>
  1815. <style lang="less" scoped>
  1816. :deep(.song-item) {
  1817. .left-icon {
  1818. cursor: pointer;
  1819. }
  1820. }
  1821. .tracks {
  1822. display: flex;
  1823. flex-direction: column;
  1824. .track-row {
  1825. .left,
  1826. .right {
  1827. padding: 8px;
  1828. width: 50%;
  1829. box-shadow: inset 0px 0px 1px white;
  1830. display: flex;
  1831. flex-direction: column;
  1832. row-gap: 8px;
  1833. }
  1834. }
  1835. }
  1836. .alternative-media-items {
  1837. display: flex;
  1838. flex-direction: column;
  1839. row-gap: 12px;
  1840. }
  1841. .alternative-song-container,
  1842. .convert-table-cell-left {
  1843. display: flex;
  1844. flex-direction: column;
  1845. row-gap: 12px;
  1846. > * {
  1847. flex-grow: 0;
  1848. }
  1849. }
  1850. .convert-table {
  1851. display: grid;
  1852. grid-template-columns: 50% 50%;
  1853. gap: 1px;
  1854. .convert-table-cell {
  1855. outline: 1px solid white;
  1856. padding: 4px;
  1857. }
  1858. }
  1859. .selected-alternative-song {
  1860. // outline: 4px solid red;
  1861. border-left: 12px solid var(--primary-color);
  1862. padding: 4px;
  1863. }
  1864. .buttons-options-info-row {
  1865. display: grid;
  1866. grid-template-columns: 33.3% 33.3% 33.3%;
  1867. gap: 8px;
  1868. .buttons,
  1869. .options {
  1870. display: flex;
  1871. flex-direction: column;
  1872. row-gap: 8px;
  1873. > .control {
  1874. margin-bottom: 0 !important;
  1875. }
  1876. }
  1877. }
  1878. // .column-headers {
  1879. // display: flex;
  1880. // flex-direction: row;
  1881. // .column-header {
  1882. // flex: 1;
  1883. // }
  1884. // }
  1885. // .artists {
  1886. // display: flex;
  1887. // flex-direction: column;
  1888. // .artist-item {
  1889. // display: flex;
  1890. // flex-direction: column;
  1891. // row-gap: 8px;
  1892. // box-shadow: inset 0px 0px 1px white;
  1893. // width: 50%;
  1894. // position: relative;
  1895. // .spotify-section {
  1896. // display: flex;
  1897. // flex-direction: column;
  1898. // row-gap: 8px;
  1899. // padding: 8px 12px;
  1900. // .spotify-songs {
  1901. // display: flex;
  1902. // flex-direction: column;
  1903. // row-gap: 4px;
  1904. // }
  1905. // }
  1906. // .soundcloud-section {
  1907. // position: absolute;
  1908. // left: 100%;
  1909. // top: 0;
  1910. // width: 100%;
  1911. // height: 100%;
  1912. // overflow: hidden;
  1913. // box-shadow: inset 0px 0px 1px white;
  1914. // padding: 8px 12px;
  1915. // }
  1916. // }
  1917. // }
  1918. </style>