EditSong.vue 48 KB

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