mirror of
https://github.com/VueTubeApp/VueTube
synced 2024-11-25 04:35:17 +00:00
Revert "Remove code duplication for thumbnails loading (#562)"
This reverts commit fa05eec499
.
This commit is contained in:
parent
ca688ab397
commit
0c4ee9e7a7
4 changed files with 35 additions and 27 deletions
|
@ -54,7 +54,7 @@
|
||||||
}rem 0rem 0rem !important`
|
}rem 0rem 0rem !important`
|
||||||
: '0',
|
: '0',
|
||||||
}"
|
}"
|
||||||
:poster="getThumbnail($route.query.v)"
|
:poster="$youtube.getThumbnail($route.query.v, 'max', [])"
|
||||||
@loadedmetadata="checkDimensions()"
|
@loadedmetadata="checkDimensions()"
|
||||||
@click="controlsHandler()"
|
@click="controlsHandler()"
|
||||||
/>
|
/>
|
||||||
|
@ -352,7 +352,6 @@ 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: {
|
||||||
|
@ -624,11 +623,6 @@ 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,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
|
// Simple Wrappers
|
||||||
async getRecommendationsAsync() {
|
async getRecommendationsAsync() {
|
||||||
const rec = await this.browseAsync("recommendations");
|
const rec = await this.browseAsync("recommendations");
|
||||||
|
|
|
@ -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;
|
|
|
@ -91,14 +91,30 @@ 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™
|
||||||
|
@ -161,7 +177,8 @@ 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