EditSong.vue 31 KB

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