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

Commit

Permalink
Revert "Remove code duplication for thumbnails loading (#562)"
Browse files Browse the repository at this point in the history
This reverts commit fa05eec.
  • Loading branch information
Frontesque committed Nov 17, 2022
1 parent ca688ab commit 0c4ee9e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
8 changes: 1 addition & 7 deletions NUXT/components/Player/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
/>
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions NUXT/plugins/innertube.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
17 changes: 0 additions & 17 deletions NUXT/plugins/thumbnail.js

This file was deleted.

23 changes: 20 additions & 3 deletions NUXT/plugins/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -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™
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0c4ee9e

Please sign in to comment.