EditSong.vue 51 KB

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