EditSong.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  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. this.discogsQuery = this.editing.song.title;
  786. lofig.get("cookie.secure", res => {
  787. this.useHTTPS = res;
  788. });
  789. io.getSocket(socket => {
  790. this.socket = socket;
  791. });
  792. this.interval = setInterval(() => {
  793. if (
  794. this.video.paused === false &&
  795. this.playerReady &&
  796. this.video.player.getCurrentTime() -
  797. this.editing.song.skipDuration >
  798. this.editing.song.duration
  799. ) {
  800. this.video.paused = false;
  801. this.video.player.stopVideo();
  802. }
  803. if (this.playerReady) {
  804. this.youtubeVideoCurrentTime = this.video.player
  805. .getCurrentTime()
  806. .toFixed(3);
  807. }
  808. if (this.video.paused === false) this.drawCanvas();
  809. }, 200);
  810. this.video.player = new window.YT.Player("player", {
  811. height: 298,
  812. width: 530,
  813. videoId: this.editing.song.songId,
  814. playerVars: {
  815. controls: 0,
  816. iv_load_policy: 3,
  817. rel: 0,
  818. showinfo: 0,
  819. autoplay: 1
  820. },
  821. startSeconds: this.editing.song.skipDuration,
  822. events: {
  823. onReady: () => {
  824. let volume = parseInt(localStorage.getItem("volume"));
  825. volume = typeof volume === "number" ? volume : 20;
  826. console.log(`Seekto: ${this.editing.song.skipDuration}`);
  827. this.video.player.seekTo(this.editing.song.skipDuration);
  828. this.video.player.setVolume(volume);
  829. if (volume > 0) this.video.player.unMute();
  830. this.youtubeVideoDuration = this.video.player.getDuration();
  831. this.youtubeVideoNote = "(~)";
  832. this.playerReady = true;
  833. this.drawCanvas();
  834. },
  835. onStateChange: event => {
  836. if (event.data === 1) {
  837. if (!this.video.autoPlayed) {
  838. this.video.autoPlayed = true;
  839. return this.video.player.stopVideo();
  840. }
  841. this.video.paused = false;
  842. let youtubeDuration = this.video.player.getDuration();
  843. this.youtubeVideoDuration = youtubeDuration;
  844. this.youtubeVideoNote = "";
  845. youtubeDuration -= this.editing.song.skipDuration;
  846. if (this.editing.song.duration > youtubeDuration + 1) {
  847. this.video.player.stopVideo();
  848. this.video.paused = true;
  849. return Toast.methods.addToast(
  850. "Video can't play. Specified duration is bigger than the YouTube song duration.",
  851. 4000
  852. );
  853. }
  854. if (this.editing.song.duration <= 0) {
  855. this.video.player.stopVideo();
  856. this.video.paused = true;
  857. return Toast.methods.addToast(
  858. "Video can't play. Specified duration has to be more than 0 seconds.",
  859. 4000
  860. );
  861. }
  862. if (
  863. this.video.player.getCurrentTime() <
  864. this.editing.song.skipDuration
  865. ) {
  866. return this.video.player.seekTo(
  867. this.editing.song.skipDuration
  868. );
  869. }
  870. } else if (event.data === 2) {
  871. this.video.paused = true;
  872. }
  873. return false;
  874. }
  875. }
  876. });
  877. let volume = parseInt(localStorage.getItem("volume"));
  878. document.getElementById("volumeSlider").value = volume =
  879. typeof volume === "number" ? volume : 20;
  880. },
  881. beforeDestroy() {
  882. this.playerReady = false;
  883. clearInterval(this.interval);
  884. }
  885. };
  886. </script>
  887. <style lang="scss">
  888. @import "styles/global.scss";
  889. .song-modal {
  890. .modal-card-title {
  891. text-align: center;
  892. margin-left: 24px;
  893. }
  894. .modal-card {
  895. width: 1160px;
  896. height: 100%;
  897. .modal-card-body {
  898. padding: 16px;
  899. }
  900. }
  901. }
  902. </style>
  903. <style lang="scss" scoped>
  904. @import "styles/global.scss";
  905. .modal-card-body > div {
  906. display: flex;
  907. height: 100%;
  908. }
  909. .left-section {
  910. display: flex;
  911. flex-direction: column;
  912. margin-right: 16px;
  913. .top-section {
  914. display: flex;
  915. .player-section {
  916. width: 530px;
  917. display: flex;
  918. flex-direction: column;
  919. .player-footer {
  920. background-color: #f4f4f4;
  921. border: 1px rgba(163, 224, 255, 0.75) solid;
  922. border-radius: 0px 0px 5px 5px;
  923. display: flex;
  924. justify-content: space-between;
  925. height: 54px;
  926. > * {
  927. width: 33.3%;
  928. display: flex;
  929. align-items: center;
  930. }
  931. .player-footer-left {
  932. flex: 1;
  933. .material-icons {
  934. font-size: 38px;
  935. cursor: pointer;
  936. }
  937. .player-play-pause {
  938. color: $musareBlue;
  939. }
  940. .player-stop {
  941. color: $red;
  942. }
  943. .player-fast-forward {
  944. color: $green;
  945. }
  946. }
  947. .player-footer-center {
  948. justify-content: center;
  949. align-items: center;
  950. flex: 2;
  951. font-size: 21px;
  952. font-weight: 400;
  953. img {
  954. height: 21px;
  955. margin-right: 12px;
  956. filter: invert(26%) sepia(54%) saturate(6317%)
  957. hue-rotate(2deg) brightness(92%) contrast(115%);
  958. }
  959. }
  960. .player-footer-right {
  961. justify-content: right;
  962. flex: 1;
  963. #volumeSlider {
  964. width: 126px;
  965. margin-right: 10px;
  966. background-color: #f4f4f4;
  967. }
  968. }
  969. }
  970. }
  971. .thumbnail-preview {
  972. width: 189px;
  973. height: 189px;
  974. margin-left: 16px;
  975. }
  976. }
  977. .edit-section {
  978. width: 735px;
  979. background-color: #f4f4f4;
  980. border: 1px rgba(163, 224, 255, 0.75) solid;
  981. margin-top: 16px;
  982. flex: 1;
  983. overflow: auto;
  984. border-radius: 5px;
  985. .album-get-button {
  986. background-color: $purple;
  987. color: white;
  988. width: 32px;
  989. text-align: center;
  990. border-width: 0;
  991. }
  992. .add-button {
  993. background-color: $musareBlue !important;
  994. width: 32px;
  995. i {
  996. font-size: 32px;
  997. }
  998. }
  999. > div {
  1000. margin: 16px;
  1001. }
  1002. input {
  1003. width: 100%;
  1004. }
  1005. .title-container {
  1006. width: calc((100% - 32px) / 2);
  1007. }
  1008. .duration-container {
  1009. margin-right: 16px;
  1010. margin-left: 16px;
  1011. width: calc((100% - 32px) / 4);
  1012. }
  1013. .skip-duration-container {
  1014. width: calc((100% - 32px) / 4);
  1015. }
  1016. .album-art-container {
  1017. width: 100%;
  1018. }
  1019. .artists-container {
  1020. width: calc((100% - 32px) / 3);
  1021. }
  1022. .genres-container {
  1023. width: calc((100% - 32px) / 3);
  1024. margin-left: 16px;
  1025. margin-right: 16px;
  1026. }
  1027. .youtube-id-container {
  1028. width: calc((100% - 32px) / 3);
  1029. }
  1030. .list-item-circle {
  1031. background-color: $musareBlue;
  1032. width: 16px;
  1033. height: 16px;
  1034. border-radius: 8px;
  1035. cursor: pointer;
  1036. margin-right: 8px;
  1037. float: left;
  1038. -webkit-touch-callout: none;
  1039. -webkit-user-select: none;
  1040. -khtml-user-select: none;
  1041. -moz-user-select: none;
  1042. -ms-user-select: none;
  1043. user-select: none;
  1044. i {
  1045. color: $musareBlue;
  1046. font-size: 14px;
  1047. margin-left: 1px;
  1048. }
  1049. }
  1050. .list-item-circle:hover,
  1051. .list-item-circle:focus {
  1052. i {
  1053. color: white;
  1054. }
  1055. }
  1056. .list-item > p {
  1057. line-height: 16px;
  1058. word-wrap: break-word;
  1059. width: calc(100% - 24px);
  1060. left: 24px;
  1061. float: left;
  1062. margin-bottom: 8px;
  1063. }
  1064. .list-item:last-child > p {
  1065. margin-bottom: 0;
  1066. }
  1067. }
  1068. }
  1069. .right-section {
  1070. display: flex;
  1071. flex-wrap: wrap;
  1072. .api-section {
  1073. width: 376px;
  1074. background-color: #f4f4f4;
  1075. border: 1px rgba(163, 224, 255, 0.75) solid;
  1076. border-radius: 5px;
  1077. padding: 16px;
  1078. overflow: auto;
  1079. height: 100%;
  1080. > label {
  1081. margin-top: 12px;
  1082. }
  1083. .top-container {
  1084. display: flex;
  1085. img {
  1086. height: 85px;
  1087. width: 85px;
  1088. }
  1089. .right-container {
  1090. padding: 8px;
  1091. display: flex;
  1092. flex-direction: column;
  1093. flex: 1;
  1094. > p {
  1095. flex: 1;
  1096. }
  1097. .bottom-row {
  1098. display: flex;
  1099. flex-flow: row;
  1100. line-height: 15px;
  1101. img {
  1102. height: 15px;
  1103. align-self: end;
  1104. flex: 1;
  1105. user-select: none;
  1106. -moz-user-select: none;
  1107. -ms-user-select: none;
  1108. -webkit-user-select: none;
  1109. cursor: pointer;
  1110. }
  1111. p {
  1112. text-align: right;
  1113. }
  1114. .album-title {
  1115. flex: 1;
  1116. font-weight: 600;
  1117. }
  1118. .type-year {
  1119. font-size: 13px;
  1120. align-self: end;
  1121. }
  1122. }
  1123. }
  1124. }
  1125. .bottom-container {
  1126. padding: 12px;
  1127. .bottom-container-field {
  1128. line-height: 16px;
  1129. margin-bottom: 8px;
  1130. font-weight: 600;
  1131. span {
  1132. font-weight: 400;
  1133. }
  1134. }
  1135. .bottom-container-field:last-of-type {
  1136. margin-bottom: 0;
  1137. }
  1138. }
  1139. .selected-discogs-info {
  1140. background-color: white;
  1141. border: 1px solid $purple;
  1142. border-radius: 5px;
  1143. margin-bottom: 16px;
  1144. .selected-discogs-info-none {
  1145. font-size: 18px;
  1146. text-align: center;
  1147. }
  1148. .bottom-row > p {
  1149. flex: 1;
  1150. }
  1151. }
  1152. .api-result {
  1153. background-color: white;
  1154. border: 0.5px solid $musareBlue;
  1155. border-radius: 5px;
  1156. margin-bottom: 16px;
  1157. }
  1158. button {
  1159. background-color: $musareBlue !important;
  1160. }
  1161. .tracks {
  1162. margin-top: 12px;
  1163. .track:first-child {
  1164. margin-top: 0;
  1165. border-radius: 3px 3px 0 0;
  1166. }
  1167. .track:last-child {
  1168. border-radius: 0 0 3px 3px;
  1169. }
  1170. .track {
  1171. border: 0.5px solid black;
  1172. margin-top: -1px;
  1173. line-height: 16px;
  1174. display: flex;
  1175. cursor: pointer;
  1176. span {
  1177. font-weight: 600;
  1178. display: inline-block;
  1179. margin-top: 7px;
  1180. margin-bottom: 7px;
  1181. margin-left: 7px;
  1182. }
  1183. p {
  1184. display: inline-block;
  1185. margin: 7px;
  1186. flex: 1;
  1187. }
  1188. }
  1189. .track:hover,
  1190. .track:focus {
  1191. background-color: #f4f4f4;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. .footer-buttons {
  1197. margin-left: auto;
  1198. margin-right: auto;
  1199. }
  1200. input[type="range"] {
  1201. -webkit-appearance: none;
  1202. width: 100%;
  1203. margin: 8.5px 0;
  1204. }
  1205. input[type="range"]:focus {
  1206. outline: none;
  1207. }
  1208. input[type="range"]::-webkit-slider-runnable-track {
  1209. width: 100%;
  1210. height: 3px;
  1211. cursor: pointer;
  1212. box-shadow: none;
  1213. background: #7e7e7e;
  1214. border-radius: none;
  1215. border: none;
  1216. }
  1217. input[type="range"]::-webkit-slider-thumb {
  1218. box-shadow: none;
  1219. border: none;
  1220. height: 20px;
  1221. width: 20px;
  1222. border-radius: 100px;
  1223. background: #03a9f4;
  1224. cursor: pointer;
  1225. -webkit-appearance: none;
  1226. margin-top: -8.5px;
  1227. }
  1228. input[type="range"]:focus::-webkit-slider-runnable-track {
  1229. background: #7e7e7e;
  1230. }
  1231. input[type="range"]::-moz-range-track {
  1232. width: 100%;
  1233. height: 3px;
  1234. cursor: pointer;
  1235. box-shadow: none;
  1236. background: #7e7e7e;
  1237. border-radius: none;
  1238. border: none;
  1239. }
  1240. input[type="range"]::-moz-range-thumb {
  1241. box-shadow: none;
  1242. border: none;
  1243. height: 20px;
  1244. width: 20px;
  1245. border-radius: 100px;
  1246. background: #03a9f4;
  1247. cursor: pointer;
  1248. }
  1249. input[type="range"]::-ms-track {
  1250. width: 100%;
  1251. height: 3px;
  1252. cursor: pointer;
  1253. background: transparent;
  1254. border-color: transparent;
  1255. color: transparent;
  1256. }
  1257. input[type="range"]::-ms-fill-lower {
  1258. background: #717171;
  1259. border: none;
  1260. border-radius: none;
  1261. box-shadow: none;
  1262. }
  1263. input[type="range"]::-ms-fill-upper {
  1264. background: #7e7e7e;
  1265. border: none;
  1266. border-radius: none;
  1267. box-shadow: none;
  1268. }
  1269. input[type="range"]::-ms-thumb {
  1270. box-shadow: none;
  1271. border: none;
  1272. height: 20px;
  1273. width: 20px;
  1274. border-radius: 100px;
  1275. background: #03a9f4;
  1276. cursor: pointer;
  1277. height: 3px;
  1278. }
  1279. input[type="range"]:focus::-ms-fill-lower {
  1280. background: #7e7e7e;
  1281. }
  1282. input[type="range"]:focus::-ms-fill-upper {
  1283. background: #7e7e7e;
  1284. }
  1285. </style>