@@ -14,8 +14,7 @@ import * as firebase from 'firebase/app';
14
14
15
15
import { IRelatedVideo } from './models/related-video.model' ;
16
16
import { INotify } from './models/notify.model' ;
17
- import { IFeedVideo } from './models/feed-video.model' ;
18
- import { Observable } from 'rxjs' ;
17
+ import { Observable } from 'rxjs/Observable' ;
19
18
20
19
@Component ( {
21
20
selector : 'app-yt' ,
@@ -32,11 +31,9 @@ export class AppComponent implements OnInit {
32
31
videoRangePercent = 0 ;
33
32
34
33
relatedVideos : Array < IRelatedVideo > = [ ] ;
35
- feedVideos : Array < IFeedVideo > ;
36
- playlistVideos : Array < any > = [ ] ;
37
34
tempPlaylist : Array < any > = [ ] ;
38
35
currentVideoObject : Array < any > = [ ] ;
39
-
36
+
40
37
thumbnails = true ;
41
38
darkMode = true ;
42
39
menuActive = false ;
@@ -99,12 +96,12 @@ export class AppComponent implements OnInit {
99
96
) {
100
97
this . _shared = shared ;
101
98
this . notify = this . _shared . notify ;
102
- this . initDragula ( ) ;
103
99
}
104
100
105
101
ngOnInit ( ) {
106
102
this . preventOldSettings ( ) ;
107
103
this . updateUserDetails ( ) ;
104
+ this . initDragula ( ) ;
108
105
}
109
106
110
107
private hasClass ( el : any , name : string ) {
@@ -138,23 +135,28 @@ export class AppComponent implements OnInit {
138
135
this . authService . checkLogged ( ) ;
139
136
this . db2 . list ( 'sessions/' + localStorage . getItem ( 'session_key' ) ) . valueChanges ( ) . subscribe ( ( data ) => {
140
137
if ( data . length > 0 ) {
138
+ this . clearSession ( ) ;
139
+ localStorage . setItem ( 'settings' , JSON . parse ( data [ '3' ] ) ) ;
141
140
this . currentVideo = data [ '2' ] ;
142
141
this . shareLink = 'https://youtu.be/' + this . currentVideo . id ;
142
+ this . playlistInit ( ) ;
143
143
this . updatePlaylist ( ) ;
144
- this . getRelatedVideos ( ) ;
144
+ this . getRelatedVideos ( ) ;
145
145
} else {
146
146
this . setDefaultPlayer ( ) ;
147
147
}
148
+ this . setSettings ( ) ;
148
149
} ) ;
149
- this . setSettings ( ) ;
150
+ }
151
+
152
+ refreshNow ( ) {
153
+ console . log ( 'si-a facut update' ) ;
150
154
}
151
155
152
156
refresh ( ) {
153
- console . log ( 'da' ) ;
154
- this . currentVideo . id = '' ;
155
157
this . clearSession ( ) ;
156
158
// this.playlistInit();
157
- // this.updatePlaylist ();
159
+ // this.getRelatedVideos ();
158
160
}
159
161
160
162
// ---------------- Init player ----------------
@@ -181,7 +183,6 @@ export class AppComponent implements OnInit {
181
183
async getFeedVideos ( ) {
182
184
await this . _shared . initFeed ( ) ;
183
185
await this . _shared . initChannel ( ) ;
184
- this . feedVideos = this . _shared . feedVideos ;
185
186
if ( ! this . currentVideo . id && ! this . _shared . isLogged ) {
186
187
this . setDefaultPlayer ( ) ;
187
188
}
@@ -197,13 +198,12 @@ export class AppComponent implements OnInit {
197
198
}
198
199
199
200
setDefaultPlayer ( ) {
200
- this . feedVideos = this . _shared . feedVideos ;
201
- this . setCurrentVideoObject ( this . feedVideos [ 0 ] ) ;
202
- this . currentVideo . id = this . feedVideos [ 0 ] . id ;
203
- this . currentVideo . title = this . feedVideos [ 0 ] . snippet . title ;
204
- this . currentVideo . stats . likes = this . feedVideos [ 0 ] . statistics . likeCount ;
205
- this . currentVideo . stats . dislikes = this . feedVideos [ 0 ] . statistics . dislikeCount ;
206
- this . currentVideo . stats . views = this . feedVideos [ 0 ] . statistics . viewCount ;
201
+ this . setCurrentVideoObject ( this . _shared . feedVideos [ 0 ] ) ;
202
+ this . currentVideo . id = this . _shared . feedVideos [ 0 ] . id ;
203
+ this . currentVideo . title = this . _shared . feedVideos [ 0 ] . snippet . title ;
204
+ this . currentVideo . stats . likes = this . _shared . feedVideos [ 0 ] . statistics . likeCount ;
205
+ this . currentVideo . stats . dislikes = this . _shared . feedVideos [ 0 ] . statistics . dislikeCount ;
206
+ this . currentVideo . stats . views = this . _shared . feedVideos [ 0 ] . statistics . viewCount ;
207
207
this . shareLink = 'https://youtu.be/' + this . currentVideo . id ;
208
208
this . getRelatedVideos ( ) ;
209
209
this . findPlaylistItem ( ) ;
@@ -225,14 +225,14 @@ export class AppComponent implements OnInit {
225
225
if ( this . currentState === 0 ) {
226
226
this . stopRange ( ) ;
227
227
if ( this . repeatMode ) {
228
- if ( this . playlistVideos . length ) {
228
+ if ( this . _shared . playlist . length ) {
229
229
this . findPlaylistItem ( ) ;
230
230
if ( this . currentPlaylistItem < 0 ) {
231
231
this . playPlaylistItem ( 'next' , this . currentPlaylistItem ) ;
232
232
} else {
233
233
this . playPlaylistItem ( 'next' , this . currentPlaylistItem ) ;
234
234
}
235
- if ( this . playlistVideos . length === 1 ) {
235
+ if ( this . _shared . playlist . length === 1 ) {
236
236
this . player . playVideo ( ) ;
237
237
}
238
238
} else {
@@ -261,7 +261,6 @@ export class AppComponent implements OnInit {
261
261
262
262
updatePlaylist ( ) {
263
263
this . findPlaylistItem ( ) ;
264
- this . _shared . playlist = this . playlistVideos ;
265
264
this . _shared . updatePlaylist ( ) ;
266
265
}
267
266
@@ -280,47 +279,45 @@ export class AppComponent implements OnInit {
280
279
}
281
280
282
281
playlistInit ( ) {
283
- if ( localStorage . getItem ( 'playlist' ) === null || localStorage . getItem ( 'playlist' ) . length === 2 ) {
284
- this . playlistVideos = JSON . parse ( JSON . stringify ( this . relatedVideos ) ) ;
285
- this . _shared . playlist = JSON . parse ( JSON . stringify ( this . playlistVideos ) ) ;
286
- this . _shared . updatePlaylist ( ) ;
287
- } else {
288
- this . _shared . getPlaylist ( ) ;
289
- this . playlistVideos = JSON . parse ( JSON . stringify ( this . _shared . playlist ) ) ;
290
- }
291
- this . findPlaylistItem ( ) ;
282
+ if ( localStorage . getItem ( 'playlist' ) === null || localStorage . getItem ( 'playlist' ) . length === 2 ) {
283
+ this . _shared . playlist = JSON . parse ( JSON . stringify ( this . relatedVideos ) ) ;
284
+ this . _shared . updatePlaylist ( ) ;
285
+ } else {
286
+ this . _shared . getPlaylist ( ) ;
287
+ }
288
+ this . findPlaylistItem ( ) ;
292
289
}
293
290
294
291
findPlaylistItem ( ) {
295
- let playlistItem ;
296
- if ( ! this . _shared . isLogged ) {
297
- if ( typeof this . currentVideoObject [ 0 ] . id . videoId !== 'undefined' ) {
298
- playlistItem = this . playlistVideos . find ( item => item . id . videoId === this . currentVideoObject [ 0 ] . id . videoId ) ;
299
- } else {
300
- playlistItem = this . playlistVideos . find ( item => item . id === this . currentVideoObject [ 0 ] . id ) ;
301
- }
302
- }
303
- this . currentPlaylistItem = this . playlistVideos . indexOf ( playlistItem ) ;
292
+ let playlistItem ;
293
+ if ( typeof this . currentVideoObject [ 0 ] . id . videoId !== 'undefined' ) {
294
+ playlistItem = this . _shared . playlist . find ( item => item . id . videoId === this . currentVideoObject [ 0 ] . id . videoId ) ;
295
+ } else {
296
+ playlistItem = this . _shared . playlist . find ( item => item . id === this . currentVideoObject [ 0 ] . id ) ;
297
+ }
298
+ console . log ( this . _shared . playlist ) ;
299
+ console . log ( this . currentVideoObject [ 0 ] . id ) ;
300
+ this . currentPlaylistItem = this . _shared . playlist . indexOf ( playlistItem ) ;
304
301
}
305
302
306
303
playPlaylistItem ( direction : string , i : number ) {
307
304
if ( direction === 'next' ) {
308
- if ( i < this . playlistVideos . length ) {
305
+ if ( i < this . _shared . playlist . length ) {
309
306
i += 1 ;
310
307
}
311
- if ( i === this . playlistVideos . length ) {
308
+ if ( i === this . _shared . playlist . length ) {
312
309
i = 0 ;
313
310
}
314
311
}
315
312
if ( direction === 'prev' ) {
316
313
if ( i === 0 || i < 0 ) {
317
- i = this . playlistVideos . length - 1 ;
314
+ i = this . _shared . playlist . length - 1 ;
318
315
} else {
319
316
i -= 1 ;
320
317
}
321
318
}
322
- if ( this . playlistVideos . length > 0 ) {
323
- this . getVideo ( this . playlistVideos [ i ] ) ;
319
+ if ( this . _shared . playlist . length > 0 ) {
320
+ this . getVideo ( this . _shared . playlist [ i ] ) ;
324
321
} else {
325
322
this . _shared . triggerNotify ( 'Playlist is empty' ) ;
326
323
this . updateNotify ( ) ;
@@ -334,7 +331,7 @@ export class AppComponent implements OnInit {
334
331
if ( i === this . currentPlaylistItem ) {
335
332
this . currentPlaylistItem = - 1 ;
336
333
}
337
- this . playlistVideos . splice ( i , 1 ) ;
334
+ this . _shared . playlist . splice ( i , 1 ) ;
338
335
this . updatePlaylist ( ) ;
339
336
} , 200 ) ;
340
337
}
@@ -359,13 +356,13 @@ export class AppComponent implements OnInit {
359
356
}
360
357
361
358
if ( typeof listType . id . videoId !== 'undefined' ) {
362
- playlistItem = this . playlistVideos . find ( item => item . id . videoId === listType . id . videoId ) ;
359
+ playlistItem = this . _shared . playlist . find ( item => item . id . videoId === listType . id . videoId ) ;
363
360
} else {
364
- playlistItem = this . playlistVideos . find ( item => item . id === listType . id ) ;
361
+ playlistItem = this . _shared . playlist . find ( item => item . id === listType . id ) ;
365
362
}
366
363
367
364
if ( typeof playlistItem === 'undefined' ) {
368
- this . playlistVideos . push ( listType ) ;
365
+ this . _shared . playlist . push ( listType ) ;
369
366
this . updatePlaylist ( ) ;
370
367
371
368
this . _shared . triggerNotify ( 'Added to playlist' ) ;
@@ -379,16 +376,27 @@ export class AppComponent implements OnInit {
379
376
380
377
clearPlaylist ( ) {
381
378
this . currentPlaylistItem = - 1 ;
382
- this . playlistVideos = [ ] ;
383
379
this . _shared . playlist = [ ] ;
384
380
this . _shared . updatePlaylist ( ) ;
385
381
}
386
382
387
383
clearSession ( ) {
384
+ const removedCurrentVid = {
385
+ id : '' ,
386
+ title : '' ,
387
+ channelTitle : '' ,
388
+ stats : {
389
+ likes : '' ,
390
+ dislikes : '' ,
391
+ views : ''
392
+ }
393
+ } ;
394
+ this . currentVideo = removedCurrentVid ;
388
395
this . currentPlaylistItem = - 1 ;
389
- this . playlistVideos = [ ] ;
390
396
this . _shared . playlist = [ ] ;
391
397
this . relatedVideos = [ ] ;
398
+ localStorage . removeItem ( 'playlist' ) ;
399
+ // localStorage.removeItem('settings');
392
400
}
393
401
394
402
exportPlaylist ( ) {
@@ -397,14 +405,13 @@ export class AppComponent implements OnInit {
397
405
398
406
exportFilePlaylist ( ) {
399
407
const a = document . createElement ( 'a' ) ;
400
- const file = new Blob ( [ JSON . stringify ( this . playlistVideos ) ] , { type : 'data:text/json;charset=utf8' } ) ;
408
+ const file = new Blob ( [ JSON . stringify ( this . _shared . playlist ) ] , { type : 'data:text/json;charset=utf8' } ) ;
401
409
a . href = URL . createObjectURL ( file ) ;
402
410
a . download = 'playlist.json' ;
403
411
a . click ( ) ;
404
412
}
405
413
406
414
importPlaylist ( input : any ) {
407
- this . playlistVideos = this . tempPlaylist ;
408
415
this . _shared . playlist = this . tempPlaylist ;
409
416
this . tempPlaylist = [ ] ;
410
417
this . _shared . updatePlaylist ( ) ;
@@ -414,7 +421,7 @@ export class AppComponent implements OnInit {
414
421
// ---------------- Init settings ----------------
415
422
416
423
initDragula ( ) {
417
- this . dragula . setOptions ( 'playlistVideos ' , {
424
+ this . dragula . setOptions ( '_shared.playlist ' , {
418
425
moves : ( el , container , handle ) => {
419
426
return handle . className === 'video-item-settings' ;
420
427
}
@@ -442,7 +449,7 @@ export class AppComponent implements OnInit {
442
449
this . _shared . settings = null ;
443
450
this . _shared . playlist = null ;
444
451
445
- this . playlistVideos = [ ] ;
452
+ this . _shared . playlist = [ ] ;
446
453
}
447
454
}
448
455
@@ -480,7 +487,7 @@ export class AppComponent implements OnInit {
480
487
if ( i === this . currentPlaylistItem ) {
481
488
this . playPauseVideo ( ) ;
482
489
} else {
483
- this . getVideo ( this . playlistVideos [ i ] ) ;
490
+ this . getVideo ( this . _shared . playlist [ i ] ) ;
484
491
}
485
492
}
486
493
@@ -533,7 +540,7 @@ export class AppComponent implements OnInit {
533
540
534
541
playPauseVideo ( ) {
535
542
if ( this . currentState === 1 ) {
536
- this . player . pauseVideo ( ) ;
543
+ this . player . pauseVideo ( ) ;
537
544
} else {
538
545
this . player . playVideo ( ) ;
539
546
}
@@ -642,7 +649,7 @@ export class AppComponent implements OnInit {
642
649
listType = this . relatedVideos [ i ] ;
643
650
}
644
651
if ( list === 3 ) {
645
- listType = this . playlistVideos [ i ] ;
652
+ listType = this . _shared . playlist [ i ] ;
646
653
}
647
654
if ( list === 4 ) {
648
655
listType = this . _shared . historyVideos [ i ] ;
0 commit comments