1
0

index.vue 53 KB

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