index.vue 49 KB

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