index.vue 51 KB

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