EditSong.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. <template>
  2. <div>
  3. <modal title="Edit Song" class="song-modal">
  4. <div slot="body">
  5. <div class="left-section">
  6. <div class="top-section">
  7. <div class="player-section">
  8. <div id="player"></div>
  9. <canvas
  10. id="durationCanvas"
  11. height="20"
  12. width="530"
  13. ></canvas>
  14. <div class="player-footer">
  15. <div class="player-footer-left">
  16. <i
  17. class="material-icons player-play-pause"
  18. v-on:click="settings('play')"
  19. v-if="video.paused"
  20. >play_arrow</i
  21. >
  22. <i
  23. class="material-icons player-play-pause"
  24. v-on:click="settings('pause')"
  25. v-if="!video.paused"
  26. >pause</i
  27. >
  28. <i
  29. class="material-icons player-stop"
  30. v-on:click="settings('stop')"
  31. >stop</i
  32. >
  33. <i
  34. class="material-icons player-fast-forward"
  35. v-on:click="
  36. settings('skipToLast10Secs')
  37. "
  38. >fast_forward</i
  39. >
  40. </div>
  41. <div class="player-footer-center">
  42. <img src="/assets/social/youtube.svg" />
  43. <span>
  44. <span>
  45. {{ youtubeVideoCurrentTime }}
  46. </span>
  47. /
  48. <span>
  49. {{ youtubeVideoDuration }}
  50. {{ youtubeVideoNote }}
  51. </span>
  52. </span>
  53. </div>
  54. <div class="player-footer-right">
  55. <input
  56. type="range"
  57. id="volumeSlider"
  58. min="0"
  59. max="100"
  60. class="active"
  61. v-on:change="changeVolume()"
  62. v-on:input="changeVolume()"
  63. />
  64. </div>
  65. </div>
  66. </div>
  67. <img
  68. class="thumbnail-preview"
  69. :src="editing.song.thumbnail"
  70. onerror="this.src='/assets/notes-transparent.png'"
  71. />
  72. </div>
  73. <div class="edit-section">
  74. <div class="control is-grouped">
  75. <div class="title-container">
  76. <label class="label">Title</label>
  77. <p class="control has-addons">
  78. <input
  79. class="input"
  80. type="text"
  81. v-model="editing.song.title"
  82. />
  83. <button
  84. class="button album-get-button"
  85. v-on:click="getAlbumData('title')"
  86. >
  87. <i class="material-icons album-get-icon"
  88. >album</i
  89. >
  90. </button>
  91. </p>
  92. </div>
  93. <div class="duration-container">
  94. <label class="label">Duration</label>
  95. <p class="control">
  96. <input
  97. class="input"
  98. type="text"
  99. v-model="editing.song.duration"
  100. />
  101. </p>
  102. </div>
  103. <div class="skip-duration-container">
  104. <label class="label">Skip duration</label>
  105. <p class="control">
  106. <input
  107. class="input"
  108. type="text"
  109. v-model="editing.song.skipDuration"
  110. />
  111. </p>
  112. </div>
  113. </div>
  114. <div class="control is-grouped">
  115. <div class="album-art-container">
  116. <label class="label">Album art</label>
  117. <p class="control has-addons">
  118. <input
  119. class="input"
  120. type="text"
  121. v-model="editing.song.thumbnail"
  122. />
  123. <button
  124. class="button album-get-button"
  125. v-on:click="getAlbumData('albumArt')"
  126. >
  127. <i class="material-icons album-get-icon"
  128. >album</i
  129. >
  130. </button>
  131. </p>
  132. </div>
  133. </div>
  134. <div class="control is-grouped">
  135. <div class="artists-container">
  136. <label class="label">Artists</label>
  137. <p class="control has-addons">
  138. <input
  139. class="input"
  140. type="text"
  141. id="new-artist"
  142. v-model="artistInputValue"
  143. v-on:blur="blurArtistInput()"
  144. v-on:focus="focusArtistInput()"
  145. v-on:keydown="keydownArtistInput()"
  146. />
  147. <button
  148. class="button album-get-button"
  149. v-on:click="getAlbumData('artists')"
  150. >
  151. <i class="material-icons album-get-icon"
  152. >album</i
  153. >
  154. </button>
  155. <button
  156. class="button is-info add-button"
  157. v-on:click="addTag('artists')"
  158. >
  159. <i class="material-icons">add</i>
  160. </button>
  161. </p>
  162. <div
  163. class="autosuggest-container"
  164. v-if="
  165. (artistInputFocussed ||
  166. artistAutosuggestContainerFocussed) &&
  167. artistAutosuggestItems.length > 0
  168. "
  169. @mouseover="focusArtistContainer()"
  170. @mouseleave="blurArtistContainer()"
  171. >
  172. <span
  173. class="autosuggest-item"
  174. tabindex="0"
  175. v-on:click="
  176. selectArtistAutosuggest(item)
  177. "
  178. v-for="(item,
  179. index) in artistAutosuggestItems"
  180. :key="index"
  181. >{{ item }}</span
  182. >
  183. </div>
  184. <div class="list-container">
  185. <div
  186. class="list-item"
  187. v-for="(artist, index) in editing.song
  188. .artists"
  189. :key="index"
  190. >
  191. <div
  192. class="list-item-circle"
  193. v-on:click="
  194. removeTag('artists', index)
  195. "
  196. >
  197. <i class="material-icons">close</i>
  198. </div>
  199. <p>{{ artist }}</p>
  200. </div>
  201. </div>
  202. </div>
  203. <div class="genres-container">
  204. <label class="label">Genres</label>
  205. <p class="control has-addons">
  206. <input
  207. class="input"
  208. type="text"
  209. id="new-genre"
  210. v-model="genreInputValue"
  211. v-on:blur="blurGenreInput()"
  212. v-on:focus="focusGenreInput()"
  213. v-on:keydown="keydownGenreInput()"
  214. />
  215. <button
  216. class="button album-get-button"
  217. v-on:click="getAlbumData('genres')"
  218. >
  219. <i class="material-icons album-get-icon"
  220. >album</i
  221. >
  222. </button>
  223. <button
  224. class="button is-info add-button"
  225. v-on:click="addTag('genres')"
  226. >
  227. <i class="material-icons">add</i>
  228. </button>
  229. </p>
  230. <div
  231. class="autosuggest-container"
  232. v-if="
  233. (genreInputFocussed ||
  234. genreAutosuggestContainerFocussed) &&
  235. genreAutosuggestItems.length > 0
  236. "
  237. @mouseover="focusGenreContainer()"
  238. @mouseleave="blurGenreContainer()"
  239. >
  240. <span
  241. class="autosuggest-item"
  242. tabindex="0"
  243. v-on:click="
  244. selectGenreAutosuggest(item)
  245. "
  246. v-for="(item,
  247. index) in genreAutosuggestItems"
  248. :key="index"
  249. >{{ item }}</span
  250. >
  251. </div>
  252. <div class="list-container">
  253. <div
  254. class="list-item"
  255. v-for="(genre, index) in editing.song
  256. .genres"
  257. :key="index"
  258. >
  259. <div
  260. class="list-item-circle"
  261. v-on:click="
  262. removeTag('genres', index)
  263. "
  264. >
  265. <i class="material-icons">close</i>
  266. </div>
  267. <p>{{ genre }}</p>
  268. </div>
  269. </div>
  270. </div>
  271. <div class="youtube-id-container">
  272. <label class="label">YouTube ID</label>
  273. <p class="control">
  274. <input
  275. class="input"
  276. type="text"
  277. v-model="editing.song.songId"
  278. />
  279. </p>
  280. </div>
  281. </div>
  282. </div>
  283. </div>
  284. <div class="right-section">
  285. <div class="api-section">
  286. <div
  287. class="selected-discogs-info"
  288. v-if="!editing.song.discogs"
  289. >
  290. <p class="selected-discogs-info-none">None</p>
  291. </div>
  292. <div
  293. class="selected-discogs-info"
  294. v-if="editing.song.discogs"
  295. >
  296. <div class="top-container">
  297. <img
  298. :src="editing.song.discogs.album.albumArt"
  299. />
  300. <div class="right-container">
  301. <p class="album-title">
  302. {{ editing.song.discogs.album.title }}
  303. </p>
  304. <div class="bottom-row">
  305. <p class="type-year">
  306. <span>{{
  307. editing.song.discogs.album.type
  308. }}</span>
  309. <span>{{
  310. editing.song.discogs.album.year
  311. }}</span>
  312. </p>
  313. </div>
  314. </div>
  315. </div>
  316. <div class="bottom-container">
  317. <p class="bottom-container-field">
  318. Artists:
  319. <span>{{
  320. editing.song.discogs.album.artists.join(
  321. ", "
  322. )
  323. }}</span>
  324. </p>
  325. <p class="bottom-container-field">
  326. Genres:
  327. <span>{{
  328. editing.song.discogs.album.genres.join(
  329. ", "
  330. )
  331. }}</span>
  332. </p>
  333. <p class="bottom-container-field">
  334. Data quality:
  335. <span>{{
  336. editing.song.discogs.dataQuality
  337. }}</span>
  338. </p>
  339. <p class="bottom-container-field">
  340. Track:
  341. <span
  342. >{{
  343. editing.song.discogs.track.position
  344. }}.
  345. {{
  346. editing.song.discogs.track.title
  347. }}</span
  348. >
  349. </p>
  350. </div>
  351. </div>
  352. <p class="control is-expanded">
  353. <label class="label">Search query</label>
  354. <input
  355. class="input"
  356. type="text"
  357. v-model="discogsQuery"
  358. />
  359. </p>
  360. <button
  361. class="button is-info is-fullwidth"
  362. v-on:click="searchDiscogs()"
  363. >
  364. Search
  365. </button>
  366. <label
  367. class="label"
  368. v-if="discogs.apiResults.length > 0"
  369. >API results</label
  370. >
  371. <div
  372. class="api-results-container"
  373. v-if="discogs.apiResults.length > 0"
  374. >
  375. <div
  376. class="api-result"
  377. v-for="(result, index) in discogs.apiResults"
  378. :key="index"
  379. >
  380. <div class="top-container">
  381. <img :src="result.album.albumArt" />
  382. <div class="right-container">
  383. <p class="album-title">
  384. {{ result.album.title }}
  385. </p>
  386. <div class="bottom-row">
  387. <img
  388. src="/assets/arrow_up.svg"
  389. v-if="result.expanded"
  390. v-on:click="
  391. toggleAPIResult(index)
  392. "
  393. />
  394. <img
  395. src="/assets/arrow_down.svg"
  396. v-if="!result.expanded"
  397. v-on:click="
  398. toggleAPIResult(index)
  399. "
  400. />
  401. <p class="type-year">
  402. <span>{{
  403. result.album.type
  404. }}</span>
  405. <span>{{
  406. result.album.year
  407. }}</span>
  408. </p>
  409. </div>
  410. </div>
  411. </div>
  412. <div
  413. class="bottom-container"
  414. v-if="result.expanded"
  415. >
  416. <p class="bottom-container-field">
  417. Artists:
  418. <span>{{
  419. result.album.artists.join(", ")
  420. }}</span>
  421. </p>
  422. <p class="bottom-container-field">
  423. Genres:
  424. <span>{{
  425. result.album.genres.join(", ")
  426. }}</span>
  427. </p>
  428. <p class="bottom-container-field">
  429. Data quality:
  430. <span>{{ result.dataQuality }}</span>
  431. </p>
  432. <div class="tracks">
  433. <div
  434. class="track"
  435. tabindex="0"
  436. v-for="(track,
  437. trackIndex) in result.tracks"
  438. :key="trackIndex"
  439. v-on:click="
  440. selectTrack(index, trackIndex)
  441. "
  442. >
  443. <span>{{ track.position }}.</span>
  444. <p>{{ track.title }}</p>
  445. </div>
  446. </div>
  447. </div>
  448. </div>
  449. </div>
  450. </div>
  451. </div>
  452. </div>
  453. <div slot="footer" class="footer-buttons">
  454. <button
  455. class="button is-success"
  456. v-on:click="save(editing.song, false)"
  457. >
  458. <i class="material-icons save-changes">done</i>
  459. <span>&nbsp;Save</span>
  460. </button>
  461. <button
  462. class="button is-success"
  463. v-on:click="save(editing.song, true)"
  464. >
  465. <i class="material-icons save-changes">done</i>
  466. <span>&nbsp;Save and close</span>
  467. </button>
  468. <button
  469. class="button is-danger"
  470. v-on:click="
  471. closeModal({ sector: 'admin', modal: 'editSong' })
  472. "
  473. >
  474. <span>&nbsp;Close</span>
  475. </button>
  476. </div>
  477. </modal>
  478. </div>
  479. </template>
  480. <script>
  481. import { mapState, mapActions } from "vuex";
  482. import { Toast } from "vue-roaster";
  483. import io from "../../io";
  484. import validation from "../../validation";
  485. import Modal from "./Modal.vue";
  486. export default {
  487. components: { Modal },
  488. data() {
  489. return {
  490. discogsQuery: "",
  491. youtubeVideoDuration: 0.0,
  492. youtubeVideoCurrentTime: 0.0,
  493. youtubeVideoNote: "",
  494. useHTTPS: false,
  495. discogs: {
  496. apiResults: []
  497. },
  498. artistInputValue: "",
  499. genreInputValue: "",
  500. artistInputFocussed: false,
  501. genreInputFocussed: false,
  502. genreAutosuggestContainerFocussed: false,
  503. artistAutosuggestContainerFocussed: false,
  504. keydownArtistInputTimeout: 0,
  505. keydownGenreInputTimeout: 0,
  506. artistAutosuggestItems: [],
  507. genreAutosuggestItems: []
  508. };
  509. },
  510. computed: {
  511. ...mapState("admin/songs", {
  512. video: state => state.video,
  513. editing: state => state.editing,
  514. songs: state => state.songs
  515. }),
  516. ...mapState("modals", {
  517. modals: state => state.modals.admin
  518. })
  519. },
  520. methods: {
  521. save(songToCopy, close) {
  522. const song = JSON.parse(JSON.stringify(songToCopy));
  523. if (!song.title)
  524. return Toast.methods.addToast(
  525. "Please fill in all fields",
  526. 8000
  527. );
  528. if (!song.thumbnail)
  529. return Toast.methods.addToast(
  530. "Please fill in all fields",
  531. 8000
  532. );
  533. // Duration
  534. if (
  535. Number(song.skipDuration) + Number(song.duration) >
  536. this.youtubeVideoDuration
  537. ) {
  538. return Toast.methods.addToast(
  539. "Duration can't be higher than the length of the video",
  540. 8000
  541. );
  542. }
  543. // Title
  544. if (!validation.isLength(song.title, 1, 100))
  545. return Toast.methods.addToast(
  546. "Title must have between 1 and 100 characters.",
  547. 8000
  548. );
  549. /* if (!validation.regex.ascii.test(song.title))
  550. return Toast.methods.addToast(
  551. "Invalid title format. Only ascii characters are allowed.",
  552. 8000
  553. ); */
  554. // Artists
  555. if (song.artists.length < 1 || song.artists.length > 10)
  556. return Toast.methods.addToast(
  557. "Invalid artists. You must have at least 1 artist and a maximum of 10 artists.",
  558. 8000
  559. );
  560. let error;
  561. song.artists.forEach(artist => {
  562. if (!validation.isLength(artist, 1, 32)) {
  563. error = "Artist must have between 1 and 32 characters.";
  564. return error;
  565. }
  566. if (!validation.regex.ascii.test(artist)) {
  567. error =
  568. "Invalid artist format. Only ascii characters are allowed.";
  569. return error;
  570. }
  571. if (artist === "NONE") {
  572. error =
  573. 'Invalid artist format. Artists are not allowed to be named "NONE".';
  574. return error;
  575. }
  576. return false;
  577. });
  578. if (error) return Toast.methods.addToast(error, 8000);
  579. // Genres
  580. error = undefined;
  581. song.genres.forEach(genre => {
  582. if (!validation.isLength(genre, 1, 16)) {
  583. error = "Genre must have between 1 and 16 characters.";
  584. return error;
  585. }
  586. if (!validation.regex.azAZ09_.test(genre)) {
  587. error =
  588. "Invalid genre format. Only ascii characters are allowed.";
  589. return error;
  590. }
  591. return false;
  592. });
  593. if (error) return Toast.methods.addToast(error, 8000);
  594. // Thumbnail
  595. if (!validation.isLength(song.thumbnail, 8, 256))
  596. return Toast.methods.addToast(
  597. "Thumbnail must have between 8 and 256 characters.",
  598. 8000
  599. );
  600. if (this.useHTTPS && song.thumbnail.indexOf("https://") !== 0) {
  601. return Toast.methods.addToast(
  602. 'Thumbnail must start with "https://".',
  603. 8000
  604. );
  605. }
  606. if (
  607. !this.useHTTPS &&
  608. (song.thumbnail.indexOf("http://") !== 0 &&
  609. song.thumbnail.indexOf("https://") !== 0)
  610. ) {
  611. return Toast.methods.addToast(
  612. 'Thumbnail must start with "http://".',
  613. 8000
  614. );
  615. }
  616. return this.socket.emit(
  617. `${this.editing.type}.update`,
  618. song._id,
  619. song,
  620. res => {
  621. Toast.methods.addToast(res.message, 4000);
  622. if (res.status === "success") {
  623. this.songs.forEach(originalSong => {
  624. const updatedSong = song;
  625. if (originalSong._id === updatedSong._id) {
  626. Object.keys(originalSong).forEach(n => {
  627. updatedSong[n] = originalSong[n];
  628. return originalSong[n];
  629. });
  630. }
  631. });
  632. }
  633. if (close)
  634. this.closeModal({
  635. sector: "admin",
  636. modal: "editSong"
  637. });
  638. }
  639. );
  640. },
  641. toggleAPIResult(index) {
  642. const apiResult = this.discogs.apiResults[index];
  643. if (apiResult.expanded === true) apiResult.expanded = false;
  644. else if (apiResult.gotMoreInfo === true) apiResult.expanded = true;
  645. else {
  646. fetch(apiResult.album.resourceUrl)
  647. .then(response => {
  648. return response.json();
  649. })
  650. .then(data => {
  651. apiResult.album.artists = [];
  652. apiResult.album.artistIds = [];
  653. const artistRegex = new RegExp(" \\([0-9]\\)$");
  654. apiResult.dataQuality = data.data_quality;
  655. data.artists.forEach(artist => {
  656. apiResult.album.artists.push(
  657. artist.name.replace(artistRegex, "")
  658. );
  659. apiResult.album.artistIds.push(artist.id);
  660. });
  661. apiResult.tracks = data.tracklist.map(track => {
  662. return {
  663. position: track.position,
  664. title: track.title
  665. };
  666. });
  667. apiResult.expanded = true;
  668. apiResult.gotMoreInfo = true;
  669. });
  670. }
  671. },
  672. getAlbumData(type) {
  673. if (!this.editing.song.discogs) return;
  674. if (type === "title")
  675. this.updateSongField({
  676. field: "title",
  677. value: this.editing.song.discogs.track.title
  678. });
  679. if (type === "albumArt")
  680. this.updateSongField({
  681. field: "thumbnail",
  682. value: this.editing.song.discogs.album.albumArt
  683. });
  684. if (type === "genres")
  685. this.updateSongField({
  686. field: "genres",
  687. value: this.editing.song.discogs.album.genres
  688. });
  689. if (type === "artists")
  690. this.updateSongField({
  691. field: "artists",
  692. value: this.editing.song.discogs.album.artists
  693. });
  694. },
  695. searchDiscogs() {
  696. const query = this.discogsQuery;
  697. this.socket.emit("apis.searchDiscogs", query, res => {
  698. if (res.status === "success") {
  699. Toast.methods.addToast(
  700. `Successfully searched. Got ${res.results.length} results.`,
  701. 4000
  702. );
  703. this.discogs.apiResults = res.results.map(result => {
  704. const type =
  705. result.type.charAt(0).toUpperCase() +
  706. result.type.slice(1);
  707. return {
  708. expanded: false,
  709. gotMoreInfo: false,
  710. album: {
  711. id: result.id,
  712. title: result.title,
  713. type,
  714. year: result.year,
  715. genres: result.genre,
  716. albumArt: result.cover_image,
  717. resourceUrl: result.resource_url
  718. }
  719. };
  720. });
  721. } else Toast.methods.addToast(res.message, 8000);
  722. });
  723. },
  724. selectTrack(apiResultIndex, trackIndex) {
  725. const apiResult = JSON.parse(
  726. JSON.stringify(this.discogs.apiResults[apiResultIndex])
  727. );
  728. apiResult.track = apiResult.tracks[trackIndex];
  729. delete apiResult.tracks;
  730. delete apiResult.expanded;
  731. delete apiResult.gotMoreInfo;
  732. this.selectDiscogsInfo(apiResult);
  733. },
  734. blurArtistInput() {
  735. this.artistInputFocussed = false;
  736. },
  737. focusArtistInput() {
  738. this.artistInputFocussed = true;
  739. },
  740. blurArtistContainer() {
  741. this.artistAutosuggestContainerFocussed = false;
  742. },
  743. focusArtistContainer() {
  744. this.artistAutosuggestContainerFocussed = true;
  745. },
  746. keydownArtistInput() {
  747. clearTimeout(this.keydownArtistInputTimeout);
  748. this.keydownArtistInputTimeout = setTimeout(() => {
  749. // Do things here to query the artist
  750. }, 1000);
  751. },
  752. selectArtistAutosuggest(value) {
  753. this.artistInputValue = value;
  754. },
  755. blurGenreInput() {
  756. this.genreInputFocussed = false;
  757. },
  758. focusGenreInput() {
  759. this.genreInputFocussed = true;
  760. },
  761. blurGenreContainer() {
  762. this.genreAutosuggestContainerFocussed = false;
  763. },
  764. focusGenreContainer() {
  765. this.genreAutosuggestContainerFocussed = true;
  766. },
  767. keydownGenreInput() {
  768. clearTimeout(this.keydownGenreInputTimeout);
  769. this.keydownGenreInputTimeout = setTimeout(() => {
  770. if (this.genreInputValue.length > 1) {
  771. const genres = ["EDM", "Pop", "Rock"];
  772. this.genreAutosuggestItems = genres.filter(genre => {
  773. return genre
  774. .toLowerCase()
  775. .startsWith(this.genreInputValue.toLowerCase());
  776. });
  777. } else this.genreAutosuggestItems = [];
  778. }, 1000);
  779. },
  780. selectGenreAutosuggest(value) {
  781. this.genreInputValue = value;
  782. },
  783. settings(type) {
  784. switch (type) {
  785. default:
  786. break;
  787. case "stop":
  788. this.stopVideo();
  789. this.pauseVideo(true);
  790. break;
  791. case "pause":
  792. this.pauseVideo(true);
  793. break;
  794. case "play":
  795. this.pauseVideo(false);
  796. break;
  797. case "skipToLast10Secs":
  798. this.video.player.seekTo(
  799. this.editing.song.duration -
  800. 10 +
  801. this.editing.song.skipDuration
  802. );
  803. break;
  804. }
  805. },
  806. changeVolume() {
  807. const volume = document.getElementById("volumeSlider").value;
  808. localStorage.setItem("volume", volume);
  809. this.video.player.setVolume(volume);
  810. if (volume > 0) this.video.player.unMute();
  811. },
  812. addTag(type) {
  813. if (type === "genres") {
  814. const genre = document
  815. .getElementById("new-genre")
  816. .value.toLowerCase()
  817. .trim();
  818. if (this.editing.song.genres.indexOf(genre) !== -1)
  819. return Toast.methods.addToast("Genre already exists", 3000);
  820. if (genre) {
  821. this.editing.song.genres.push(genre);
  822. document.getElementById("new-genre").value = "";
  823. return false;
  824. }
  825. return Toast.methods.addToast("Genre cannot be empty", 3000);
  826. }
  827. if (type === "artists") {
  828. const artist = document.getElementById("new-artist").value;
  829. if (this.editing.song.artists.indexOf(artist) !== -1)
  830. return Toast.methods.addToast(
  831. "Artist already exists",
  832. 3000
  833. );
  834. if (document.getElementById("new-artist").value !== "") {
  835. this.editing.song.artists.push(artist);
  836. document.getElementById("new-artist").value = "";
  837. return false;
  838. }
  839. return Toast.methods.addToast("Artist cannot be empty", 3000);
  840. }
  841. return false;
  842. },
  843. removeTag(type, index) {
  844. if (type === "genres") this.editing.song.genres.splice(index, 1);
  845. else if (type === "artists")
  846. this.editing.song.artists.splice(index, 1);
  847. },
  848. drawCanvas() {
  849. const canvasElement = document.getElementById("durationCanvas");
  850. const ctx = canvasElement.getContext("2d");
  851. const videoDuration = Number(this.youtubeVideoDuration);
  852. const skipDuration = Number(this.editing.song.skipDuration);
  853. const duration = Number(this.editing.song.duration);
  854. const afterDuration = videoDuration - (skipDuration + duration);
  855. const width = 560;
  856. const currentTime = this.video.player.getCurrentTime();
  857. const widthSkipDuration = (skipDuration / videoDuration) * width;
  858. const widthDuration = (duration / videoDuration) * width;
  859. const widthAfterDuration = (afterDuration / videoDuration) * width;
  860. const widthCurrentTime = (currentTime / videoDuration) * width;
  861. const skipDurationColor = "#F42003";
  862. const durationColor = "#03A9F4";
  863. const afterDurationColor = "#41E841";
  864. const currentDurationColor = "#3b25e8";
  865. ctx.fillStyle = skipDurationColor;
  866. ctx.fillRect(0, 0, widthSkipDuration, 20);
  867. ctx.fillStyle = durationColor;
  868. ctx.fillRect(widthSkipDuration, 0, widthDuration, 20);
  869. ctx.fillStyle = afterDurationColor;
  870. ctx.fillRect(
  871. widthSkipDuration + widthDuration,
  872. 0,
  873. widthAfterDuration,
  874. 20
  875. );
  876. ctx.fillStyle = currentDurationColor;
  877. ctx.fillRect(widthCurrentTime, 0, 1, 20);
  878. },
  879. ...mapActions("admin/songs", [
  880. "stopVideo",
  881. "loadVideoById",
  882. "pauseVideo",
  883. "getCurrentTime",
  884. "editSong",
  885. "updateSongField",
  886. "selectDiscogsInfo"
  887. ]),
  888. ...mapActions("modals", ["closeModal"])
  889. },
  890. mounted() {
  891. // if (this.modals.editSong = false) this.video.player.stopVideo();
  892. // this.loadVideoById(
  893. // this.editing.song.songId,
  894. // this.editing.song.skipDuration
  895. // );
  896. lofig.get("cookie.secure", res => {
  897. this.useHTTPS = res;
  898. });
  899. io.getSocket(socket => {
  900. this.socket = socket;
  901. });
  902. this.interval = setInterval(() => {
  903. if (
  904. this.video.paused === false &&
  905. this.playerReady &&
  906. this.video.player.getCurrentTime() -
  907. this.editing.song.skipDuration >
  908. this.editing.song.duration
  909. ) {
  910. this.video.paused = false;
  911. this.video.player.stopVideo();
  912. }
  913. if (this.playerReady) {
  914. this.youtubeVideoCurrentTime = this.video.player
  915. .getCurrentTime()
  916. .toFixed(3);
  917. }
  918. if (this.video.paused === false) this.drawCanvas();
  919. }, 200);
  920. this.video.player = new window.YT.Player("player", {
  921. height: 298,
  922. width: 530,
  923. videoId: this.editing.song.songId,
  924. playerVars: {
  925. controls: 0,
  926. iv_load_policy: 3,
  927. rel: 0,
  928. showinfo: 0,
  929. autoplay: 1
  930. },
  931. startSeconds: this.editing.song.skipDuration,
  932. events: {
  933. onReady: () => {
  934. let volume = parseInt(localStorage.getItem("volume"));
  935. volume = typeof volume === "number" ? volume : 20;
  936. console.log(`Seekto: ${this.editing.song.skipDuration}`);
  937. this.video.player.seekTo(this.editing.song.skipDuration);
  938. this.video.player.setVolume(volume);
  939. if (volume > 0) this.video.player.unMute();
  940. this.youtubeVideoDuration = this.video.player.getDuration();
  941. this.youtubeVideoNote = "(~)";
  942. this.playerReady = true;
  943. this.drawCanvas();
  944. },
  945. onStateChange: event => {
  946. if (event.data === 1) {
  947. if (!this.video.autoPlayed) {
  948. this.video.autoPlayed = true;
  949. return this.video.player.stopVideo();
  950. }
  951. this.video.paused = false;
  952. let youtubeDuration = this.video.player.getDuration();
  953. this.youtubeVideoDuration = youtubeDuration;
  954. this.youtubeVideoNote = "";
  955. youtubeDuration -= this.editing.song.skipDuration;
  956. if (this.editing.song.duration > youtubeDuration + 1) {
  957. this.video.player.stopVideo();
  958. this.video.paused = true;
  959. return Toast.methods.addToast(
  960. "Video can't play. Specified duration is bigger than the YouTube song duration.",
  961. 4000
  962. );
  963. }
  964. if (this.editing.song.duration <= 0) {
  965. this.video.player.stopVideo();
  966. this.video.paused = true;
  967. return Toast.methods.addToast(
  968. "Video can't play. Specified duration has to be more than 0 seconds.",
  969. 4000
  970. );
  971. }
  972. if (
  973. this.video.player.getCurrentTime() <
  974. this.editing.song.skipDuration
  975. ) {
  976. return this.video.player.seekTo(
  977. this.editing.song.skipDuration
  978. );
  979. }
  980. } else if (event.data === 2) {
  981. this.video.paused = true;
  982. }
  983. return false;
  984. }
  985. }
  986. });
  987. let volume = parseInt(localStorage.getItem("volume"));
  988. document.getElementById("volumeSlider").value = volume =
  989. typeof volume === "number" ? volume : 20;
  990. },
  991. beforeDestroy() {
  992. this.playerReady = false;
  993. clearInterval(this.interval);
  994. }
  995. };
  996. </script>
  997. <style lang="scss">
  998. @import "styles/global.scss";
  999. .song-modal {
  1000. .modal-card-title {
  1001. text-align: center;
  1002. margin-left: 24px;
  1003. }
  1004. .modal-card {
  1005. width: 1160px;
  1006. height: 100%;
  1007. .modal-card-body {
  1008. padding: 16px;
  1009. }
  1010. }
  1011. }
  1012. </style>
  1013. <style lang="scss" scoped>
  1014. @import "styles/global.scss";
  1015. .modal-card-body > div {
  1016. display: flex;
  1017. height: 100%;
  1018. }
  1019. .left-section {
  1020. display: flex;
  1021. flex-direction: column;
  1022. margin-right: 16px;
  1023. .top-section {
  1024. display: flex;
  1025. .player-section {
  1026. width: 530px;
  1027. display: flex;
  1028. flex-direction: column;
  1029. .player-footer {
  1030. background-color: #f4f4f4;
  1031. border: 1px rgba(163, 224, 255, 0.75) solid;
  1032. border-radius: 0px 0px 5px 5px;
  1033. display: flex;
  1034. justify-content: space-between;
  1035. height: 54px;
  1036. > * {
  1037. width: 33.3%;
  1038. display: flex;
  1039. align-items: center;
  1040. }
  1041. .player-footer-left {
  1042. flex: 1;
  1043. .material-icons {
  1044. font-size: 38px;
  1045. cursor: pointer;
  1046. }
  1047. .player-play-pause {
  1048. color: $musareBlue;
  1049. }
  1050. .player-stop {
  1051. color: $red;
  1052. }
  1053. .player-fast-forward {
  1054. color: $green;
  1055. }
  1056. }
  1057. .player-footer-center {
  1058. justify-content: center;
  1059. align-items: center;
  1060. flex: 2;
  1061. font-size: 21px;
  1062. font-weight: 400;
  1063. img {
  1064. height: 21px;
  1065. margin-right: 12px;
  1066. filter: invert(26%) sepia(54%) saturate(6317%)
  1067. hue-rotate(2deg) brightness(92%) contrast(115%);
  1068. }
  1069. }
  1070. .player-footer-right {
  1071. justify-content: right;
  1072. flex: 1;
  1073. #volumeSlider {
  1074. width: 126px;
  1075. margin-right: 10px;
  1076. background-color: #f4f4f4;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. .thumbnail-preview {
  1082. width: 189px;
  1083. height: 189px;
  1084. margin-left: 16px;
  1085. }
  1086. }
  1087. .edit-section {
  1088. width: 735px;
  1089. background-color: #f4f4f4;
  1090. border: 1px rgba(163, 224, 255, 0.75) solid;
  1091. margin-top: 16px;
  1092. flex: 1;
  1093. overflow: auto;
  1094. border-radius: 5px;
  1095. .album-get-button {
  1096. background-color: $purple;
  1097. color: white;
  1098. width: 32px;
  1099. text-align: center;
  1100. border-width: 0;
  1101. }
  1102. .add-button {
  1103. background-color: $musareBlue !important;
  1104. width: 32px;
  1105. i {
  1106. font-size: 32px;
  1107. }
  1108. }
  1109. > div {
  1110. margin: 16px;
  1111. }
  1112. input {
  1113. width: 100%;
  1114. }
  1115. .title-container {
  1116. width: calc((100% - 32px) / 2);
  1117. }
  1118. .duration-container {
  1119. margin-right: 16px;
  1120. margin-left: 16px;
  1121. width: calc((100% - 32px) / 4);
  1122. }
  1123. .skip-duration-container {
  1124. width: calc((100% - 32px) / 4);
  1125. }
  1126. .album-art-container {
  1127. width: 100%;
  1128. }
  1129. .artists-container {
  1130. width: calc((100% - 32px) / 3);
  1131. position: relative;
  1132. }
  1133. .genres-container {
  1134. width: calc((100% - 32px) / 3);
  1135. margin-left: 16px;
  1136. margin-right: 16px;
  1137. position: relative;
  1138. }
  1139. .youtube-id-container {
  1140. width: calc((100% - 32px) / 3);
  1141. }
  1142. .list-item-circle {
  1143. background-color: $musareBlue;
  1144. width: 16px;
  1145. height: 16px;
  1146. border-radius: 8px;
  1147. cursor: pointer;
  1148. margin-right: 8px;
  1149. float: left;
  1150. -webkit-touch-callout: none;
  1151. -webkit-user-select: none;
  1152. -khtml-user-select: none;
  1153. -moz-user-select: none;
  1154. -ms-user-select: none;
  1155. user-select: none;
  1156. i {
  1157. color: $musareBlue;
  1158. font-size: 14px;
  1159. margin-left: 1px;
  1160. }
  1161. }
  1162. .list-item-circle:hover,
  1163. .list-item-circle:focus {
  1164. i {
  1165. color: white;
  1166. }
  1167. }
  1168. .list-item > p {
  1169. line-height: 16px;
  1170. word-wrap: break-word;
  1171. width: calc(100% - 24px);
  1172. left: 24px;
  1173. float: left;
  1174. margin-bottom: 8px;
  1175. }
  1176. .list-item:last-child > p {
  1177. margin-bottom: 0;
  1178. }
  1179. .autosuggest-container {
  1180. position: absolute;
  1181. background: white;
  1182. width: calc(100% + 1px);
  1183. top: 57px;
  1184. z-index: 200;
  1185. overflow: auto;
  1186. max-height: 100%;
  1187. clear: both;
  1188. .autosuggest-item {
  1189. padding: 8px;
  1190. display: block;
  1191. border: 1px solid #dbdbdb;
  1192. margin-top: -1px;
  1193. line-height: 16px;
  1194. cursor: pointer;
  1195. -webkit-user-select: none;
  1196. -ms-user-select: none;
  1197. -moz-user-select: none;
  1198. user-select: none;
  1199. }
  1200. .autosuggest-item:hover,
  1201. .autosuggest-item:focus {
  1202. background-color: #eee;
  1203. }
  1204. .autosuggest-item:first-child {
  1205. border-top: none;
  1206. }
  1207. .autosuggest-item:last-child {
  1208. border-radius: 0 0 3px 3px;
  1209. }
  1210. }
  1211. }
  1212. }
  1213. .right-section {
  1214. display: flex;
  1215. flex-wrap: wrap;
  1216. .api-section {
  1217. width: 376px;
  1218. background-color: #f4f4f4;
  1219. border: 1px rgba(163, 224, 255, 0.75) solid;
  1220. border-radius: 5px;
  1221. padding: 16px;
  1222. overflow: auto;
  1223. height: 100%;
  1224. > label {
  1225. margin-top: 12px;
  1226. }
  1227. .top-container {
  1228. display: flex;
  1229. img {
  1230. height: 85px;
  1231. width: 85px;
  1232. }
  1233. .right-container {
  1234. padding: 8px;
  1235. display: flex;
  1236. flex-direction: column;
  1237. flex: 1;
  1238. > p {
  1239. flex: 1;
  1240. }
  1241. .bottom-row {
  1242. display: flex;
  1243. flex-flow: row;
  1244. line-height: 15px;
  1245. img {
  1246. height: 15px;
  1247. align-self: end;
  1248. flex: 1;
  1249. user-select: none;
  1250. -moz-user-select: none;
  1251. -ms-user-select: none;
  1252. -webkit-user-select: none;
  1253. cursor: pointer;
  1254. }
  1255. p {
  1256. text-align: right;
  1257. }
  1258. .album-title {
  1259. flex: 1;
  1260. font-weight: 600;
  1261. }
  1262. .type-year {
  1263. font-size: 13px;
  1264. align-self: end;
  1265. }
  1266. }
  1267. }
  1268. }
  1269. .bottom-container {
  1270. padding: 12px;
  1271. .bottom-container-field {
  1272. line-height: 16px;
  1273. margin-bottom: 8px;
  1274. font-weight: 600;
  1275. span {
  1276. font-weight: 400;
  1277. }
  1278. }
  1279. .bottom-container-field:last-of-type {
  1280. margin-bottom: 0;
  1281. }
  1282. }
  1283. .selected-discogs-info {
  1284. background-color: white;
  1285. border: 1px solid $purple;
  1286. border-radius: 5px;
  1287. margin-bottom: 16px;
  1288. .selected-discogs-info-none {
  1289. font-size: 18px;
  1290. text-align: center;
  1291. }
  1292. .bottom-row > p {
  1293. flex: 1;
  1294. }
  1295. }
  1296. .api-result {
  1297. background-color: white;
  1298. border: 0.5px solid $musareBlue;
  1299. border-radius: 5px;
  1300. margin-bottom: 16px;
  1301. }
  1302. button {
  1303. background-color: $musareBlue !important;
  1304. }
  1305. .tracks {
  1306. margin-top: 12px;
  1307. .track:first-child {
  1308. margin-top: 0;
  1309. border-radius: 3px 3px 0 0;
  1310. }
  1311. .track:last-child {
  1312. border-radius: 0 0 3px 3px;
  1313. }
  1314. .track {
  1315. border: 0.5px solid black;
  1316. margin-top: -1px;
  1317. line-height: 16px;
  1318. display: flex;
  1319. cursor: pointer;
  1320. span {
  1321. font-weight: 600;
  1322. display: inline-block;
  1323. margin-top: 7px;
  1324. margin-bottom: 7px;
  1325. margin-left: 7px;
  1326. }
  1327. p {
  1328. display: inline-block;
  1329. margin: 7px;
  1330. flex: 1;
  1331. }
  1332. }
  1333. .track:hover,
  1334. .track:focus {
  1335. background-color: #f4f4f4;
  1336. }
  1337. }
  1338. }
  1339. }
  1340. .footer-buttons {
  1341. margin-left: auto;
  1342. margin-right: auto;
  1343. }
  1344. input[type="range"] {
  1345. -webkit-appearance: none;
  1346. width: 100%;
  1347. margin: 8.5px 0;
  1348. }
  1349. input[type="range"]:focus {
  1350. outline: none;
  1351. }
  1352. input[type="range"]::-webkit-slider-runnable-track {
  1353. width: 100%;
  1354. height: 3px;
  1355. cursor: pointer;
  1356. box-shadow: none;
  1357. background: #7e7e7e;
  1358. border-radius: none;
  1359. border: none;
  1360. }
  1361. input[type="range"]::-webkit-slider-thumb {
  1362. box-shadow: none;
  1363. border: none;
  1364. height: 20px;
  1365. width: 20px;
  1366. border-radius: 100px;
  1367. background: #03a9f4;
  1368. cursor: pointer;
  1369. -webkit-appearance: none;
  1370. margin-top: -8.5px;
  1371. }
  1372. input[type="range"]:focus::-webkit-slider-runnable-track {
  1373. background: #7e7e7e;
  1374. }
  1375. input[type="range"]::-moz-range-track {
  1376. width: 100%;
  1377. height: 3px;
  1378. cursor: pointer;
  1379. box-shadow: none;
  1380. background: #7e7e7e;
  1381. border-radius: none;
  1382. border: none;
  1383. }
  1384. input[type="range"]::-moz-range-thumb {
  1385. box-shadow: none;
  1386. border: none;
  1387. height: 20px;
  1388. width: 20px;
  1389. border-radius: 100px;
  1390. background: #03a9f4;
  1391. cursor: pointer;
  1392. }
  1393. input[type="range"]::-ms-track {
  1394. width: 100%;
  1395. height: 3px;
  1396. cursor: pointer;
  1397. background: transparent;
  1398. border-color: transparent;
  1399. color: transparent;
  1400. }
  1401. input[type="range"]::-ms-fill-lower {
  1402. background: #717171;
  1403. border: none;
  1404. border-radius: none;
  1405. box-shadow: none;
  1406. }
  1407. input[type="range"]::-ms-fill-upper {
  1408. background: #7e7e7e;
  1409. border: none;
  1410. border-radius: none;
  1411. box-shadow: none;
  1412. }
  1413. input[type="range"]::-ms-thumb {
  1414. box-shadow: none;
  1415. border: none;
  1416. height: 20px;
  1417. width: 20px;
  1418. border-radius: 100px;
  1419. background: #03a9f4;
  1420. cursor: pointer;
  1421. height: 3px;
  1422. }
  1423. input[type="range"]:focus::-ms-fill-lower {
  1424. background: #7e7e7e;
  1425. }
  1426. input[type="range"]:focus::-ms-fill-upper {
  1427. background: #7e7e7e;
  1428. }
  1429. </style>