index.vue 49 KB

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