0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-28 22:23:04 +00:00

Revert "Remove code duplication for thumbnails loading (#562)"

This reverts commit fa05eec499.
This commit is contained in:
Kenny 2022-11-16 19:27:22 -05:00 committed by GitHub
parent ca688ab397
commit 0c4ee9e7a7
4 changed files with 35 additions and 27 deletions

View file

@ -54,7 +54,7 @@
}rem 0rem 0rem !important`
: '0',
}"
:poster="getThumbnail($route.query.v)"
:poster="$youtube.getThumbnail($route.query.v, 'max', [])"
@loadedmetadata="checkDimensions()"
@click="controlsHandler()"
/>
@ -352,7 +352,6 @@ import progressbar from "~/components/Player/progressbar.vue";
import sponsorblock from "~/components/Player/sponsorblock.vue";
import backType from "~/plugins/classes/backType";
import Thumbnail from "~/plugins/thumbnail";
export default {
components: {
@ -624,11 +623,6 @@ export default {
this.$refs.player.playbackRate = speed;
this.$refs.audio.playbackRate = speed;
},
getThumbnail(query) {
const thumbnail = new Thumbnail();
return thumbnail.getThumbnail(query, "max", []);
},
checkDimensions() {
if (this.$refs.player.videoHeight > this.$refs.player.videoWidth) {
this.isVerticalVideo = true;

View file

@ -262,6 +262,20 @@ class Innertube {
});
}
// Static methods
static getThumbnail(id, resolution) {
if (resolution == "max") {
const url = `https://img.youtube.com/vi/${id}/maxresdefault.jpg`;
let img = new Image();
img.src = url;
img.onload = function () {
if (img.height !== 120) return url;
};
}
return `https://img.youtube.com/vi/${id}/mqdefault.jpg`;
}
// Simple Wrappers
async getRecommendationsAsync() {
const rec = await this.browseAsync("recommendations");

View file

@ -1,17 +0,0 @@
class Thumbnail {
getThumbnail(id, resolution, backupThumbnail) {
if (resolution == "max") {
const url = `https://img.youtube.com/vi/${id}/maxresdefault.jpg`;
let img = new Image();
img.src = url;
img.onload = function () {
if (img.height !== 120) return url;
};
}
if (backupThumbnail[backupThumbnail.length - 1])
return backupThumbnail[backupThumbnail.length - 1].url;
else return `https://img.youtube.com/vi/${id}/mqdefault.jpg`;
}
}
export default Thumbnail;

View file

@ -91,14 +91,30 @@ const innertubeModule = {
async getVid(id) {
try {
return await InnertubeAPI.VidInfoAsync(id);
} catch (error) {}
} catch (error) {
}
},
getThumbnail(id, resolution, backupThumbnail) {
if (resolution == "max") {
const url = `https://img.youtube.com/vi/${id}/maxresdefault.jpg`;
let img = new Image();
img.src = url;
img.onload = function () {
if (img.height !== 120) return url;
};
}
if (backupThumbnail[backupThumbnail.length - 1])
return backupThumbnail[backupThumbnail.length - 1].url;
else return `https://img.youtube.com/vi/${id}/mqdefault.jpg`;
},
async getChannel(url) {
try {
const response = await InnertubeAPI.getChannelAsync(url);
return response.data;
} catch (error) {}
} catch (error) {
}
},
// It just works™
@ -161,7 +177,8 @@ const innertubeModule = {
try {
const response = await InnertubeAPI.getSearchAsync(query);
return response.contents.sectionListRenderer;
} catch (err) {}
} catch (err) {
}
},
async saveApiStats(query, url) {