EditSong.vue 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179
  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="editSongPlayer"></div>
  9. <canvas
  10. ref="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. @click="play()"
  19. @keyup.enter="play()"
  20. tabindex="0"
  21. v-if="video.paused"
  22. >play_arrow</i
  23. >
  24. <i
  25. class="material-icons player-play-pause"
  26. @click="settings('pause')"
  27. @keyup.enter="settings('pause')"
  28. tabindex="0"
  29. v-if="!video.paused"
  30. >pause</i
  31. >
  32. <i
  33. class="material-icons player-stop"
  34. @click="settings('stop')"
  35. @keyup.enter="settings('stop')"
  36. tabindex="0"
  37. >stop</i
  38. >
  39. <i
  40. class="material-icons player-fast-forward"
  41. @click="settings('skipToLast10Secs')"
  42. @keyup.enter="
  43. settings('skipToLast10Secs')
  44. "
  45. tabindex="0"
  46. >fast_forward</i
  47. >
  48. </div>
  49. <div class="player-footer-center">
  50. <img src="/assets/social/youtube.svg" />
  51. <span>
  52. <span>
  53. {{ youtubeVideoCurrentTime }}
  54. </span>
  55. /
  56. <span>
  57. {{ youtubeVideoDuration }}
  58. {{ youtubeVideoNote }}
  59. </span>
  60. </span>
  61. </div>
  62. <div class="player-footer-right">
  63. <input
  64. type="range"
  65. v-model="volumeSliderValue"
  66. min="0"
  67. max="10000"
  68. class="active"
  69. @change="changeVolume()"
  70. @input="changeVolume()"
  71. />
  72. </div>
  73. </div>
  74. </div>
  75. <img
  76. class="thumbnail-preview"
  77. :src="song.thumbnail"
  78. onerror="this.src='/assets/notes-transparent.png'"
  79. ref="thumbnailElement"
  80. v-if="songDataLoaded"
  81. />
  82. </div>
  83. <div class="edit-section" v-if="songDataLoaded">
  84. <div class="control is-grouped">
  85. <div class="title-container">
  86. <label class="label">Title</label>
  87. <p class="control has-addons">
  88. <input
  89. class="input"
  90. type="text"
  91. ref="title-input"
  92. v-model="song.title"
  93. @keyup.ctrl.alt.d="
  94. getAlbumData('title')
  95. "
  96. />
  97. <button
  98. class="button album-get-button"
  99. @click="getAlbumData('title')"
  100. >
  101. <i class="material-icons">album</i>
  102. </button>
  103. </p>
  104. </div>
  105. <div class="duration-container">
  106. <label class="label">Duration</label>
  107. <p class="control has-addons">
  108. <input
  109. class="input"
  110. type="text"
  111. v-model.number="song.duration"
  112. />
  113. <button
  114. class="button duration-fill-button"
  115. @click="fillDuration()"
  116. >
  117. <i class="material-icons">sync</i>
  118. </button>
  119. </p>
  120. </div>
  121. <div class="skip-duration-container">
  122. <label class="label">Skip duration</label>
  123. <p class="control">
  124. <input
  125. class="input"
  126. type="text"
  127. v-model.number="song.skipDuration"
  128. />
  129. </p>
  130. </div>
  131. </div>
  132. <div class="control is-grouped">
  133. <div class="album-art-container">
  134. <label class="label">Album art</label>
  135. <p class="control has-addons">
  136. <input
  137. class="input"
  138. type="text"
  139. v-model="song.thumbnail"
  140. @keyup.ctrl.alt.d="
  141. getAlbumData('albumArt')
  142. "
  143. />
  144. <button
  145. class="button album-get-button"
  146. @click="getAlbumData('albumArt')"
  147. >
  148. <i class="material-icons">album</i>
  149. </button>
  150. </p>
  151. </div>
  152. </div>
  153. <div class="control is-grouped">
  154. <div class="artists-container">
  155. <label class="label">Artists</label>
  156. <p class="control has-addons">
  157. <input
  158. class="input"
  159. type="text"
  160. ref="new-artist"
  161. v-model="artistInputValue"
  162. @blur="blurArtistInput()"
  163. @focus="focusArtistInput()"
  164. @keydown="keydownArtistInput()"
  165. @keyup.enter="addTag('artists')"
  166. @keyup.ctrl.alt.d="
  167. getAlbumData('artists')
  168. "
  169. />
  170. <button
  171. class="button album-get-button"
  172. @click="getAlbumData('artists')"
  173. >
  174. <i class="material-icons">album</i>
  175. </button>
  176. <button
  177. class="button is-info add-button"
  178. @click="addTag('artists')"
  179. >
  180. <i class="material-icons">add</i>
  181. </button>
  182. </p>
  183. <div
  184. class="autosuggest-container"
  185. v-if="
  186. (artistInputFocussed ||
  187. artistAutosuggestContainerFocussed) &&
  188. artistAutosuggestItems.length > 0
  189. "
  190. @mouseover="focusArtistContainer()"
  191. @mouseleave="blurArtistContainer()"
  192. >
  193. <span
  194. class="autosuggest-item"
  195. tabindex="0"
  196. @click="selectArtistAutosuggest(item)"
  197. v-for="item in artistAutosuggestItems"
  198. :key="item"
  199. >{{ item }}</span
  200. >
  201. </div>
  202. <div class="list-container">
  203. <div
  204. class="list-item"
  205. v-for="artist in song.artists"
  206. :key="artist"
  207. >
  208. <div
  209. class="list-item-circle"
  210. @click="
  211. removeTag('artists', artist)
  212. "
  213. >
  214. <i class="material-icons">close</i>
  215. </div>
  216. <p>{{ artist }}</p>
  217. </div>
  218. </div>
  219. </div>
  220. <div class="genres-container">
  221. <label class="label">
  222. <span>Genres</span>
  223. <i
  224. class="material-icons"
  225. @click="toggleGenreHelper"
  226. @dblclick="resetGenreHelper"
  227. >info</i
  228. >
  229. </label>
  230. <p class="control has-addons">
  231. <input
  232. class="input"
  233. type="text"
  234. ref="new-genre"
  235. v-model="genreInputValue"
  236. @blur="blurGenreInput()"
  237. @focus="focusGenreInput()"
  238. @keydown="keydownGenreInput()"
  239. @keyup.enter="addTag('genres')"
  240. @keyup.ctrl.alt.d="
  241. getAlbumData('genres')
  242. "
  243. />
  244. <button
  245. class="button album-get-button"
  246. @click="getAlbumData('genres')"
  247. >
  248. <i class="material-icons">album</i>
  249. </button>
  250. <button
  251. class="button is-info add-button"
  252. @click="addTag('genres')"
  253. >
  254. <i class="material-icons">add</i>
  255. </button>
  256. </p>
  257. <div
  258. class="autosuggest-container"
  259. v-if="
  260. (genreInputFocussed ||
  261. genreAutosuggestContainerFocussed) &&
  262. genreAutosuggestItems.length > 0
  263. "
  264. @mouseover="focusGenreContainer()"
  265. @mouseleave="blurGenreContainer()"
  266. >
  267. <span
  268. class="autosuggest-item"
  269. @click="selectGenreAutosuggest(item)"
  270. v-for="item in genreAutosuggestItems"
  271. :key="item"
  272. >{{ item }}</span
  273. >
  274. </div>
  275. <div class="list-container">
  276. <div
  277. class="list-item"
  278. v-for="genre in song.genres"
  279. :key="genre"
  280. >
  281. <div
  282. class="list-item-circle"
  283. @click="removeTag('genres', genre)"
  284. >
  285. <i class="material-icons">close</i>
  286. </div>
  287. <p>{{ genre }}</p>
  288. </div>
  289. </div>
  290. </div>
  291. <div class="youtube-id-container">
  292. <label class="label">YouTube ID</label>
  293. <p class="control">
  294. <input
  295. class="input"
  296. type="text"
  297. v-model="song.youtubeId"
  298. />
  299. </p>
  300. </div>
  301. </div>
  302. </div>
  303. </div>
  304. <div class="right-section" v-if="songDataLoaded">
  305. <div class="api-section">
  306. <div class="selected-discogs-info" v-if="!song.discogs">
  307. <p class="selected-discogs-info-none">None</p>
  308. </div>
  309. <div class="selected-discogs-info" v-if="song.discogs">
  310. <div class="top-container">
  311. <img :src="song.discogs.album.albumArt" />
  312. <div class="right-container">
  313. <p class="album-title">
  314. {{ song.discogs.album.title }}
  315. </p>
  316. <div class="bottom-row">
  317. <p class="type-year">
  318. <span>{{
  319. song.discogs.album.type
  320. }}</span>
  321. <span>{{
  322. song.discogs.album.year
  323. }}</span>
  324. </p>
  325. </div>
  326. </div>
  327. </div>
  328. <div class="bottom-container">
  329. <p class="bottom-container-field">
  330. Artists:
  331. <span>{{
  332. song.discogs.album.artists.join(", ")
  333. }}</span>
  334. </p>
  335. <p class="bottom-container-field">
  336. Genres:
  337. <span>{{
  338. song.discogs.album.genres.join(", ")
  339. }}</span>
  340. </p>
  341. <p class="bottom-container-field">
  342. Data quality:
  343. <span>{{ song.discogs.dataQuality }}</span>
  344. </p>
  345. <p class="bottom-container-field">
  346. Track:
  347. <span
  348. >{{ song.discogs.track.position }}.
  349. {{ song.discogs.track.title }}</span
  350. >
  351. </p>
  352. </div>
  353. </div>
  354. <p class="control is-expanded">
  355. <label class="label">Search query</label>
  356. <input
  357. class="input"
  358. type="text"
  359. ref="discogs-input"
  360. v-model="discogsQuery"
  361. @keyup.enter="searchDiscogsForPage(1)"
  362. @change="onDiscogsQueryChange"
  363. v-focus
  364. />
  365. </p>
  366. <button
  367. class="button is-info is-fullwidth"
  368. @click="searchDiscogsForPage(1)"
  369. >
  370. Search
  371. </button>
  372. <label
  373. class="label"
  374. v-if="discogs.apiResults.length > 0"
  375. >API results</label
  376. >
  377. <div
  378. class="api-results-container"
  379. v-if="discogs.apiResults.length > 0"
  380. >
  381. <div
  382. class="api-result"
  383. v-for="(result, index) in discogs.apiResults"
  384. :key="result.album.id"
  385. tabindex="0"
  386. @keydown.space.prevent
  387. @keyup.enter="toggleAPIResult(index)"
  388. >
  389. <div class="top-container">
  390. <img :src="result.album.albumArt" />
  391. <div class="right-container">
  392. <p class="album-title">
  393. {{ result.album.title }}
  394. </p>
  395. <div class="bottom-row">
  396. <img
  397. src="/assets/arrow_up.svg"
  398. v-if="result.expanded"
  399. @click="toggleAPIResult(index)"
  400. />
  401. <img
  402. src="/assets/arrow_down.svg"
  403. v-if="!result.expanded"
  404. @click="toggleAPIResult(index)"
  405. />
  406. <p class="type-year">
  407. <span>{{
  408. result.album.type
  409. }}</span>
  410. <span>{{
  411. result.album.year
  412. }}</span>
  413. </p>
  414. </div>
  415. </div>
  416. </div>
  417. <div
  418. class="bottom-container"
  419. v-if="result.expanded"
  420. >
  421. <p class="bottom-container-field">
  422. Artists:
  423. <span>{{
  424. result.album.artists.join(", ")
  425. }}</span>
  426. </p>
  427. <p class="bottom-container-field">
  428. Genres:
  429. <span>{{
  430. result.album.genres.join(", ")
  431. }}</span>
  432. </p>
  433. <p class="bottom-container-field">
  434. Data quality:
  435. <span>{{ result.dataQuality }}</span>
  436. </p>
  437. <div class="tracks">
  438. <div
  439. class="track"
  440. tabindex="0"
  441. v-for="(track,
  442. trackIndex) in result.tracks"
  443. :key="
  444. `${track.position}-${track.title}`
  445. "
  446. @click="
  447. selectTrack(index, trackIndex)
  448. "
  449. @keyup.enter="
  450. selectTrack(index, trackIndex)
  451. "
  452. >
  453. <span>{{ track.position }}.</span>
  454. <p>{{ track.title }}</p>
  455. </div>
  456. </div>
  457. </div>
  458. </div>
  459. </div>
  460. <button
  461. v-if="
  462. discogs.apiResults.length > 0 &&
  463. !discogs.disableLoadMore &&
  464. discogs.page < discogs.pages
  465. "
  466. class="button is-fullwidth is-info discogs-load-more"
  467. @click="loadNextDiscogsPage()"
  468. >
  469. Load more...
  470. </button>
  471. </div>
  472. </div>
  473. </div>
  474. <div slot="footer">
  475. <save-button ref="saveButton" @clicked="save(song, false)" />
  476. <save-button
  477. ref="saveAndCloseButton"
  478. type="save-and-close"
  479. @clicked="save(song, true)"
  480. />
  481. <div class="right">
  482. <button
  483. v-if="song.status !== 'verified'"
  484. class="button is-success"
  485. @click="verify(song._id)"
  486. content="Verify Song"
  487. v-tippy
  488. >
  489. <i class="material-icons">check_circle</i>
  490. </button>
  491. <confirm
  492. v-if="song.status === 'verified'"
  493. placement="left"
  494. @confirm="unverify(song._id)"
  495. >
  496. <button
  497. class="button is-danger"
  498. content="Unverify Song"
  499. v-tippy
  500. >
  501. <i class="material-icons">cancel</i>
  502. </button>
  503. </confirm>
  504. <confirm
  505. v-if="song.status !== 'hidden'"
  506. placement="left"
  507. @confirm="hide(song._id)"
  508. >
  509. <button
  510. class="button is-danger"
  511. content="Hide Song"
  512. v-tippy
  513. >
  514. <i class="material-icons">visibility_off</i>
  515. </button>
  516. </confirm>
  517. <button
  518. v-if="song.status === 'hidden'"
  519. class="button is-success"
  520. @click="unhide(song._id)"
  521. content="Unhide Song"
  522. v-tippy
  523. >
  524. <i class="material-icons">visibility</i>
  525. </button>
  526. <!-- <confirm placement="left" @confirm="remove(song._id)">
  527. <button
  528. class="button is-danger"
  529. content="Remove Song"
  530. v-tippy
  531. >
  532. <i class="material-icons">delete</i>
  533. </button>
  534. </confirm> -->
  535. </div>
  536. </div>
  537. </modal>
  538. <floating-box id="genreHelper" ref="genreHelper">
  539. <template #body>
  540. <span>Blues</span><span>Country</span><span>Disco</span
  541. ><span>Funk</span><span>Hip-Hop</span><span>Jazz</span
  542. ><span>Metal</span><span>Oldies</span><span>Other</span
  543. ><span>Pop</span><span>Rap</span><span>Reggae</span
  544. ><span>Rock</span><span>Techno</span><span>Trance</span
  545. ><span>Classical</span><span>Instrumental</span
  546. ><span>House</span><span>Electronic</span
  547. ><span>Christian Rap</span><span>Lo-Fi</span><span>Musical</span
  548. ><span>Rock 'n' Roll</span><span>Opera</span
  549. ><span>Drum & Bass</span><span>Club-House</span
  550. ><span>Indie</span><span>Heavy Metal</span
  551. ><span>Christian rock</span><span>Dubstep</span>
  552. </template>
  553. </floating-box>
  554. </div>
  555. </template>
  556. <script>
  557. import { mapState, mapGetters, mapActions } from "vuex";
  558. import Toast from "toasters";
  559. import aw from "@/aw";
  560. import validation from "@/validation";
  561. import keyboardShortcuts from "@/keyboardShortcuts";
  562. import Confirm from "@/components/Confirm.vue";
  563. import Modal from "../Modal.vue";
  564. import FloatingBox from "../FloatingBox.vue";
  565. import SaveButton from "../SaveButton.vue";
  566. export default {
  567. components: { Modal, FloatingBox, SaveButton, Confirm },
  568. props: {
  569. youtubeId: { type: String, default: null },
  570. // songType: { type: String, default: null },
  571. sector: { type: String, default: "admin" }
  572. },
  573. data() {
  574. return {
  575. songDataLoaded: false,
  576. focusedElementBefore: null,
  577. discogsQuery: "",
  578. youtubeVideoDuration: "0.000",
  579. youtubeVideoCurrentTime: 0,
  580. youtubeVideoNote: "",
  581. useHTTPS: false,
  582. discogs: {
  583. apiResults: [],
  584. page: 1,
  585. pages: 1,
  586. disableLoadMore: false
  587. },
  588. volumeSliderValue: 0,
  589. skipToLast10SecsPressed: false,
  590. artistInputValue: "",
  591. genreInputValue: "",
  592. artistInputFocussed: false,
  593. genreInputFocussed: false,
  594. genreAutosuggestContainerFocussed: false,
  595. artistAutosuggestContainerFocussed: false,
  596. keydownArtistInputTimeout: 0,
  597. keydownGenreInputTimeout: 0,
  598. artistAutosuggestItems: [],
  599. genreAutosuggestItems: [],
  600. activityWatchVideoDataInterval: null,
  601. activityWatchVideoLastStatus: "",
  602. activityWatchVideoLastStartDuration: "",
  603. genres: [
  604. "Blues",
  605. "Country",
  606. "Disco",
  607. "Funk",
  608. "Hip-Hop",
  609. "Jazz",
  610. "Metal",
  611. "Oldies",
  612. "Other",
  613. "Pop",
  614. "Rap",
  615. "Reggae",
  616. "Rock",
  617. "Techno",
  618. "Trance",
  619. "Classical",
  620. "Instrumental",
  621. "House",
  622. "Electronic",
  623. "Christian Rap",
  624. "Lo-Fi",
  625. "Musical",
  626. "Rock 'n' Roll",
  627. "Opera",
  628. "Drum & Bass",
  629. "Club-House",
  630. "Indie",
  631. "Heavy Metal",
  632. "Christian rock",
  633. "Dubstep"
  634. ]
  635. };
  636. },
  637. computed: {
  638. ...mapState("modals/editSong", {
  639. video: state => state.video,
  640. song: state => state.song
  641. }),
  642. ...mapState("modalVisibility", {
  643. modals: state => state.modals
  644. }),
  645. ...mapGetters({
  646. socket: "websockets/getSocket"
  647. })
  648. },
  649. watch: {
  650. /* eslint-disable */
  651. "song.duration": function() {
  652. this.drawCanvas();
  653. },
  654. "song.skipDuration": function() {
  655. this.drawCanvas();
  656. }
  657. /* eslint-enable */
  658. },
  659. async mounted() {
  660. // if (this.modals.editSong = false) this.video.player.stopVideo();
  661. // this.loadVideoById(
  662. // this.song.youtubeId,
  663. // this.song.skipDuration
  664. // );
  665. this.activityWatchVideoDataInterval = setInterval(() => {
  666. this.sendActivityWatchVideoData();
  667. }, 1000);
  668. this.useHTTPS = await lofig.get("cookie.secure");
  669. this.socket.dispatch(`songs.getSongFromSongId`, this.song._id, res => {
  670. if (res.status === "success") {
  671. const { song } = res.data;
  672. // this.song = { ...song };
  673. // if (this.song.discogs === undefined)
  674. // this.song.discogs = null;
  675. this.editSong(song);
  676. console.log(song);
  677. this.songDataLoaded = true;
  678. this.socket.dispatch(
  679. "apis.joinRoom",
  680. `edit-song.${this.song._id}`
  681. );
  682. // this.edit(res.data.song);
  683. this.discogsQuery = this.song.title;
  684. this.interval = setInterval(() => {
  685. if (
  686. this.song.duration !== -1 &&
  687. this.video.paused === false &&
  688. this.playerReady &&
  689. this.video.player.getCurrentTime() -
  690. this.song.skipDuration >
  691. this.song.duration
  692. ) {
  693. this.video.paused = true;
  694. this.video.player.stopVideo();
  695. this.drawCanvas();
  696. }
  697. if (this.playerReady) {
  698. this.youtubeVideoCurrentTime = this.video.player
  699. .getCurrentTime()
  700. .toFixed(3);
  701. }
  702. if (this.video.paused === false) this.drawCanvas();
  703. }, 200);
  704. this.video.player = new window.YT.Player("editSongPlayer", {
  705. height: 298,
  706. width: 530,
  707. videoId: this.song.youtubeId,
  708. host: "https://www.youtube-nocookie.com",
  709. playerVars: {
  710. controls: 0,
  711. iv_load_policy: 3,
  712. rel: 0,
  713. showinfo: 0,
  714. autoplay: 1
  715. },
  716. startSeconds: this.song.skipDuration,
  717. events: {
  718. onReady: () => {
  719. let volume = parseInt(
  720. localStorage.getItem("volume")
  721. );
  722. volume = typeof volume === "number" ? volume : 20;
  723. console.log(`Seekto: ${this.song.skipDuration}`);
  724. this.video.player.seekTo(this.song.skipDuration);
  725. this.video.player.setVolume(volume);
  726. if (volume > 0) this.video.player.unMute();
  727. const duration = this.video.player.getDuration();
  728. console.log(1111, duration.toFixed(3));
  729. this.youtubeVideoDuration = duration.toFixed(3);
  730. this.youtubeVideoNote = "(~)";
  731. this.playerReady = true;
  732. this.drawCanvas();
  733. },
  734. onStateChange: event => {
  735. this.drawCanvas();
  736. let skipToLast10SecsPressed = false;
  737. if (this.skipToLast10SecsPressed) {
  738. this.skipToLast10SecsPressed = false;
  739. skipToLast10SecsPressed = true;
  740. }
  741. if (event.data === 1 && !skipToLast10SecsPressed) {
  742. if (!this.video.autoPlayed) {
  743. this.video.autoPlayed = true;
  744. return this.video.player.stopVideo();
  745. }
  746. this.video.paused = false;
  747. let youtubeDuration = this.video.player.getDuration();
  748. const newYoutubeVideoDuration = youtubeDuration.toFixed(
  749. 3
  750. );
  751. const songDurationNumber = Number(
  752. this.song.duration
  753. );
  754. const songDurationNumber2 =
  755. Number(this.song.duration) + 1;
  756. const songDurationNumber3 =
  757. Number(this.song.duration) - 1;
  758. const fixedSongDuration = songDurationNumber.toFixed(
  759. 3
  760. );
  761. const fixedSongDuration2 = songDurationNumber2.toFixed(
  762. 3
  763. );
  764. const fixedSongDuration3 = songDurationNumber3.toFixed(
  765. 3
  766. );
  767. if (
  768. this.youtubeVideoDuration !==
  769. newYoutubeVideoDuration &&
  770. (fixedSongDuration ===
  771. this.youtubeVideoDuration ||
  772. fixedSongDuration2 ===
  773. this.youtubeVideoDuration ||
  774. fixedSongDuration3 ===
  775. this.youtubeVideoDuration)
  776. )
  777. this.song.duration = newYoutubeVideoDuration;
  778. console.log(
  779. 2222,
  780. newYoutubeVideoDuration,
  781. this.video.player.getDuration()
  782. );
  783. this.youtubeVideoDuration = newYoutubeVideoDuration;
  784. this.youtubeVideoNote = "";
  785. if (this.song.duration === -1)
  786. this.song.duration = youtubeDuration;
  787. youtubeDuration -= this.song.skipDuration;
  788. if (this.song.duration > youtubeDuration + 1) {
  789. this.video.player.stopVideo();
  790. this.video.paused = true;
  791. return new Toast(
  792. "Video can't play. Specified duration is bigger than the YouTube song duration."
  793. );
  794. }
  795. if (this.song.duration <= 0) {
  796. this.video.player.stopVideo();
  797. this.video.paused = true;
  798. return new Toast(
  799. "Video can't play. Specified duration has to be more than 0 seconds."
  800. );
  801. }
  802. if (
  803. this.video.player.getCurrentTime() <
  804. this.song.skipDuration
  805. ) {
  806. return this.video.player.seekTo(
  807. this.song.skipDuration
  808. );
  809. }
  810. } else if (event.data === 2) {
  811. this.video.paused = true;
  812. }
  813. return false;
  814. }
  815. }
  816. });
  817. } else {
  818. new Toast("Song with that ID not found");
  819. this.closeModal("editSong");
  820. }
  821. });
  822. let volume = parseFloat(localStorage.getItem("volume"));
  823. volume =
  824. typeof volume === "number" && !Number.isNaN(volume) ? volume : 20;
  825. localStorage.setItem("volume", volume);
  826. this.volumeSliderValue = volume * 100;
  827. this.socket.on("event:admin.hiddenSong.added", res => {
  828. this.song.status = res.data.song.status;
  829. });
  830. this.socket.on("event:admin.unverifiedSong.added", res => {
  831. this.song.status = res.data.song.status;
  832. });
  833. this.socket.on("event:admin.verifiedSong.added", res => {
  834. this.song.status = res.data.song.status;
  835. });
  836. this.socket.on("event:admin.hiddenSong.removed", () => {
  837. new Toast("The song you were editing was removed");
  838. this.closeModal("editSong");
  839. });
  840. this.socket.on("event:admin.unverifiedSong.removed", () => {
  841. new Toast("The song you were editing was removed");
  842. this.closeModal("editSong");
  843. });
  844. this.socket.on("event:admin.verifiedSong.removed", () => {
  845. new Toast("The song you were editing was removed");
  846. this.closeModal("editSong");
  847. });
  848. keyboardShortcuts.registerShortcut("editSong.pauseResumeVideo", {
  849. keyCode: 101,
  850. preventDefault: true,
  851. handler: () => {
  852. if (this.video.paused) this.play();
  853. else this.settings("pause");
  854. }
  855. });
  856. keyboardShortcuts.registerShortcut("editSong.stopVideo", {
  857. keyCode: 101,
  858. ctrl: true,
  859. preventDefault: true,
  860. handler: () => {
  861. this.settings("stop");
  862. }
  863. });
  864. keyboardShortcuts.registerShortcut("editSong.skipToLast10Secs", {
  865. keyCode: 102,
  866. preventDefault: true,
  867. handler: () => {
  868. this.settings("skipToLast10Secs");
  869. }
  870. });
  871. keyboardShortcuts.registerShortcut("editSong.lowerVolumeLarge", {
  872. keyCode: 98,
  873. preventDefault: true,
  874. handler: () => {
  875. this.volumeSliderValue = Math.max(
  876. 0,
  877. this.volumeSliderValue - 1000
  878. );
  879. this.changeVolume();
  880. }
  881. });
  882. keyboardShortcuts.registerShortcut("editSong.lowerVolumeSmall", {
  883. keyCode: 98,
  884. ctrl: true,
  885. preventDefault: true,
  886. handler: () => {
  887. this.volumeSliderValue = Math.max(
  888. 0,
  889. this.volumeSliderValue - 100
  890. );
  891. this.changeVolume();
  892. }
  893. });
  894. keyboardShortcuts.registerShortcut("editSong.increaseVolumeLarge", {
  895. keyCode: 104,
  896. preventDefault: true,
  897. handler: () => {
  898. this.volumeSliderValue = Math.min(
  899. 10000,
  900. this.volumeSliderValue + 1000
  901. );
  902. this.changeVolume();
  903. }
  904. });
  905. keyboardShortcuts.registerShortcut("editSong.increaseVolumeSmall", {
  906. keyCode: 104,
  907. ctrl: true,
  908. preventDefault: true,
  909. handler: () => {
  910. this.volumeSliderValue = Math.min(
  911. 10000,
  912. this.volumeSliderValue + 100
  913. );
  914. this.changeVolume();
  915. }
  916. });
  917. keyboardShortcuts.registerShortcut("editSong.save", {
  918. keyCode: 83,
  919. ctrl: true,
  920. preventDefault: true,
  921. handler: () => {
  922. this.save(this.song, false);
  923. }
  924. });
  925. keyboardShortcuts.registerShortcut("editSong.close", {
  926. keyCode: 88,
  927. ctrl: true,
  928. preventDefault: true,
  929. handler: () => {
  930. this.closeModal("editSong");
  931. setTimeout(() => {
  932. window.focusedElementBefore.focus();
  933. }, 500);
  934. }
  935. });
  936. keyboardShortcuts.registerShortcut("editSong.focusTitle", {
  937. keyCode: 36,
  938. preventDefault: true,
  939. handler: () => {
  940. this.$refs["title-input"].focus();
  941. }
  942. });
  943. keyboardShortcuts.registerShortcut("editSong.focusDiscogs", {
  944. keyCode: 35,
  945. preventDefault: true,
  946. handler: () => {
  947. this.$refs["discogs-input"].focus();
  948. }
  949. });
  950. keyboardShortcuts.registerShortcut("editSong.useAllDiscogs", {
  951. keyCode: 68,
  952. alt: true,
  953. ctrl: true,
  954. preventDefault: true,
  955. handler: () => {
  956. this.getAlbumData("title");
  957. this.getAlbumData("albumArt");
  958. this.getAlbumData("artists");
  959. this.getAlbumData("genres");
  960. }
  961. });
  962. keyboardShortcuts.registerShortcut("editSong.resetDuration", {
  963. keyCode: 82,
  964. alt: true,
  965. ctrl: true,
  966. preventDefault: true,
  967. handler: () => {
  968. this.fillDuration();
  969. }
  970. });
  971. /*
  972. editSong.pauseResume - Num 5 - Pause/resume song
  973. editSong.stopVideo - Ctrl - Num 5 - Stop
  974. editSong.skipToLast10Secs - Num 6 - Skip to last 10 seconds
  975. editSong.volumeDown5 - Num 2 - Volume down by 10
  976. editSong.volumeDown1 - Ctrl - Num 2 - Volume down by 1
  977. editSong.volumeUp5 - Num 8 - Volume up by 10
  978. editSong.volumeUp1 - Ctrl - Num 8 - Volume up by 1
  979. editSong.focusTitle - Home - Focus the title input
  980. editSong.focusDicogs - End - Focus the discogs input
  981. editSong.save - Ctrl - S - Saves song
  982. editSong.close - Ctrl - X - Closes modal
  983. editSong.useAllDiscogs - Ctrl - Alt - D - Sets all fields to the Discogs data
  984. editSong.resetDuration - Ctrl - Alt - R - Resets the duration
  985. Inside Discogs inputs: Ctrl - D - Sets this field to the Discogs data
  986. */
  987. },
  988. beforeDestroy() {
  989. this.playerReady = false;
  990. clearInterval(this.interval);
  991. clearInterval(this.activityWatchVideoDataInterval);
  992. this.socket.dispatch(
  993. "apis.leaveRoom",
  994. `edit-song.${this.song._id}`,
  995. () => {}
  996. );
  997. const shortcutNames = [
  998. "editSong.pauseResume",
  999. "editSong.stopVideo",
  1000. "editSong.skipToLast10Secs",
  1001. "editSong.volumeDown5",
  1002. "editSong.volumeDown1",
  1003. "editSong.volumeUp5",
  1004. "editSong.volumeUp1",
  1005. "editSong.focusTitle",
  1006. "editSong.focusDicogs",
  1007. "editSong.save",
  1008. "editSong.close",
  1009. "editSong.useAllDiscogs",
  1010. "editSong.resetDuration"
  1011. ];
  1012. shortcutNames.forEach(shortcutName => {
  1013. keyboardShortcuts.unregisterShortcut(shortcutName);
  1014. });
  1015. },
  1016. methods: {
  1017. save(songToCopy, close) {
  1018. const song = JSON.parse(JSON.stringify(songToCopy));
  1019. let saveButtonRef = this.$refs.saveButton;
  1020. if (close) saveButtonRef = this.$refs.saveAndCloseButton;
  1021. if (this.youtubeVideoDuration === "0.000") {
  1022. saveButtonRef.handleFailedSave();
  1023. return new Toast("The video appears to not be working.");
  1024. }
  1025. if (!song.title) {
  1026. saveButtonRef.handleFailedSave();
  1027. return new Toast("Please fill in all fields");
  1028. }
  1029. if (!song.thumbnail) {
  1030. saveButtonRef.handleFailedSave();
  1031. return new Toast("Please fill in all fields");
  1032. }
  1033. const thumbnailHeight = this.$refs.thumbnailElement.naturalHeight;
  1034. const thumbnailWidth = this.$refs.thumbnailElement.naturalWidth;
  1035. if (thumbnailHeight < 80 || thumbnailWidth < 80) {
  1036. saveButtonRef.handleFailedSave();
  1037. return new Toast(
  1038. "Thumbnail width and height must be at least 80px."
  1039. );
  1040. }
  1041. if (thumbnailHeight > 4000 || thumbnailWidth > 4000) {
  1042. saveButtonRef.handleFailedSave();
  1043. return new Toast(
  1044. "Thumbnail width and height must be less than 4000px."
  1045. );
  1046. }
  1047. if (thumbnailHeight - thumbnailWidth > 5) {
  1048. saveButtonRef.handleFailedSave();
  1049. return new Toast("Thumbnail cannot be taller than it is wide.");
  1050. }
  1051. // Duration
  1052. if (
  1053. Number(song.skipDuration) + Number(song.duration) >
  1054. this.youtubeVideoDuration
  1055. ) {
  1056. saveButtonRef.handleFailedSave();
  1057. return new Toast(
  1058. "Duration can't be higher than the length of the video"
  1059. );
  1060. }
  1061. // Title
  1062. if (!validation.isLength(song.title, 1, 100)) {
  1063. saveButtonRef.handleFailedSave();
  1064. return new Toast(
  1065. "Title must have between 1 and 100 characters."
  1066. );
  1067. }
  1068. // Artists
  1069. if (song.artists.length < 1 || song.artists.length > 10) {
  1070. saveButtonRef.handleFailedSave();
  1071. return new Toast(
  1072. "Invalid artists. You must have at least 1 artist and a maximum of 10 artists."
  1073. );
  1074. }
  1075. let error;
  1076. song.artists.forEach(artist => {
  1077. if (!validation.isLength(artist, 1, 64)) {
  1078. error = "Artist must have between 1 and 64 characters.";
  1079. return error;
  1080. }
  1081. if (artist === "NONE") {
  1082. error =
  1083. 'Invalid artist format. Artists are not allowed to be named "NONE".';
  1084. return error;
  1085. }
  1086. return false;
  1087. });
  1088. if (error) {
  1089. saveButtonRef.handleFailedSave();
  1090. return new Toast(error);
  1091. }
  1092. // Genres
  1093. error = undefined;
  1094. song.genres.forEach(genre => {
  1095. if (!validation.isLength(genre, 1, 32)) {
  1096. error = "Genre must have between 1 and 32 characters.";
  1097. return error;
  1098. }
  1099. if (!validation.regex.ascii.test(genre)) {
  1100. error =
  1101. "Invalid genre format. Only ascii characters are allowed.";
  1102. return error;
  1103. }
  1104. return false;
  1105. });
  1106. if (song.genres.length < 1 || song.genres.length > 16)
  1107. error = "You must have between 1 and 16 genres.";
  1108. if (error) {
  1109. saveButtonRef.handleFailedSave();
  1110. return new Toast(error);
  1111. }
  1112. // Thumbnail
  1113. if (!validation.isLength(song.thumbnail, 1, 256)) {
  1114. saveButtonRef.handleFailedSave();
  1115. return new Toast(
  1116. "Thumbnail must have between 8 and 256 characters."
  1117. );
  1118. }
  1119. if (this.useHTTPS && song.thumbnail.indexOf("https://") !== 0) {
  1120. saveButtonRef.handleFailedSave();
  1121. return new Toast('Thumbnail must start with "https://".');
  1122. }
  1123. if (
  1124. !this.useHTTPS &&
  1125. song.thumbnail.indexOf("http://") !== 0 &&
  1126. song.thumbnail.indexOf("https://") !== 0
  1127. ) {
  1128. saveButtonRef.handleFailedSave();
  1129. return new Toast('Thumbnail must start with "http://".');
  1130. }
  1131. saveButtonRef.status = "disabled";
  1132. return this.socket.dispatch(`songs.update`, song._id, song, res => {
  1133. new Toast(res.message);
  1134. if (res.status === "success")
  1135. saveButtonRef.handleSuccessfulSave();
  1136. else saveButtonRef.handleFailedSave();
  1137. if (close) this.closeModal("editSong");
  1138. });
  1139. },
  1140. toggleAPIResult(index) {
  1141. const apiResult = this.discogs.apiResults[index];
  1142. if (apiResult.expanded === true) apiResult.expanded = false;
  1143. else if (apiResult.gotMoreInfo === true) apiResult.expanded = true;
  1144. else {
  1145. fetch(apiResult.album.resourceUrl)
  1146. .then(response => {
  1147. return response.json();
  1148. })
  1149. .then(data => {
  1150. apiResult.album.artists = [];
  1151. apiResult.album.artistIds = [];
  1152. const artistRegex = new RegExp(" \\([0-9]+\\)$");
  1153. apiResult.dataQuality = data.data_quality;
  1154. data.artists.forEach(artist => {
  1155. apiResult.album.artists.push(
  1156. artist.name.replace(artistRegex, "")
  1157. );
  1158. apiResult.album.artistIds.push(artist.id);
  1159. });
  1160. apiResult.tracks = data.tracklist.map(track => {
  1161. return {
  1162. position: track.position,
  1163. title: track.title
  1164. };
  1165. });
  1166. apiResult.expanded = true;
  1167. apiResult.gotMoreInfo = true;
  1168. });
  1169. }
  1170. },
  1171. fillDuration() {
  1172. this.song.duration =
  1173. this.youtubeVideoDuration - this.song.skipDuration;
  1174. },
  1175. getAlbumData(type) {
  1176. if (!this.song.discogs) return;
  1177. if (type === "title")
  1178. this.updateSongField({
  1179. field: "title",
  1180. value: this.song.discogs.track.title
  1181. });
  1182. if (type === "albumArt")
  1183. this.updateSongField({
  1184. field: "thumbnail",
  1185. value: this.song.discogs.album.albumArt
  1186. });
  1187. if (type === "genres")
  1188. this.updateSongField({
  1189. field: "genres",
  1190. value: JSON.parse(
  1191. JSON.stringify(this.song.discogs.album.genres)
  1192. )
  1193. });
  1194. if (type === "artists")
  1195. this.updateSongField({
  1196. field: "artists",
  1197. value: JSON.parse(
  1198. JSON.stringify(this.song.discogs.album.artists)
  1199. )
  1200. });
  1201. },
  1202. searchDiscogsForPage(page) {
  1203. const query = this.discogsQuery;
  1204. this.socket.dispatch("apis.searchDiscogs", query, page, res => {
  1205. if (res.status === "success") {
  1206. if (page === 1)
  1207. new Toast(
  1208. `Successfully searched. Got ${res.data.results.length} results.`
  1209. );
  1210. else
  1211. new Toast(
  1212. `Successfully got ${res.data.results.length} more results.`
  1213. );
  1214. if (page === 1) {
  1215. this.discogs.apiResults = [];
  1216. }
  1217. this.discogs.pages = res.data.pages;
  1218. this.discogs.apiResults = this.discogs.apiResults.concat(
  1219. res.data.results.map(result => {
  1220. const type =
  1221. result.type.charAt(0).toUpperCase() +
  1222. result.type.slice(1);
  1223. return {
  1224. expanded: false,
  1225. gotMoreInfo: false,
  1226. album: {
  1227. id: result.id,
  1228. title: result.title,
  1229. type,
  1230. year: result.year,
  1231. genres: result.genre,
  1232. albumArt: result.cover_image,
  1233. resourceUrl: result.resource_url
  1234. }
  1235. };
  1236. })
  1237. );
  1238. this.discogs.page = page;
  1239. this.discogs.disableLoadMore = false;
  1240. } else new Toast(res.message);
  1241. });
  1242. },
  1243. loadNextDiscogsPage() {
  1244. this.discogs.disableLoadMore = true;
  1245. this.searchDiscogsForPage(this.discogs.page + 1);
  1246. },
  1247. onDiscogsQueryChange() {
  1248. this.discogs.page = 1;
  1249. this.discogs.pages = 1;
  1250. this.discogs.apiResults = [];
  1251. this.discogs.disableLoadMore = false;
  1252. },
  1253. selectTrack(apiResultIndex, trackIndex) {
  1254. const apiResult = JSON.parse(
  1255. JSON.stringify(this.discogs.apiResults[apiResultIndex])
  1256. );
  1257. apiResult.track = apiResult.tracks[trackIndex];
  1258. delete apiResult.tracks;
  1259. delete apiResult.expanded;
  1260. delete apiResult.gotMoreInfo;
  1261. this.selectDiscogsInfo(apiResult);
  1262. },
  1263. blurArtistInput() {
  1264. this.artistInputFocussed = false;
  1265. },
  1266. focusArtistInput() {
  1267. this.artistInputFocussed = true;
  1268. },
  1269. blurArtistContainer() {
  1270. this.artistAutosuggestContainerFocussed = false;
  1271. },
  1272. focusArtistContainer() {
  1273. this.artistAutosuggestContainerFocussed = true;
  1274. },
  1275. keydownArtistInput() {
  1276. clearTimeout(this.keydownArtistInputTimeout);
  1277. this.keydownArtistInputTimeout = setTimeout(() => {
  1278. // Do things here to query the artist
  1279. }, 1000);
  1280. },
  1281. selectArtistAutosuggest(value) {
  1282. this.artistInputValue = value;
  1283. },
  1284. blurGenreInput() {
  1285. this.genreInputFocussed = false;
  1286. },
  1287. focusGenreInput() {
  1288. this.genreInputFocussed = true;
  1289. },
  1290. blurGenreContainer() {
  1291. this.genreAutosuggestContainerFocussed = false;
  1292. },
  1293. focusGenreContainer() {
  1294. this.genreAutosuggestContainerFocussed = true;
  1295. },
  1296. keydownGenreInput() {
  1297. clearTimeout(this.keydownGenreInputTimeout);
  1298. this.keydownGenreInputTimeout = setTimeout(() => {
  1299. if (this.genreInputValue.length > 1) {
  1300. this.genreAutosuggestItems = this.genres.filter(genre => {
  1301. return genre
  1302. .toLowerCase()
  1303. .startsWith(this.genreInputValue.toLowerCase());
  1304. });
  1305. } else this.genreAutosuggestItems = [];
  1306. }, 1000);
  1307. },
  1308. selectGenreAutosuggest(value) {
  1309. this.genreInputValue = value;
  1310. },
  1311. settings(type) {
  1312. switch (type) {
  1313. default:
  1314. break;
  1315. case "stop":
  1316. this.stopVideo();
  1317. this.pauseVideo(true);
  1318. break;
  1319. case "pause":
  1320. this.pauseVideo(true);
  1321. break;
  1322. case "play":
  1323. this.pauseVideo(false);
  1324. break;
  1325. case "skipToLast10Secs":
  1326. this.skipToLast10SecsPressed = true;
  1327. if (this.video.paused) this.pauseVideo(false);
  1328. this.video.player.seekTo(
  1329. this.song.duration - 10 + this.song.skipDuration
  1330. );
  1331. break;
  1332. }
  1333. },
  1334. play() {
  1335. if (
  1336. this.video.player.getVideoData().video_id !==
  1337. this.song.youtubeId
  1338. ) {
  1339. this.song.duration = -1;
  1340. this.loadVideoById(this.song.youtubeId, this.song.skipDuration);
  1341. }
  1342. this.settings("play");
  1343. },
  1344. changeVolume() {
  1345. const volume = this.volumeSliderValue;
  1346. localStorage.setItem("volume", volume / 100);
  1347. this.video.player.setVolume(volume / 100);
  1348. if (volume > 0) this.video.player.unMute();
  1349. },
  1350. addTag(type) {
  1351. if (type === "genres") {
  1352. const genre = this.genreInputValue.trim();
  1353. if (
  1354. this.song.genres
  1355. .map(genre => genre.toLowerCase())
  1356. .indexOf(genre.toLowerCase()) !== -1
  1357. )
  1358. return new Toast("Genre already exists");
  1359. if (genre) {
  1360. this.song.genres.push(genre);
  1361. this.genreInputValue = "";
  1362. return false;
  1363. }
  1364. return new Toast("Genre cannot be empty");
  1365. }
  1366. if (type === "artists") {
  1367. const artist = this.artistInputValue;
  1368. if (this.song.artists.indexOf(artist) !== -1)
  1369. return new Toast("Artist already exists");
  1370. if (artist !== "") {
  1371. this.song.artists.push(artist);
  1372. this.artistInputValue = "";
  1373. return false;
  1374. }
  1375. return new Toast("Artist cannot be empty");
  1376. }
  1377. return false;
  1378. },
  1379. removeTag(type, value) {
  1380. if (type === "genres")
  1381. this.song.genres.splice(this.song.genres.indexOf(value), 1);
  1382. else if (type === "artists")
  1383. this.song.artists.splice(this.song.artists.indexOf(value), 1);
  1384. },
  1385. drawCanvas() {
  1386. const canvasElement = this.$refs.durationCanvas;
  1387. const ctx = canvasElement.getContext("2d");
  1388. const videoDuration = Number(this.youtubeVideoDuration);
  1389. const skipDuration = Number(this.song.skipDuration);
  1390. const duration = Number(this.song.duration);
  1391. const afterDuration = videoDuration - (skipDuration + duration);
  1392. const width = 530;
  1393. const currentTime =
  1394. this.video.player && this.video.player.getCurrentTime
  1395. ? this.video.player.getCurrentTime()
  1396. : 0;
  1397. const widthSkipDuration = (skipDuration / videoDuration) * width;
  1398. const widthDuration = (duration / videoDuration) * width;
  1399. const widthAfterDuration = (afterDuration / videoDuration) * width;
  1400. const widthCurrentTime = (currentTime / videoDuration) * width;
  1401. const skipDurationColor = "#F42003";
  1402. const durationColor = "#03A9F4";
  1403. const afterDurationColor = "#41E841";
  1404. const currentDurationColor = "#3b25e8";
  1405. ctx.fillStyle = skipDurationColor;
  1406. ctx.fillRect(0, 0, widthSkipDuration, 20);
  1407. ctx.fillStyle = durationColor;
  1408. ctx.fillRect(widthSkipDuration, 0, widthDuration, 20);
  1409. ctx.fillStyle = afterDurationColor;
  1410. ctx.fillRect(
  1411. widthSkipDuration + widthDuration,
  1412. 0,
  1413. widthAfterDuration,
  1414. 20
  1415. );
  1416. ctx.fillStyle = currentDurationColor;
  1417. ctx.fillRect(widthCurrentTime, 0, 1, 20);
  1418. },
  1419. toggleGenreHelper() {
  1420. this.$refs.genreHelper.toggleBox();
  1421. },
  1422. resetGenreHelper() {
  1423. this.$refs.genreHelper.resetBox();
  1424. },
  1425. sendActivityWatchVideoData() {
  1426. if (!this.video.paused) {
  1427. if (this.activityWatchVideoLastStatus !== "playing") {
  1428. this.activityWatchVideoLastStatus = "playing";
  1429. if (
  1430. this.song.skipDuration > 0 &&
  1431. parseFloat(this.youtubeVideoCurrentTime) === 0
  1432. ) {
  1433. this.activityWatchVideoLastStartDuration = Math.floor(
  1434. this.song.skipDuration +
  1435. parseFloat(this.youtubeVideoCurrentTime)
  1436. );
  1437. } else {
  1438. this.activityWatchVideoLastStartDuration = Math.floor(
  1439. parseFloat(this.youtubeVideoCurrentTime)
  1440. );
  1441. }
  1442. }
  1443. const videoData = {
  1444. title: this.song.title,
  1445. artists: this.song.artists
  1446. ? this.song.artists.join(", ")
  1447. : null,
  1448. youtubeId: this.song.youtubeId,
  1449. muted: this.muted,
  1450. volume: this.volumeSliderValue / 100,
  1451. startedDuration:
  1452. this.activityWatchVideoLastStartDuration <= 0
  1453. ? 0
  1454. : this.activityWatchVideoLastStartDuration,
  1455. source: `editSong#${this.song.youtubeId}`,
  1456. hostname: window.location.hostname
  1457. };
  1458. aw.sendVideoData(videoData);
  1459. } else {
  1460. this.activityWatchVideoLastStatus = "not_playing";
  1461. }
  1462. },
  1463. verify(id) {
  1464. this.socket.dispatch("songs.verify", id, res => {
  1465. new Toast(res.message);
  1466. });
  1467. },
  1468. unverify(id) {
  1469. this.socket.dispatch("songs.unverify", id, res => {
  1470. new Toast(res.message);
  1471. });
  1472. },
  1473. hide(id) {
  1474. this.socket.dispatch("songs.hide", id, res => {
  1475. new Toast(res.message);
  1476. });
  1477. },
  1478. unhide(id) {
  1479. this.socket.dispatch("songs.unhide", id, res => {
  1480. new Toast(res.message);
  1481. });
  1482. },
  1483. // remove(id) {
  1484. // this.socket.dispatch("songs.remove", id, res => {
  1485. // new Toast(res.message);
  1486. // });
  1487. // },
  1488. ...mapActions("modals/editSong", [
  1489. "stopVideo",
  1490. "loadVideoById",
  1491. "pauseVideo",
  1492. "getCurrentTime",
  1493. "editSong",
  1494. "updateSongField",
  1495. "selectDiscogsInfo"
  1496. ]),
  1497. ...mapActions("modalVisibility", ["closeModal"])
  1498. }
  1499. };
  1500. </script>
  1501. <style lang="scss">
  1502. .song-modal {
  1503. .modal-card-title {
  1504. text-align: center;
  1505. margin-left: 24px;
  1506. }
  1507. .modal-card {
  1508. width: 1160px;
  1509. height: 100%;
  1510. .modal-card-body {
  1511. padding: 16px;
  1512. }
  1513. .modal-card-foot {
  1514. div div {
  1515. margin-right: 5px;
  1516. }
  1517. .right {
  1518. display: flex;
  1519. margin-left: auto;
  1520. margin-right: 0;
  1521. }
  1522. }
  1523. }
  1524. }
  1525. </style>
  1526. <style lang="scss" scoped>
  1527. .night-mode {
  1528. .edit-section,
  1529. .api-section,
  1530. .api-result,
  1531. .player-footer {
  1532. background-color: var(--dark-grey-3) !important;
  1533. }
  1534. .api-result .tracks .track:hover,
  1535. .selected-discogs-info {
  1536. background-color: var(--dark-grey-2) !important;
  1537. }
  1538. .label,
  1539. p,
  1540. strong {
  1541. color: var(--light-grey-2);
  1542. }
  1543. }
  1544. .modal-card-body > div {
  1545. display: flex;
  1546. height: 100%;
  1547. }
  1548. .left-section {
  1549. display: flex;
  1550. flex-direction: column;
  1551. margin-right: 16px;
  1552. .top-section {
  1553. display: flex;
  1554. .player-section {
  1555. width: 530px;
  1556. display: flex;
  1557. flex-direction: column;
  1558. .player-footer {
  1559. background-color: var(--light-grey);
  1560. border: 1px rgba(163, 224, 255, 0.75) solid;
  1561. border-radius: 0px 0px 5px 5px;
  1562. display: flex;
  1563. justify-content: space-between;
  1564. height: 54px;
  1565. > * {
  1566. width: 33.3%;
  1567. display: flex;
  1568. align-items: center;
  1569. }
  1570. .player-footer-left {
  1571. flex: 1;
  1572. .material-icons {
  1573. font-size: 38px;
  1574. cursor: pointer;
  1575. }
  1576. .player-play-pause {
  1577. color: var(--primary-color);
  1578. }
  1579. .player-stop {
  1580. color: var(--red);
  1581. }
  1582. .player-fast-forward {
  1583. color: var(--green);
  1584. }
  1585. }
  1586. .player-footer-center {
  1587. justify-content: center;
  1588. align-items: center;
  1589. flex: 2;
  1590. font-size: 21px;
  1591. font-weight: 400;
  1592. img {
  1593. height: 21px;
  1594. margin-right: 12px;
  1595. filter: invert(26%) sepia(54%) saturate(6317%)
  1596. hue-rotate(2deg) brightness(92%) contrast(115%);
  1597. }
  1598. }
  1599. .player-footer-right {
  1600. justify-content: right;
  1601. flex: 1;
  1602. #volumeSlider {
  1603. width: 126px;
  1604. margin-right: 10px;
  1605. background-color: var(--light-grey);
  1606. }
  1607. }
  1608. }
  1609. }
  1610. .thumbnail-preview {
  1611. width: 189px;
  1612. height: 189px;
  1613. margin-left: 16px;
  1614. }
  1615. }
  1616. .edit-section {
  1617. width: 735px;
  1618. background-color: var(--light-grey);
  1619. border: 1px rgba(163, 224, 255, 0.75) solid;
  1620. margin-top: 16px;
  1621. flex: 1;
  1622. overflow: auto;
  1623. border-radius: 5px;
  1624. .album-get-button {
  1625. background-color: var(--purple);
  1626. color: var(--white);
  1627. width: 32px;
  1628. text-align: center;
  1629. border-width: 0;
  1630. }
  1631. .duration-fill-button {
  1632. background-color: var(--red);
  1633. color: var(--white);
  1634. width: 32px;
  1635. text-align: center;
  1636. border-width: 0;
  1637. }
  1638. .add-button {
  1639. background-color: var(--primary-color) !important;
  1640. width: 32px;
  1641. i {
  1642. font-size: 32px;
  1643. }
  1644. }
  1645. .album-get-button,
  1646. .duration-fill-button,
  1647. .add-button {
  1648. &:focus,
  1649. &:hover {
  1650. filter: contrast(0.75);
  1651. border: 1px solid var(--black) !important;
  1652. }
  1653. }
  1654. > div {
  1655. margin: 16px;
  1656. }
  1657. input {
  1658. width: 100%;
  1659. }
  1660. .title-container {
  1661. width: calc((100% - 32px) / 2);
  1662. }
  1663. .duration-container {
  1664. margin-right: 16px;
  1665. margin-left: 16px;
  1666. width: calc((100% - 32px) / 4);
  1667. }
  1668. .skip-duration-container {
  1669. width: calc((100% - 32px) / 4);
  1670. }
  1671. .album-art-container {
  1672. width: 100%;
  1673. }
  1674. .artists-container {
  1675. width: calc((100% - 32px) / 3);
  1676. position: relative;
  1677. }
  1678. .genres-container {
  1679. width: calc((100% - 32px) / 3);
  1680. margin-left: 16px;
  1681. margin-right: 16px;
  1682. position: relative;
  1683. label {
  1684. display: flex;
  1685. i {
  1686. font-size: 15px;
  1687. align-self: center;
  1688. margin-left: 5px;
  1689. color: var(--primary-color);
  1690. cursor: pointer;
  1691. -webkit-user-select: none;
  1692. -moz-user-select: none;
  1693. -ms-user-select: none;
  1694. user-select: none;
  1695. }
  1696. }
  1697. }
  1698. .youtube-id-container {
  1699. width: calc((100% - 32px) / 3);
  1700. }
  1701. .list-item-circle {
  1702. background-color: var(--primary-color);
  1703. width: 16px;
  1704. height: 16px;
  1705. border-radius: 8px;
  1706. cursor: pointer;
  1707. margin-right: 8px;
  1708. float: left;
  1709. -webkit-touch-callout: none;
  1710. -webkit-user-select: none;
  1711. -khtml-user-select: none;
  1712. -moz-user-select: none;
  1713. -ms-user-select: none;
  1714. user-select: none;
  1715. i {
  1716. color: var(--primary-color);
  1717. font-size: 14px;
  1718. margin-left: 1px;
  1719. }
  1720. }
  1721. .list-item-circle:hover,
  1722. .list-item-circle:focus {
  1723. i {
  1724. color: var(--white);
  1725. }
  1726. }
  1727. .list-item > p {
  1728. line-height: 16px;
  1729. word-wrap: break-word;
  1730. width: calc(100% - 24px);
  1731. left: 24px;
  1732. float: left;
  1733. margin-bottom: 8px;
  1734. }
  1735. .list-item:last-child > p {
  1736. margin-bottom: 0;
  1737. }
  1738. .autosuggest-container {
  1739. position: absolute;
  1740. background: var(--white);
  1741. width: calc(100% + 1px);
  1742. top: 57px;
  1743. z-index: 200;
  1744. overflow: auto;
  1745. max-height: 100%;
  1746. clear: both;
  1747. .autosuggest-item {
  1748. padding: 8px;
  1749. display: block;
  1750. border: 1px solid var(--light-grey-2);
  1751. margin-top: -1px;
  1752. line-height: 16px;
  1753. cursor: pointer;
  1754. -webkit-user-select: none;
  1755. -ms-user-select: none;
  1756. -moz-user-select: none;
  1757. user-select: none;
  1758. }
  1759. .autosuggest-item:hover,
  1760. .autosuggest-item:focus {
  1761. background-color: var(--light-grey);
  1762. }
  1763. .autosuggest-item:first-child {
  1764. border-top: none;
  1765. }
  1766. .autosuggest-item:last-child {
  1767. border-radius: 0 0 3px 3px;
  1768. }
  1769. }
  1770. }
  1771. }
  1772. .right-section {
  1773. display: flex;
  1774. flex-wrap: wrap;
  1775. .api-section {
  1776. width: 376px;
  1777. background-color: var(--light-grey);
  1778. border: 1px rgba(163, 224, 255, 0.75) solid;
  1779. border-radius: 5px;
  1780. padding: 16px;
  1781. overflow: auto;
  1782. height: 100%;
  1783. > label {
  1784. margin-top: 12px;
  1785. }
  1786. .top-container {
  1787. display: flex;
  1788. img {
  1789. height: 85px;
  1790. width: 85px;
  1791. }
  1792. .right-container {
  1793. padding: 8px;
  1794. display: flex;
  1795. flex-direction: column;
  1796. flex: 1;
  1797. .album-title {
  1798. flex: 1;
  1799. font-weight: 600;
  1800. }
  1801. .bottom-row {
  1802. display: flex;
  1803. flex-flow: row;
  1804. line-height: 15px;
  1805. img {
  1806. height: 15px;
  1807. align-self: end;
  1808. flex: 1;
  1809. user-select: none;
  1810. -moz-user-select: none;
  1811. -ms-user-select: none;
  1812. -webkit-user-select: none;
  1813. cursor: pointer;
  1814. }
  1815. p {
  1816. text-align: right;
  1817. }
  1818. .type-year {
  1819. font-size: 13px;
  1820. align-self: end;
  1821. }
  1822. }
  1823. }
  1824. }
  1825. .bottom-container {
  1826. padding: 12px;
  1827. .bottom-container-field {
  1828. line-height: 16px;
  1829. margin-bottom: 8px;
  1830. font-weight: 600;
  1831. span {
  1832. font-weight: 400;
  1833. }
  1834. }
  1835. .bottom-container-field:last-of-type {
  1836. margin-bottom: 0;
  1837. }
  1838. }
  1839. .selected-discogs-info {
  1840. background-color: var(--white);
  1841. border: 1px solid var(--purple);
  1842. border-radius: 5px;
  1843. margin-bottom: 16px;
  1844. .selected-discogs-info-none {
  1845. font-size: 18px;
  1846. text-align: center;
  1847. }
  1848. .bottom-row > p {
  1849. flex: 1;
  1850. }
  1851. }
  1852. .api-result {
  1853. background-color: var(--white);
  1854. border: 0.5px solid var(--primary-color);
  1855. border-radius: 5px;
  1856. margin-bottom: 16px;
  1857. }
  1858. button {
  1859. background-color: var(--primary-color) !important;
  1860. &:focus,
  1861. &:hover {
  1862. filter: contrast(0.75);
  1863. }
  1864. }
  1865. .tracks {
  1866. margin-top: 12px;
  1867. .track:first-child {
  1868. margin-top: 0;
  1869. border-radius: 3px 3px 0 0;
  1870. }
  1871. .track:last-child {
  1872. border-radius: 0 0 3px 3px;
  1873. }
  1874. .track {
  1875. border: 0.5px solid var(--black);
  1876. margin-top: -1px;
  1877. line-height: 16px;
  1878. display: flex;
  1879. cursor: pointer;
  1880. span {
  1881. font-weight: 600;
  1882. display: inline-block;
  1883. margin-top: 7px;
  1884. margin-bottom: 7px;
  1885. margin-left: 7px;
  1886. }
  1887. p {
  1888. display: inline-block;
  1889. margin: 7px;
  1890. flex: 1;
  1891. }
  1892. }
  1893. .track:hover,
  1894. .track:focus {
  1895. background-color: var(--light-grey);
  1896. }
  1897. }
  1898. .discogs-load-more {
  1899. margin-bottom: 8px;
  1900. }
  1901. }
  1902. }
  1903. .modal-card-foot .is-primary {
  1904. width: 200px;
  1905. }
  1906. input[type="range"] {
  1907. -webkit-appearance: none;
  1908. width: 100%;
  1909. margin: 8.5px 0;
  1910. }
  1911. input[type="range"]:focus {
  1912. outline-style: outset;
  1913. }
  1914. input[type="range"]::-webkit-slider-runnable-track {
  1915. width: 100%;
  1916. height: 3px;
  1917. cursor: pointer;
  1918. box-shadow: none;
  1919. background: var(--grey-3);
  1920. border-radius: none;
  1921. border: none;
  1922. }
  1923. input[type="range"]::-webkit-slider-thumb {
  1924. box-shadow: none;
  1925. border: none;
  1926. height: 20px;
  1927. width: 20px;
  1928. border-radius: 100px;
  1929. background: var(--primary-color);
  1930. cursor: pointer;
  1931. -webkit-appearance: none;
  1932. margin-top: -8.5px;
  1933. }
  1934. input[type="range"]:focus::-webkit-slider-runnable-track {
  1935. background: var(--grey-3);
  1936. }
  1937. input[type="range"]::-moz-range-track {
  1938. width: 100%;
  1939. height: 3px;
  1940. cursor: pointer;
  1941. box-shadow: none;
  1942. background: var(--grey-3);
  1943. border-radius: none;
  1944. border: none;
  1945. }
  1946. input[type="range"]::-moz-range-thumb {
  1947. box-shadow: none;
  1948. border: none;
  1949. height: 20px;
  1950. width: 20px;
  1951. border-radius: 100px;
  1952. background: var(--primary-color);
  1953. cursor: pointer;
  1954. }
  1955. input[type="range"]::-ms-track {
  1956. width: 100%;
  1957. height: 3px;
  1958. cursor: pointer;
  1959. background: transparent;
  1960. border-color: transparent;
  1961. color: transparent;
  1962. }
  1963. input[type="range"]::-ms-fill-lower {
  1964. background: var(--grey-2);
  1965. border: none;
  1966. border-radius: none;
  1967. box-shadow: none;
  1968. }
  1969. input[type="range"]::-ms-fill-upper {
  1970. background: var(--grey-3);
  1971. border: none;
  1972. border-radius: none;
  1973. box-shadow: none;
  1974. }
  1975. input[type="range"]::-ms-thumb {
  1976. box-shadow: none;
  1977. border: none;
  1978. height: 20px;
  1979. width: 20px;
  1980. border-radius: 100px;
  1981. background: var(--primary-color);
  1982. cursor: pointer;
  1983. height: 3px;
  1984. }
  1985. input[type="range"]:focus::-ms-fill-lower {
  1986. background: var(--grey-3);
  1987. }
  1988. input[type="range"]:focus::-ms-fill-upper {
  1989. background: var(--grey-3);
  1990. }
  1991. </style>