0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-16 16:25:17 +00:00
This commit is contained in:
Alex 2022-03-31 16:00:36 +13:00
commit 1db075c5ee
12 changed files with 397 additions and 171 deletions

View file

@ -0,0 +1,130 @@
<template>
<div>
<div class="content">
<v-btn class="pausePlay" text @click="playing = !playing">
<v-icon size="5em" color="white">mdi-{{ playing ? "pause" : "play" }}</v-icon>
</v-btn>
<div class="seekBar">
<v-slider
dense
hide-details
min="0"
:max="videoEnd"
:value="currentTime"
@change="scrubTo()"
/>
</div>
<video
ref="player"
autoplay
:src="vidSrc"
width="100%"
style="max-height: 50vh"
@webkitfullscreenchange="handleFullscreenChange"
/>
</div>
<div v-for="(source, index) in sources" :key="index">
{{ source.qualityLabel }}
</div>
</div>
</template>
<script>
export default {
props: {
sources: {
type: Array,
default: [],
},
},
data() {
return {
//--- Basic Information ---//
playerVersion: 0.1,
vidSrc: null,
//--- Player State Information ---//
playing: true,
currentTime: 0,
videoEnd: 0,
};
},
watch: {
playing() {
this.playing ? this.$refs.player.play() : this.$refs.player.pause();
},
},
mounted() {
const src = this.sources[this.sources.length - 1].url;
this.vidSrc = src;
setInterval(this.updateTiming, 100);
},
methods: {
handleFullscreenChange() {
if (document.fullscreenElement === this.$refs.player) {
this.$vuetube.statusBar.hide();
this.$vuetube.navigationBar.hide();
} else {
this.$vuetube.statusBar.show();
this.$vuetube.navigationBar.show();
}
},
scrubTo() {
const player = this.$refs.player;
player.currentTime = 0;
console.log(val, this.currentTime, player.currentTime);
},
updateTiming() {
const player = this.$refs.player;
if (player == undefined) return;
this.videoEnd = player.duration;
this.currentTime = player.currentTime;
console.log(player.currentTime, this.currentTime);
},
},
};
</script>
<style scoped>
/*** Overlay Information ***/
.content {
position: relative;
width: 500px;
margin: 0 auto;
}
.content video {
width: 100%;
display: block;
}
.content:before {
content: "";
position: absolute;
background: rgba(0, 0, 0, 0.5);
top: 0;
right: 0;
bottom: 0;
left: 0;
}
/*** General Overlay Styling ***/
.pausePlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.seekBar {
position: absolute;
bottom: 0;
width: 100%;
}
</style>

View file

@ -0,0 +1,122 @@
<template>
<div>
<div class="content">
<v-btn class="pausePlay" text @click="playing = !playing">
<v-icon size="5em" color="white">mdi-{{ playing ? "pause" : "play" }}</v-icon>
</v-btn>
<scrubber class="scrubber" :duration="duration" :endDuration="endDuration" />
<video
ref="player"
autoplay
:src="vidSrc"
width="100%"
style="max-height: 50vh"
@webkitfullscreenchange="handleFullscreenChange"
/>
</div>
<div v-for="(source, index) in sources" :key="index">
{{ source.qualityLabel }}
</div>
</div>
</template>
<script>
import scrubber from "./scrubber.vue";
export default {
components: {
scrubber,
},
props: {
sources: {
type: Array,
default: [],
},
},
data() {
return {
//--- Basic Information ---//
playerVersion: 0.1,
vidSrc: null,
//--- Player State Information ---//
playing: true,
duration: 0,
endDuration: 0,
};
},
watch: {
playing() {
this.playing ? this.$refs.player.play() : this.$refs.player.pause();
},
},
mounted() {
const src = this.sources[this.sources.length - 1].url;
this.vidSrc = src;
setInterval(this.updateTiming, 100);
},
methods: {
handleFullscreenChange() {
if (document.fullscreenElement === this.$refs.player) {
this.$vuetube.statusBar.hide();
this.$vuetube.navigationBar.hide();
} else {
this.$vuetube.statusBar.show();
this.$vuetube.navigationBar.show();
}
},
updateTiming() {
const player = this.$refs.player;
if (player == undefined) return;
this.duration = player.currentTime;
this.endDuration = player.duration;
},
},
};
</script>
<style scoped>
/*** Overlay Information ***/
.content {
position: relative;
width: 500px;
margin: 0 auto;
}
.content video {
width: 100%;
display: block;
}
.content:before {
content: "";
position: absolute;
background: rgba(0, 0, 0, 0.5);
top: 0;
right: 0;
bottom: 0;
left: 0;
}
/*** General Overlay Styling ***/
.pausePlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 5em !important;
width: 5em !important;
}
.scrubber {
position: absolute;
bottom: 0;
}
</style>

View file

@ -0,0 +1,44 @@
<template>
<div class="scrubber">
<div id="progress" class="primary" />
</div>
</template>
<script>
export default {
props: {
duration: {
type: Number,
default: 0,
},
endDuration: {
type: Number,
default: 0,
},
},
data() {
return {
percentage: 0,
};
},
mounted() {
const vm = this;
setInterval(function () {
vm.percentage = (vm.duration / vm.endDuration) * 100;
document.getElementById("progress").style.width = vm.percentage + "%";
}, 100);
},
};
</script>
<style scoped>
.scrubber {
width: 100%;
height: 5px;
background: rgba(255, 255, 255, 0.5);
}
#progress {
height: 100%;
}
</style>

View file

@ -1,5 +1,5 @@
<template> <template>
<div class="description" style="white-space: pre-line"> <div class="description">
<template v-for="(text, index) in render.description.runs"> <template v-for="(text, index) in render.description.runs">
<template <template
v-if=" v-if="
@ -7,19 +7,15 @@
" "
> >
<a <a
@click=" @click="openExternal($rendererUtils.getNavigationEndpoints(text))"
openExternal(this.$rendererUtils.getNavigationEndpoints(text))
"
:key="index" :key="index"
class="link" class="link"
>{{ text.text }}</a >{{ text.text }}</a
> >
</template> </template>
<template v-else-if="this.$rendererUtils.checkInternal(text)"> <template v-else-if="$rendererUtils.checkInternal(text)">
<a <a
@click=" @click="openInternal($rendererUtils.getNavigationEndpoints(text))"
openInternal(this.$rendererUtils.getNavigationEndpoints(text))
"
:key="index" :key="index"
class="link" class="link"
>{{ text.text }}</a >{{ text.text }}</a
@ -30,7 +26,12 @@
</div> </div>
</template> </template>
<style scoped></style> <style scoped>
.description {
white-space: pre-line;
margin-bottom: 16px;
}
</style>
<script> <script>
import { Browser } from "@capacitor/browser"; import { Browser } from "@capacitor/browser";

View file

@ -1,132 +0,0 @@
<template>
<div>
<div class="content">
<v-btn @click="playing = !playing" class="pausePlay" text><v-icon size="5em" color="white">mdi-{{playing ? 'pause' : 'play' }}</v-icon></v-btn>
<div class="seekBar">
<v-slider dense hide-details min="0" :max="videoEnd" :value="currentTime" @change="scrubTo(value)" />
</div>
<video
autoplay
:src="vidSrc"
width="100%"
@webkitfullscreenchange="handleFullscreenChange"
ref="player"
style="max-height: 50vh"
/>
</div>
<div v-for="(source, index) in sources" :key="index">
{{ source.qualityLabel }}
</div>
</div>
</template>
<script>
export default {
props: {
sources: {
type: Array,
default: [],
},
},
data() {
return {
//--- Basic Information ---//
playerVersion: 0.1,
vidSrc: null,
//--- Player State Information ---//
playing: true,
currentTime: 0,
videoEnd: 0,
}
},
watch: {
playing() {
this.playing
? this.$refs.player.play()
: this.$refs.player.pause()
},
},
methods: {
handleFullscreenChange() {
if (document.fullscreenElement === this.$refs.player) {
this.$vuetube.statusBar.hide();
this.$vuetube.navigationBar.hide();
} else {
this.$vuetube.statusBar.show();
this.$vuetube.navigationBar.show();
}
},
scrubTo(val) {
const player = this.$refs.player;
player.currentTime = val;
console.log(val, this.currentTime, player.currentTime)
},
updateTiming() {
const player = this.$refs.player;
this.videoEnd = player?.duration;
this.currentTime = player?.currentTime;
console.log(player.currentTime, this.currentTime)
}
},
mounted() {
const src = this.sources[this.sources.length-1].url;
this.vidSrc = src;
setInterval(this.updateTiming, 100);
}
}
</script>
<style scoped>
/*** Overlay Information ***/
.content {
position: relative;
width: 500px;
margin: 0 auto;
}
.content video {
width: 100%;
display: block;
}
.content:before {
content: '';
position: absolute;
background: rgba(0, 0, 0, 0.5);
top: 0;
right: 0;
bottom: 0;
left: 0;
}
/*** General Overlay Styling ***/
.pausePlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.seekBar {
position: absolute;
bottom: 0;
width: 100%;
}
</style>

View file

@ -77,11 +77,18 @@ export default {
methods: { methods: {
refreshRecommendations() { refreshRecommendations() {
this.$emit("scroll-to-top"); this.$emit("scroll-to-top");
const continuations = this.$store.state.recommendedVideos.continuations;
this.$store.commit("updateRecommendedVideos", []); this.$store.commit("updateRecommendedVideos", []);
this.$youtube this.$youtube
.recommend() .continuation(
continuations[1].reloadContinuationData.continuation,
"browse"
)
.then((result) => { .then((result) => {
if (result) this.$store.commit("updateRecommendedVideos", result[0]); if (result)
this.$youtube.recommend(result).then((result) => {
if (result) this.$store.commit("updateRecommendedVideos", result);
});
}) })
.catch((error) => this.$logger("Home Page (Nav Refresh)", error, true)); .catch((error) => this.$logger("Home Page (Nav Refresh)", error, true));
}, },

View file

@ -7,8 +7,8 @@
<div> <div>
<!-- Video Loading Animation --> <!-- Video Loading Animation -->
<vid-load-renderer v-if="!recommends" /> <vid-load-renderer v-if="!recommends.contents" />
<horizontal-list-renderer v-else :render="recommends" /> <horizontal-list-renderer v-else :render="recommends.contents[0]" />
</div> </div>
</template> </template>
@ -29,14 +29,12 @@ export default {
}, },
}, },
// The following code is only a demo for debugging purposes, note that each "shelfRenderer" has a "title" value that seems to align to the categories at the top of the vanilla yt app
mounted() { mounted() {
if (!this.recommends.items || !this.recommends.items.length) { if (!this.recommends.items || !this.recommends.items.length) {
this.$youtube this.$youtube
.recommend() .recommend()
.then((result) => { .then((result) => {
if (result) this.recommends = result[0]; if (result) this.recommends = result;
}) })
.catch((error) => this.$logger("Home Page", error, true)); .catch((error) => this.$logger("Home Page", error, true));
} }

View file

@ -28,7 +28,7 @@
<div>OS: {{ deviceInfo.operatingSystem }} ({{ deviceInfo.osVersion }})</div> <div>OS: {{ deviceInfo.operatingSystem }} ({{ deviceInfo.osVersion }})</div>
<div>Model: {{ deviceInfo.model }}</div> <div>Model: {{ deviceInfo.model }}</div>
<div>Manufacturer: {{ deviceInfo.manufacturer }}</div> <div>Manufacturer: {{ deviceInfo.manufacturer }}</div>
<div>Virtual Device: {{ deviceInfo.isVirtual ? "yes" : "no" }}</div> <div>Emulator: {{ deviceInfo.isVirtual ? "yes" : "no" }}</div>
</center> </center>
</template> </template>

View file

@ -2,7 +2,7 @@
<div class="accent"> <div class="accent">
<!-- Stock Player --> <!-- Stock Player -->
<videoPlayer :vidSrc="vidSrc" /> <videoPlayer :vid-src="vidSrc" />
<!-- VueTube Player V1 --> <!-- VueTube Player V1 -->
<!-- <VTPlayerV1 :sources="sources" v-if="sources.length > 0" />--> <!-- <VTPlayerV1 :sources="sources" v-if="sources.length > 0" />-->
@ -60,7 +60,7 @@
<p>Channel Stuff</p> <p>Channel Stuff</p>
</v-card-text> </v-card-text>
<div v-if="showMore" class="scroll-y ml-2 mr-2"> <div v-if="showMore" class="scroll-y ml-2 mr-2">
<slim-video-description-renderer :render="description"> <slim-video-description-renderer :render="description" />
</div> </div>
<!-- <v-bottom-sheet <!-- <v-bottom-sheet
@ -91,18 +91,11 @@
</div> </div>
</template> </template>
<style>
.vertical-button span.v-btn__content {
flex-direction: column;
justify-content: space-around;
}
</style>
<script> <script>
import { Share } from "@capacitor/share"; import { Share } from "@capacitor/share";
import ShelfRenderer from "~/components/SectionRenderers/shelfRenderer.vue"; import ShelfRenderer from "~/components/SectionRenderers/shelfRenderer.vue";
import VidLoadRenderer from "~/components/vidLoadRenderer.vue"; import VidLoadRenderer from "~/components/vidLoadRenderer.vue";
import SlimVideoDescriptionRenderer from '../components/UtilRenderers/slimVideoDescriptionRenderer.vue'; import SlimVideoDescriptionRenderer from '~/components/UtilRenderers/slimVideoDescriptionRenderer.vue';
export default { export default {
components: { ShelfRenderer, VidLoadRenderer, SlimVideoDescriptionRenderer }, components: { ShelfRenderer, VidLoadRenderer, SlimVideoDescriptionRenderer },
@ -184,10 +177,10 @@ export default {
//--- Content Stuff ---// //--- Content Stuff ---//
this.title = result.title; this.title = result.title;
this.description = result.renderedData.description; // While this works, I do recommend using the rendered description instead in the future as there are some things a pure string wouldn't work with this.description = result.renderedData.description; // While this works, I do recommend using the rendered description instead in the future as there are some things a pure string wouldn't work with
this.views = result.metadata.viewCount.toLocaleString(); this.views = parseInt(result.metadata.viewCount).toLocaleString();
this.likes = result.metadata.likes.toLocaleString(); this.likes = result.metadata.likes.toLocaleString();
this.uploaded = result.metadata.uploadDate; this.uploaded = result.metadata.uploadDate;
this.interactions[0].value = result.metadata.likes; this.interactions[0].value = result.metadata.likes.toLocaleString();
this.loaded = true; this.loaded = true;
this.recommends = result.renderedData.recommendations; this.recommends = result.renderedData.recommendations;
@ -218,3 +211,10 @@ export default {
}, },
}; };
</script> </script>
<style>
.vertical-button span.v-btn__content {
flex-direction: column;
justify-content: space-around;
}
</style>

View file

@ -1,13 +1,13 @@
<template> <template>
<div class="accent"> <div class="accent">
<VTPlayerV1 :sources="sources" v-if="sources.length > 0" /> <player :sources="sources" v-if="sources.length > 0" />
</div> </div>
</template> </template>
<script> <script>
import player from "~/components/Player/index.vue"
export default { export default {
data() { data() {
return { return {

View file

@ -95,6 +95,42 @@ class Innertube {
}; };
} }
async getContinuationsAsync(continuation, type) {
let data = { context: this.context, continuation: continuation };
let url
switch (type) {
case "browse":
url = `${constants.URLS.YT_BASE_API}/browse?key=${this.key}`;
break
case "search":
url = `${constants.URLS.YT_BASE_API}/search?key=${this.key}`;
break
case "next":
url = `${constants.URLS.YT_BASE_API}/next?key=${this.key}`;
break
default:
throw ("Invalid type")
}
const response = await Http.post({
url: url,
data: data,
headers: { "Content-Type": "application/json" },
}).catch((error) => error);
if (response instanceof Error) {
return {
success: false,
status_code: response.status,
message: response.message,
};
}
return {
success: true,
status_code: response.status,
data: response.data,
};
}
async getVidAsync(id) { async getVidAsync(id) {
let data = { context: this.context, videoId: id }; let data = { context: this.context, videoId: id };
const responseNext = await Http.post({ const responseNext = await Http.post({
@ -198,11 +234,9 @@ class Innertube {
response.data.output?.playabilityStatus?.status == ("ERROR" || undefined) response.data.output?.playabilityStatus?.status == ("ERROR" || undefined)
) )
throw new Error( throw new Error(
`Could not get information for video: ${ `Could not get information for video: ${response.status_code ||
response.status_code ||
response.data.output?.playabilityStatus?.status response.data.output?.playabilityStatus?.status
} - ${ } - ${response.message || response.data.output?.playabilityStatus?.reason
response.message || response.data.output?.playabilityStatus?.reason
}` }`
); );
const responseInfo = response.data.output; const responseInfo = response.data.output;

View file

@ -107,6 +107,8 @@ const innertubeModule = {
// Front page recommendation // Front page recommendation
async recommend() { async recommend() {
const response = await InnertubeAPI.getRecommendationsAsync(); const response = await InnertubeAPI.getRecommendationsAsync();
if (!response.success) if (!response.success)
throw new Error("An error occurred and innertube failed to respond"); throw new Error("An error occurred and innertube failed to respond");
@ -118,8 +120,28 @@ const innertubeModule = {
if (video) return video; if (video) return video;
}); });
console.log(final); const continuations = response.data.contents.singleColumnBrowseResultsRenderer.tabs[0]
return final; .tabRenderer.content.sectionListRenderer.continuations
console.log({ continuations: continuations, contents: final });
return { continuations: continuations, contents: final };
},
async recommendContinuation(response) {
const contents = response.continuationContents.sectionListContinuation.contents;
const final = contents.map((shelves) => {
const video = shelves.shelfRenderer?.content?.horizontalListRenderer;
if (video) return video;
});
const continuations = response.continuationContents.sectionListContinuation.continuations
return { continuations: continuations, contents: final };
},
async continuation(continuation, endpoint) {
const response = await InnertubeAPI.getContinuationsAsync(continuation, endpoint);
console.log(response)
if (!response.success) throw new Error("An error occurred and innertube failed to respond");
return response
}, },
async search(query) { async search(query) {