1
1
import { Component , ElementRef , ViewChild , OnInit , HostListener } from '@angular/core' ;
2
2
import { YoutubeGetVideo } from './services/youtube.service' ;
3
3
import { SharedService } from './services/shared.service' ;
4
+ import { GlobalsService } from './services/globals.service' ;
4
5
import { Event } from '@angular/router/src/events' ;
5
6
import { DragulaService } from 'ng2-dragula/ng2-dragula' ;
6
7
@@ -30,11 +31,9 @@ export class AppComponent implements OnInit {
30
31
nw : any ;
31
32
videoRangePercent = 0 ;
32
33
33
- relatedVideos : Array < IRelatedVideo > = [ ] ;
34
34
tempPlaylist : Array < any > = [ ] ;
35
35
currentVideoObject : Array < any > = [ ] ;
36
36
37
- thumbnails = true ;
38
37
darkMode = true ;
39
38
menuActive = false ;
40
39
@@ -86,6 +85,7 @@ export class AppComponent implements OnInit {
86
85
constructor (
87
86
private youtube : YoutubeGetVideo ,
88
87
private shared : SharedService ,
88
+ private globals : GlobalsService ,
89
89
private dragula : DragulaService ,
90
90
91
91
private authService : AuthService ,
@@ -101,7 +101,7 @@ export class AppComponent implements OnInit {
101
101
ngOnInit ( ) {
102
102
this . preventOldSettings ( ) ;
103
103
this . updateUserDetails ( ) ;
104
- this . initDragula ( ) ;
104
+ this . initDragula ( ) ;
105
105
}
106
106
107
107
private hasClass ( el : any , name : string ) {
@@ -134,7 +134,7 @@ export class AppComponent implements OnInit {
134
134
// To fix update in realtime
135
135
this . authService . checkLogged ( ) ;
136
136
this . db2 . list ( 'sessions/' + localStorage . getItem ( 'session_key' ) ) . valueChanges ( ) . subscribe ( ( data ) => {
137
- this . shared . updateData ( 'check status' ) ;
137
+ this . shared . updateData ( 'check status' ) ;
138
138
if ( data . length > 0 ) {
139
139
// this.clearSession();
140
140
// localStorage.setItem('settings', JSON.parse(data['3']));
@@ -174,7 +174,7 @@ export class AppComponent implements OnInit {
174
174
async getFeedVideos ( ) {
175
175
await this . _shared . initFeed ( ) ;
176
176
await this . _shared . initChannel ( ) ;
177
- if ( ! this . currentVideo . id && ! this . _shared . isLogged ) {
177
+ if ( ! this . currentVideo . id && ! this . globals . isLogged ) {
178
178
this . setDefaultPlayer ( ) ;
179
179
}
180
180
}
@@ -189,12 +189,12 @@ export class AppComponent implements OnInit {
189
189
}
190
190
191
191
setDefaultPlayer ( ) {
192
- this . setCurrentVideoObject ( this . _shared . feedVideos [ 0 ] ) ;
193
- this . currentVideo . id = this . _shared . feedVideos [ 0 ] . id ;
194
- this . currentVideo . title = this . _shared . feedVideos [ 0 ] . snippet . title ;
195
- this . currentVideo . stats . likes = this . _shared . feedVideos [ 0 ] . statistics . likeCount ;
196
- this . currentVideo . stats . dislikes = this . _shared . feedVideos [ 0 ] . statistics . dislikeCount ;
197
- this . currentVideo . stats . views = this . _shared . feedVideos [ 0 ] . statistics . viewCount ;
192
+ this . setCurrentVideoObject ( this . globals . feedVideos [ 0 ] ) ;
193
+ this . currentVideo . id = this . globals . feedVideos [ 0 ] . id ;
194
+ this . currentVideo . title = this . globals . feedVideos [ 0 ] . snippet . title ;
195
+ this . currentVideo . stats . likes = this . globals . feedVideos [ 0 ] . statistics . likeCount ;
196
+ this . currentVideo . stats . dislikes = this . globals . feedVideos [ 0 ] . statistics . dislikeCount ;
197
+ this . currentVideo . stats . views = this . globals . feedVideos [ 0 ] . statistics . viewCount ;
198
198
this . shareLink = 'https://youtu.be/' + this . currentVideo . id ;
199
199
this . getRelatedVideos ( ) ;
200
200
this . findPlaylistItem ( ) ;
@@ -216,14 +216,14 @@ export class AppComponent implements OnInit {
216
216
if ( this . currentState === 0 ) {
217
217
this . stopRange ( ) ;
218
218
if ( this . repeatMode ) {
219
- if ( this . _shared . playlist . length ) {
219
+ if ( this . globals . playlist . length ) {
220
220
this . findPlaylistItem ( ) ;
221
221
if ( this . currentPlaylistItem < 0 ) {
222
222
this . playPlaylistItem ( 'next' , this . currentPlaylistItem ) ;
223
223
} else {
224
224
this . playPlaylistItem ( 'next' , this . currentPlaylistItem ) ;
225
225
}
226
- if ( this . _shared . playlist . length === 1 ) {
226
+ if ( this . globals . playlist . length === 1 ) {
227
227
this . player . playVideo ( ) ;
228
228
}
229
229
} else {
@@ -271,7 +271,7 @@ export class AppComponent implements OnInit {
271
271
272
272
playlistInit ( ) {
273
273
if ( localStorage . getItem ( 'playlist' ) === null || localStorage . getItem ( 'playlist' ) . length === 2 ) {
274
- this . _shared . playlist = JSON . parse ( JSON . stringify ( this . relatedVideos ) ) ;
274
+ this . globals . playlist = JSON . parse ( JSON . stringify ( this . globals . relatedVideos ) ) ;
275
275
this . _shared . updatePlaylist ( ) ;
276
276
} else {
277
277
this . _shared . getPlaylist ( ) ;
@@ -282,31 +282,31 @@ export class AppComponent implements OnInit {
282
282
findPlaylistItem ( ) {
283
283
let playlistItem ;
284
284
if ( typeof this . currentVideoObject [ 0 ] . id . videoId !== 'undefined' ) {
285
- playlistItem = this . _shared . playlist . find ( item => item . id . videoId === this . currentVideoObject [ 0 ] . id . videoId ) ;
285
+ playlistItem = this . globals . playlist . find ( item => item . id . videoId === this . currentVideoObject [ 0 ] . id . videoId ) ;
286
286
} else {
287
- playlistItem = this . _shared . playlist . find ( item => item . id === this . currentVideoObject [ 0 ] . id ) ;
287
+ playlistItem = this . globals . playlist . find ( item => item . id === this . currentVideoObject [ 0 ] . id ) ;
288
288
}
289
- this . currentPlaylistItem = this . _shared . playlist . indexOf ( playlistItem ) ;
289
+ this . currentPlaylistItem = this . globals . playlist . indexOf ( playlistItem ) ;
290
290
}
291
291
292
292
playPlaylistItem ( direction : string , i : number ) {
293
293
if ( direction === 'next' ) {
294
- if ( i < this . _shared . playlist . length ) {
294
+ if ( i < this . globals . playlist . length ) {
295
295
i += 1 ;
296
296
}
297
- if ( i === this . _shared . playlist . length ) {
297
+ if ( i === this . globals . playlist . length ) {
298
298
i = 0 ;
299
299
}
300
300
}
301
301
if ( direction === 'prev' ) {
302
302
if ( i === 0 || i < 0 ) {
303
- i = this . _shared . playlist . length - 1 ;
303
+ i = this . globals . playlist . length - 1 ;
304
304
} else {
305
305
i -= 1 ;
306
306
}
307
307
}
308
- if ( this . _shared . playlist . length > 0 ) {
309
- this . getVideo ( this . _shared . playlist [ i ] ) ;
308
+ if ( this . globals . playlist . length > 0 ) {
309
+ this . getVideo ( this . globals . playlist [ i ] ) ;
310
310
} else {
311
311
this . _shared . triggerNotify ( 'Playlist is empty' ) ;
312
312
this . updateNotify ( ) ;
@@ -320,7 +320,7 @@ export class AppComponent implements OnInit {
320
320
if ( i === this . currentPlaylistItem ) {
321
321
this . currentPlaylistItem = - 1 ;
322
322
}
323
- this . _shared . playlist . splice ( i , 1 ) ;
323
+ this . globals . playlist . splice ( i , 1 ) ;
324
324
this . updatePlaylist ( ) ;
325
325
} , 200 ) ;
326
326
}
@@ -329,29 +329,29 @@ export class AppComponent implements OnInit {
329
329
let listType ;
330
330
let playlistItem ;
331
331
if ( list === 0 ) {
332
- listType = this . _shared . feedVideos [ i ] ;
332
+ listType = this . globals . feedVideos [ i ] ;
333
333
}
334
334
if ( list === 1 ) {
335
- listType = this . _shared . lastSearchedVideos [ i ] ;
335
+ listType = this . globals . lastSearchedVideos [ i ] ;
336
336
}
337
337
if ( list === 2 ) {
338
- listType = this . relatedVideos [ i ] ;
338
+ listType = this . globals . relatedVideos [ i ] ;
339
339
}
340
340
if ( list === 3 ) {
341
341
listType = this . currentVideoObject [ i ] ;
342
342
}
343
343
if ( list === 4 ) {
344
- listType = this . _shared . historyVideos [ i ] ;
344
+ listType = this . globals . historyVideos [ i ] ;
345
345
}
346
346
347
347
if ( typeof listType . id . videoId !== 'undefined' ) {
348
- playlistItem = this . _shared . playlist . find ( item => item . id . videoId === listType . id . videoId ) ;
348
+ playlistItem = this . globals . playlist . find ( item => item . id . videoId === listType . id . videoId ) ;
349
349
} else {
350
- playlistItem = this . _shared . playlist . find ( item => item . id === listType . id ) ;
350
+ playlistItem = this . globals . playlist . find ( item => item . id === listType . id ) ;
351
351
}
352
352
353
353
if ( typeof playlistItem === 'undefined' ) {
354
- this . _shared . playlist . push ( listType ) ;
354
+ this . globals . playlist . push ( listType ) ;
355
355
this . updatePlaylist ( ) ;
356
356
357
357
this . _shared . triggerNotify ( 'Added to playlist' ) ;
@@ -365,7 +365,7 @@ export class AppComponent implements OnInit {
365
365
366
366
clearPlaylist ( ) {
367
367
this . currentPlaylistItem = - 1 ;
368
- this . _shared . playlist = [ ] ;
368
+ this . globals . playlist = [ ] ;
369
369
this . _shared . updatePlaylist ( ) ;
370
370
}
371
371
@@ -382,8 +382,8 @@ export class AppComponent implements OnInit {
382
382
} ;
383
383
this . currentVideo = removedCurrentVid ;
384
384
this . currentPlaylistItem = - 1 ;
385
- this . _shared . playlist = [ ] ;
386
- this . relatedVideos = [ ] ;
385
+ this . globals . playlist = [ ] ;
386
+ this . globals . relatedVideos = [ ] ;
387
387
localStorage . removeItem ( 'playlist' ) ;
388
388
// localStorage.removeItem('settings');
389
389
}
@@ -394,14 +394,14 @@ export class AppComponent implements OnInit {
394
394
395
395
exportFilePlaylist ( ) {
396
396
const a = document . createElement ( 'a' ) ;
397
- const file = new Blob ( [ JSON . stringify ( this . _shared . playlist ) ] , { type : 'data:text/json;charset=utf8' } ) ;
397
+ const file = new Blob ( [ JSON . stringify ( this . globals . playlist ) ] , { type : 'data:text/json;charset=utf8' } ) ;
398
398
a . href = URL . createObjectURL ( file ) ;
399
399
a . download = 'playlist.json' ;
400
400
a . click ( ) ;
401
401
}
402
402
403
403
importPlaylist ( input : any ) {
404
- this . _shared . playlist = this . tempPlaylist ;
404
+ this . globals . playlist = this . tempPlaylist ;
405
405
this . tempPlaylist = [ ] ;
406
406
this . _shared . updatePlaylist ( ) ;
407
407
this . closeModal ( ) ;
@@ -410,7 +410,7 @@ export class AppComponent implements OnInit {
410
410
// ---------------- Init settings ----------------
411
411
412
412
initDragula ( ) {
413
- this . dragula . setOptions ( '_shared .playlist' , {
413
+ this . dragula . setOptions ( 'globals .playlist' , {
414
414
moves : ( el , container , handle ) => {
415
415
return handle . className === 'video-item-settings' ;
416
416
}
@@ -436,15 +436,15 @@ export class AppComponent implements OnInit {
436
436
console . log ( 'Updating localstorage...' ) ;
437
437
localStorage . clear ( ) ;
438
438
this . _shared . settings = null ;
439
- this . _shared . playlist = [ ] ;
439
+ this . globals . playlist = [ ] ;
440
440
}
441
441
}
442
442
443
443
setSettings ( ) {
444
444
this . _shared . getSettings ( ) ;
445
445
if ( this . _shared . settings ) {
446
446
this . regionCode = this . _shared . settings . api_settings [ 1 ] . value ;
447
- this . thumbnails = this . _shared . settings . form_settings [ 0 ] . value ;
447
+ this . globals . thumbnails = this . _shared . settings . form_settings [ 0 ] . value ;
448
448
this . displayVideoPlayer = this . _shared . settings . form_settings [ 2 ] . value ;
449
449
this . repeatMode = this . _shared . settings . form_settings [ 3 ] . value ;
450
450
this . darkMode = this . _shared . settings . form_settings [ 4 ] . value ;
@@ -467,14 +467,14 @@ export class AppComponent implements OnInit {
467
467
// ---------------- Video fetching ----------------
468
468
469
469
onClickRelated ( event : Event , i : number ) {
470
- this . getVideo ( this . relatedVideos [ i ] ) ;
470
+ this . getVideo ( this . globals . relatedVideos [ i ] ) ;
471
471
}
472
472
473
473
onClickPlaylist ( event : Event , i : number ) {
474
474
if ( i === this . currentPlaylistItem ) {
475
475
this . playPauseVideo ( ) ;
476
476
} else {
477
- this . getVideo ( this . _shared . playlist [ i ] ) ;
477
+ this . getVideo ( this . globals . playlist [ i ] ) ;
478
478
}
479
479
}
480
480
@@ -516,7 +516,7 @@ export class AppComponent implements OnInit {
516
516
517
517
async getRelatedVideos ( ) {
518
518
const res = await this . youtube . relatedVideos ( this . currentVideo . id ) ;
519
- this . relatedVideos = res [ 'items' ] ;
519
+ this . globals . relatedVideos = res [ 'items' ] ;
520
520
if ( this . playlistPrefill ) {
521
521
this . playlistInit ( ) ;
522
522
this . playlistPrefill = false ;
@@ -627,19 +627,19 @@ export class AppComponent implements OnInit {
627
627
let listType ;
628
628
const youtubeLink = 'https://youtu.be/' ;
629
629
if ( list === 0 ) {
630
- listType = this . _shared . feedVideos [ i ] ;
630
+ listType = this . globals . feedVideos [ i ] ;
631
631
}
632
632
if ( list === 1 ) {
633
- listType = this . _shared . lastSearchedVideos [ i ] ;
633
+ listType = this . globals . lastSearchedVideos [ i ] ;
634
634
}
635
635
if ( list === 2 ) {
636
- listType = this . relatedVideos [ i ] ;
636
+ listType = this . globals . relatedVideos [ i ] ;
637
637
}
638
638
if ( list === 3 ) {
639
- listType = this . _shared . playlist [ i ] ;
639
+ listType = this . globals . playlist [ i ] ;
640
640
}
641
641
if ( list === 4 ) {
642
- listType = this . _shared . historyVideos [ i ] ;
642
+ listType = this . globals . historyVideos [ i ] ;
643
643
}
644
644
645
645
if ( typeof listType . id . videoId !== 'undefined' ) {
0 commit comments