mirror of
https://github.com/VueTubeApp/VueTube
synced 2024-11-25 04:35:17 +00:00
Remove code duplication for thumbnails loading (#562)
This commit is contained in:
parent
1352008937
commit
fa05eec499
4 changed files with 27 additions and 35 deletions
|
@ -54,7 +54,7 @@
|
||||||
}rem 0rem 0rem !important`
|
}rem 0rem 0rem !important`
|
||||||
: '0',
|
: '0',
|
||||||
}"
|
}"
|
||||||
:poster="$youtube.getThumbnail($route.query.v, 'max', [])"
|
:poster="getThumbnail($route.query.v)"
|
||||||
@loadedmetadata="checkDimensions()"
|
@loadedmetadata="checkDimensions()"
|
||||||
@click="controlsHandler()"
|
@click="controlsHandler()"
|
||||||
/>
|
/>
|
||||||
|
@ -352,6 +352,7 @@ import progressbar from "~/components/Player/progressbar.vue";
|
||||||
import sponsorblock from "~/components/Player/sponsorblock.vue";
|
import sponsorblock from "~/components/Player/sponsorblock.vue";
|
||||||
|
|
||||||
import backType from "~/plugins/classes/backType";
|
import backType from "~/plugins/classes/backType";
|
||||||
|
import Thumbnail from "~/plugins/thumbnail";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -623,6 +624,11 @@ export default {
|
||||||
this.$refs.player.playbackRate = speed;
|
this.$refs.player.playbackRate = speed;
|
||||||
this.$refs.audio.playbackRate = speed;
|
this.$refs.audio.playbackRate = speed;
|
||||||
},
|
},
|
||||||
|
getThumbnail(query) {
|
||||||
|
const thumbnail = new Thumbnail();
|
||||||
|
|
||||||
|
return thumbnail.getThumbnail(query, "max", []);
|
||||||
|
},
|
||||||
checkDimensions() {
|
checkDimensions() {
|
||||||
if (this.$refs.player.videoHeight > this.$refs.player.videoWidth) {
|
if (this.$refs.player.videoHeight > this.$refs.player.videoWidth) {
|
||||||
this.isVerticalVideo = true;
|
this.isVerticalVideo = true;
|
||||||
|
|
|
@ -262,20 +262,6 @@ 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
|
// Simple Wrappers
|
||||||
async getRecommendationsAsync() {
|
async getRecommendationsAsync() {
|
||||||
const rec = await this.browseAsync("recommendations");
|
const rec = await this.browseAsync("recommendations");
|
||||||
|
|
17
NUXT/plugins/thumbnail.js
Normal file
17
NUXT/plugins/thumbnail.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
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;
|
|
@ -91,30 +91,14 @@ const innertubeModule = {
|
||||||
async getVid(id) {
|
async getVid(id) {
|
||||||
try {
|
try {
|
||||||
return await InnertubeAPI.VidInfoAsync(id);
|
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) {
|
async getChannel(url) {
|
||||||
try {
|
try {
|
||||||
const response = await InnertubeAPI.getChannelAsync(url);
|
const response = await InnertubeAPI.getChannelAsync(url);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// It just works™
|
// It just works™
|
||||||
|
@ -177,8 +161,7 @@ const innertubeModule = {
|
||||||
try {
|
try {
|
||||||
const response = await InnertubeAPI.getSearchAsync(query);
|
const response = await InnertubeAPI.getSearchAsync(query);
|
||||||
return response.contents.sectionListRenderer;
|
return response.contents.sectionListRenderer;
|
||||||
} catch (err) {
|
} catch (err) {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveApiStats(query, url) {
|
async saveApiStats(query, url) {
|
||||||
|
|
Loading…
Reference in a new issue