Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 1a6a94c

Browse files
authored
Merge pull request #580 from VueTubeApp/revert-562-remove-code-duplication-for-thumbnails
Revert "Remove code duplication for thumbnails loading"
2 parents ca688ab + 0c4ee9e commit 1a6a94c

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

NUXT/components/Player/index.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
}rem 0rem 0rem !important`
5555
: '0',
5656
}"
57-
:poster="getThumbnail($route.query.v)"
57+
:poster="$youtube.getThumbnail($route.query.v, 'max', [])"
5858
@loadedmetadata="checkDimensions()"
5959
@click="controlsHandler()"
6060
/>
@@ -352,7 +352,6 @@ import progressbar from "~/components/Player/progressbar.vue";
352352
import sponsorblock from "~/components/Player/sponsorblock.vue";
353353
354354
import backType from "~/plugins/classes/backType";
355-
import Thumbnail from "~/plugins/thumbnail";
356355
357356
export default {
358357
components: {
@@ -624,11 +623,6 @@ export default {
624623
this.$refs.player.playbackRate = speed;
625624
this.$refs.audio.playbackRate = speed;
626625
},
627-
getThumbnail(query) {
628-
const thumbnail = new Thumbnail();
629-
630-
return thumbnail.getThumbnail(query, "max", []);
631-
},
632626
checkDimensions() {
633627
if (this.$refs.player.videoHeight > this.$refs.player.videoWidth) {
634628
this.isVerticalVideo = true;

NUXT/plugins/innertube.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,20 @@ class Innertube {
262262
});
263263
}
264264

265+
// Static methods
266+
267+
static getThumbnail(id, resolution) {
268+
if (resolution == "max") {
269+
const url = `https://img.youtube.com/vi/${id}/maxresdefault.jpg`;
270+
let img = new Image();
271+
img.src = url;
272+
img.onload = function () {
273+
if (img.height !== 120) return url;
274+
};
275+
}
276+
return `https://img.youtube.com/vi/${id}/mqdefault.jpg`;
277+
}
278+
265279
// Simple Wrappers
266280
async getRecommendationsAsync() {
267281
const rec = await this.browseAsync("recommendations");

NUXT/plugins/thumbnail.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

NUXT/plugins/youtube.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,30 @@ const innertubeModule = {
9191
async getVid(id) {
9292
try {
9393
return await InnertubeAPI.VidInfoAsync(id);
94-
} catch (error) {}
94+
} catch (error) {
95+
}
96+
},
97+
98+
getThumbnail(id, resolution, backupThumbnail) {
99+
if (resolution == "max") {
100+
const url = `https://img.youtube.com/vi/${id}/maxresdefault.jpg`;
101+
let img = new Image();
102+
img.src = url;
103+
img.onload = function () {
104+
if (img.height !== 120) return url;
105+
};
106+
}
107+
if (backupThumbnail[backupThumbnail.length - 1])
108+
return backupThumbnail[backupThumbnail.length - 1].url;
109+
else return `https://img.youtube.com/vi/${id}/mqdefault.jpg`;
95110
},
96111

97112
async getChannel(url) {
98113
try {
99114
const response = await InnertubeAPI.getChannelAsync(url);
100115
return response.data;
101-
} catch (error) {}
116+
} catch (error) {
117+
}
102118
},
103119

104120
// It just works™
@@ -161,7 +177,8 @@ const innertubeModule = {
161177
try {
162178
const response = await InnertubeAPI.getSearchAsync(query);
163179
return response.contents.sectionListRenderer;
164-
} catch (err) {}
180+
} catch (err) {
181+
}
165182
},
166183

167184
async saveApiStats(query, url) {

0 commit comments

Comments
 (0)