index.vue 51 KB

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