index.vue 53 KB

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