Skip to content

Commit 9b74f74

Browse files
committed
2.0.2 - Refactoring services
1 parent d41f03e commit 9b74f74

File tree

7 files changed

+148
-289
lines changed

7 files changed

+148
-289
lines changed

src/app/app.component.ts

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ export class AppComponent implements OnInit {
9797
}
9898
});
9999
this.preventOldSettings();
100+
100101
this.setSettings();
102+
101103
this.getFeedVideos();
102104
}
103105

@@ -122,13 +124,12 @@ export class AppComponent implements OnInit {
122124
return playerVars;
123125
}
124126

125-
getFeedVideos() {
126-
this._shared.getFeed().subscribe(data => {
127-
this.feedVideos = data;
128-
if (!this.currentVideo.id) {
129-
this.setDefaultPlayer();
130-
}
131-
});
127+
async getFeedVideos() {
128+
await this._shared.initFeed();
129+
this.feedVideos = this._shared.feedVideos;
130+
if (!this.currentVideo.id) {
131+
this.setDefaultPlayer();
132+
}
132133
}
133134

134135
setCurrentVideoObject(data: any) {
@@ -186,7 +187,6 @@ export class AppComponent implements OnInit {
186187
this.stopRange();
187188
if (this.currentState) {
188189
this.videoRangeTimer = setInterval(() => {
189-
console.log('Rangeu merge de nebun...');
190190
this.videoCurRange = this.player.getCurrentTime();
191191
this.videoCurFull = this.timeFormat(this.videoCurRange);
192192
this.videoRangePercent = (this.videoCurRange / this.videoMaxRange) * 100;
@@ -347,7 +347,7 @@ export class AppComponent implements OnInit {
347347
// ---------------- Init settings ----------------
348348

349349
preventOldSettings() {
350-
if (localStorage.length === 1 || localStorage.getItem('version') === null) {
350+
if (localStorage.length === 1 || !localStorage.getItem('version')) {
351351
console.log('Updating localstorage...');
352352
localStorage.removeItem('version');
353353
localStorage.removeItem('playlist');
@@ -359,14 +359,13 @@ export class AppComponent implements OnInit {
359359
}
360360
}
361361

362-
setSettings() {
363-
this._shared.getSettings().subscribe(data => {
364-
this.regionCode = data.api_settings[1].value;
365-
this.thumbnails = data.form_settings[0].value;
366-
this.displayVideoPlayer = data.form_settings[2].value;
367-
this.repeatMode = data.form_settings[3].value;
368-
this.darkMode = data.form_settings[4].value;
369-
});
362+
async setSettings() {
363+
await this._shared.getSettings();
364+
this.regionCode = this._shared.settings.api_settings[1].value;
365+
this.thumbnails = this._shared.settings.form_settings[0].value;
366+
this.displayVideoPlayer = this._shared.settings.form_settings[2].value;
367+
this.repeatMode = this._shared.settings.form_settings[3].value;
368+
this.darkMode = this._shared.settings.form_settings[4].value;
370369
}
371370

372371
toggleHeadSettings(int: number) {
@@ -421,36 +420,24 @@ export class AppComponent implements OnInit {
421420
}
422421
}
423422

424-
getStatsVideos(query: string) {
425-
this.youtube.statsVideos(query).subscribe(
426-
result => {
427-
this.currentVideo.id = result['items'][0].id;
428-
this.currentVideo.title = result['items'][0].snippet.title;
429-
this.currentVideo.channelTitle = result['items'][0].snippet.channelTitle;
430-
this.currentVideo.stats.likes = result['items'][0].statistics.likeCount;
431-
this.currentVideo.stats.dislikes = result['items'][0].statistics.dislikeCount;
432-
this.currentVideo.stats.views = result['items'][0].statistics.viewCount;
433-
this.shareLink = 'https://youtu.be/' + this.currentVideo.id;
434-
},
435-
error => {
436-
console.log('error on related videos');
437-
}
438-
);
423+
async getStatsVideos(query: string) {
424+
const res = await this.youtube.statsVideos(query);
425+
this.currentVideo.id = res['items'][0].id;
426+
this.currentVideo.title = res['items'][0].snippet.title;
427+
this.currentVideo.channelTitle = res['items'][0].snippet.channelTitle;
428+
this.currentVideo.stats.likes = res['items'][0].statistics.likeCount;
429+
this.currentVideo.stats.dislikes = res['items'][0].statistics.dislikeCount;
430+
this.currentVideo.stats.views = res['items'][0].statistics.viewCount;
431+
this.shareLink = 'https://youtu.be/' + this.currentVideo.id;
439432
}
440433

441-
getRelatedVideos() {
442-
this.youtube.relatedVideos(this.currentVideo.id).subscribe(
443-
result => {
444-
this.relatedVideos = result['items'];
445-
if (this.playlistPrefill) {
446-
this.playlistInit();
447-
this.playlistPrefill = false;
448-
}
449-
},
450-
error => {
451-
console.log('error on related videos');
452-
}
453-
);
434+
async getRelatedVideos() {
435+
const res = await this.youtube.relatedVideos(this.currentVideo.id);
436+
this.relatedVideos = res['items'];
437+
if (this.playlistPrefill) {
438+
this.playlistInit();
439+
this.playlistPrefill = false;
440+
}
454441
}
455442

456443
// ---------------- Player controls ----------------
@@ -677,7 +664,6 @@ export class AppComponent implements OnInit {
677664

678665
copyShareLink() {
679666
if (!this.notify.enabled) {
680-
console.log('test');
681667
document.execCommand('Copy');
682668
this._shared.triggerNotify('Copied');
683669
this.updateNotify();

src/app/components/youtube-history.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ export class HistoryComponent implements OnInit {
3434
}
3535

3636
getSettings() {
37-
this._shared.getSettings().subscribe(data => {
38-
this.thumbnails = data.form_settings[0].value;
39-
});
37+
this.thumbnails = this._shared.settings.form_settings[0].value;
4038
}
4139

4240
addPlaylistItem(i: number, list: number) {

src/app/components/youtube-search.component.ts

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,36 @@ export class SearchComponent implements OnInit {
6262
console.log('search');
6363
this.setSettings();
6464
this.searchFunction();
65+
6566
this.getFeedVideos();
66-
this.initCategories();
67+
68+
this.getCategories();
6769
}
6870

69-
initCategories() {
70-
this._shared.getCategories().subscribe(
71-
data => {
72-
this.categories = data;
73-
console.log(this.categories);
74-
}
75-
);
76-
this._shared.getVideoCategories(2).subscribe(
77-
result => {
78-
console.log(result);
79-
}
80-
);
71+
async getCategories() {
72+
const res = await this.youtube.categories();
73+
this.categories = res;
74+
75+
const res2 = await this.youtube.videoCategories(2);
76+
}
77+
78+
async setSettings() {
79+
this.thumbnails = this._shared.settings.form_settings[0].value;
80+
this.listGrid = this._shared.settings.form_settings[1].value;
81+
}
82+
83+
async getFeedVideos() {
84+
await this._shared.initFeed();
85+
await this._shared.initChannel();
86+
this.feedVideos = this._shared.feedVideos;
87+
this.channel = this._shared.channel;
88+
this.getChannelTrending();
89+
}
90+
91+
async searchVideo(query: any) {
92+
const res = await this.youtube.searchVideo(query);
93+
this.videos = res['items'];
94+
this._shared.lastSearchedVideos = res['items'];
8195
}
8296

8397
searchFunction() {
@@ -86,56 +100,28 @@ export class SearchComponent implements OnInit {
86100
});
87101

88102
this.searchForm.valueChanges.subscribe((form) => {
89-
this.youtube.searchVideo(form.searchInput).subscribe(
90-
result => {
91-
if (!this.searchForm.invalid) {
92-
this.videos = result['items'];
93-
this._shared.lastSearchedVideos = result['items'];
94-
} else {
95-
this.videos = null;
96-
}
97-
},
98-
error => {
99-
console.log('error on search');
100-
}
101-
);
102-
});
103-
}
104-
105-
setSettings() {
106-
this._shared.getSettings().subscribe(data => {
107-
this.thumbnails = data.form_settings[0].value;
108-
this.listGrid = data.form_settings[1].value;
103+
this.searchVideo(form.searchInput);
109104
});
110105
}
111106

112-
getFeedVideos() {
113-
this._shared.getFeed().subscribe(data => {
114-
this.feedVideos = data;
115-
this.getChannelTrending(this.feedVideos[0].snippet.channelId);
116-
});
117-
}
118-
119-
getChannelTrending(query: any) {
120-
this._shared.getChannel(query).subscribe(data => {
121-
this.feedVideos = this._shared.feedVideos;
122-
this.channel = this._shared.channel;
123-
this.trendingFirst.video.id = this.feedVideos[0].id;
124-
this.trendingFirst.video.title = this.feedVideos[0].snippet.title;
125-
this.trendingFirst.video.img = this.feedVideos[0].snippet.thumbnails.medium.url;
126-
this.trendingFirst.video.stats.likes = this.feedVideos[0].statistics.likeCount;
127-
this.trendingFirst.video.stats.dislikes = this.feedVideos[0].statistics.dislikeCount;
128-
this.trendingFirst.video.stats.views = this.feedVideos[0].statistics.viewCount;
129-
this.trendingFirst.bannerURL = this.channel.items[0].brandingSettings.image.bannerTabletHdImageUrl;
130-
this.trendingFirst.video.channelTitle = this.channel.items[0].snippet.title;
131-
if (!this.channel.items[0].statistics.hiddenSubscriberCount) {
132-
this.trendingFirst.stats.subscribers = this.channel.items[0].statistics.subscriberCount;
133-
} else {
134-
this.trendingFirst.stats.subscribers = '0';
135-
}
136-
this.trendingFirst.stats.videoCount = this.channel.items[0].statistics.videoCount;
137-
this.trendingFirst.stats.views = this.channel.items[0].statistics.viewCount;
138-
});
107+
getChannelTrending() {
108+
this.feedVideos = this._shared.feedVideos;
109+
this.channel = this._shared.channel;
110+
this.trendingFirst.video.id = this.feedVideos[0].id;
111+
this.trendingFirst.video.title = this.feedVideos[0].snippet.title;
112+
this.trendingFirst.video.img = this.feedVideos[0].snippet.thumbnails.medium.url;
113+
this.trendingFirst.video.stats.likes = this.feedVideos[0].statistics.likeCount;
114+
this.trendingFirst.video.stats.dislikes = this.feedVideos[0].statistics.dislikeCount;
115+
this.trendingFirst.video.stats.views = this.feedVideos[0].statistics.viewCount;
116+
this.trendingFirst.bannerURL = this.channel.items[0].brandingSettings.image.bannerTabletHdImageUrl;
117+
this.trendingFirst.video.channelTitle = this.channel.items[0].snippet.title;
118+
if (!this.channel.items[0].statistics.hiddenSubscriberCount) {
119+
this.trendingFirst.stats.subscribers = this.channel.items[0].statistics.subscriberCount;
120+
} else {
121+
this.trendingFirst.stats.subscribers = '0';
122+
}
123+
this.trendingFirst.stats.videoCount = this.channel.items[0].statistics.videoCount;
124+
this.trendingFirst.stats.views = this.channel.items[0].statistics.viewCount;
139125
}
140126

141127
clearSearch() {

src/app/components/youtube-settings.component.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ export class SettingsComponent implements OnInit {
8080
Object.keys(data.settings).map(i => {
8181
this.internal_settings[i].value = data.settings[i];
8282
});
83-
this._shared.form_settings = this.internal_settings;
83+
this._shared.settings.form_settings = this.internal_settings;
84+
this._shared.updateSettings();
8485

8586
this._app.setSettings();
8687
this._app.checkVolumeRange();
8788
this._search.setSettings();
88-
this._shared.updateSettings();
8989

9090
this._shared.triggerNotify('Changed');
9191
this.updateNotify();
@@ -100,13 +100,11 @@ export class SettingsComponent implements OnInit {
100100
}
101101

102102
getDefaultSettings() {
103-
this._shared.getSettings().subscribe(data => {
104-
this.internal_settings = data.form_settings;
105-
this.external_settings = data.api_settings;
106-
this.initExternalForm();
107-
this.finished = true;
108-
this.setForm();
109-
});
103+
this.internal_settings = this._shared.settings.form_settings;
104+
this.external_settings = this._shared.settings.api_settings;
105+
this.initExternalForm();
106+
this.finished = true;
107+
this.setForm();
110108
}
111109

112110
updateNotify() {
@@ -121,13 +119,13 @@ export class SettingsComponent implements OnInit {
121119
this.external_settings[2].value = parseInt(this.externalSettings.controls.fcSearchresults.value, 10);
122120
this.external_settings[3].value = parseInt(this.externalSettings.controls.fcRelatedResults.value, 10);
123121
this._shared.settings.api_settings = this.external_settings;
124-
125122
this._shared.feedVideos = null;
126123

124+
this._shared.updateSettings();
125+
127126
this._shared.setApiSettings();
128127
this._app.setSettings();
129128
this._app.getFeedVideos();
130-
this._shared.updateSettings();
131129

132130
this._shared.triggerNotify('Saved');
133131
this.updateNotify();

0 commit comments

Comments
 (0)