EditSong.vue 51 KB

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