index.vue 53 KB

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