index.vue 53 KB

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