EditSong.vue 51 KB

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