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>
<div class="description" style="white-space: pre-line">
<div class="description">
<template v-for="(text, index) in render.description.runs">
<template
v-if="
@ -7,19 +7,15 @@
"
>
<a
@click="
openExternal(this.$rendererUtils.getNavigationEndpoints(text))
"
@click="openExternal($rendererUtils.getNavigationEndpoints(text))"
:key="index"
class="link"
>{{ text.text }}</a
>
</template>
<template v-else-if="this.$rendererUtils.checkInternal(text)">
<template v-else-if="$rendererUtils.checkInternal(text)">
<a
@click="
openInternal(this.$rendererUtils.getNavigationEndpoints(text))
"
@click="openInternal($rendererUtils.getNavigationEndpoints(text))"
:key="index"
class="link"
>{{ text.text }}</a
@ -30,7 +26,12 @@
</div>
</template>
<style scoped></style>
<style scoped>
.description {
white-space: pre-line;
margin-bottom: 16px;
}
</style>
<script>
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: {
refreshRecommendations() {
this.$emit("scroll-to-top");
const continuations = this.$store.state.recommendedVideos.continuations;
this.$store.commit("updateRecommendedVideos", []);
this.$youtube
.recommend()
.continuation(
continuations[1].reloadContinuationData.continuation,
"browse"
)
.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));
},

View File

@ -7,8 +7,8 @@
<div>
<!-- Video Loading Animation -->
<vid-load-renderer v-if="!recommends" />
<horizontal-list-renderer v-else :render="recommends" />
<vid-load-renderer v-if="!recommends.contents" />
<horizontal-list-renderer v-else :render="recommends.contents[0]" />
</div>
</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() {
if (!this.recommends.items || !this.recommends.items.length) {
this.$youtube
.recommend()
.then((result) => {
if (result) this.recommends = result[0];
if (result) this.recommends = result;
})
.catch((error) => this.$logger("Home Page", error, true));
}

View File

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

View File

@ -2,7 +2,7 @@
<div class="accent">
<!-- Stock Player -->
<videoPlayer :vidSrc="vidSrc" />
<videoPlayer :vid-src="vidSrc" />
<!-- VueTube Player V1 -->
<!-- <VTPlayerV1 :sources="sources" v-if="sources.length > 0" />-->
@ -60,7 +60,7 @@
<p>Channel Stuff</p>
</v-card-text>
<div v-if="showMore" class="scroll-y ml-2 mr-2">
<slim-video-description-renderer :render="description">
<slim-video-description-renderer :render="description" />
</div>
<!-- <v-bottom-sheet
@ -91,18 +91,11 @@
</div>
</template>
<style>
.vertical-button span.v-btn__content {
flex-direction: column;
justify-content: space-around;
}
</style>
<script>
import { Share } from "@capacitor/share";
import ShelfRenderer from "~/components/SectionRenderers/shelfRenderer.vue";
import VidLoadRenderer from "~/components/vidLoadRenderer.vue";
import SlimVideoDescriptionRenderer from '../components/UtilRenderers/slimVideoDescriptionRenderer.vue';
import SlimVideoDescriptionRenderer from '~/components/UtilRenderers/slimVideoDescriptionRenderer.vue';
export default {
components: { ShelfRenderer, VidLoadRenderer, SlimVideoDescriptionRenderer },
@ -180,14 +173,14 @@ export default {
result.availableResolutions[
result.availableResolutions.length - 1
].url; // Takes the highest available resolution with both video and Audio. Note this will be lower than the actual highest resolution
//--- Content Stuff ---//
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.views = result.metadata.viewCount.toLocaleString();
this.views = parseInt(result.metadata.viewCount).toLocaleString();
this.likes = result.metadata.likes.toLocaleString();
this.uploaded = result.metadata.uploadDate;
this.interactions[0].value = result.metadata.likes;
this.interactions[0].value = result.metadata.likes.toLocaleString();
this.loaded = true;
this.recommends = result.renderedData.recommendations;
@ -218,3 +211,10 @@ export default {
},
};
</script>
<style>
.vertical-button span.v-btn__content {
flex-direction: column;
justify-content: space-around;
}
</style>

View File

@ -1,13 +1,13 @@
<template>
<div class="accent">
<VTPlayerV1 :sources="sources" v-if="sources.length > 0" />
<player :sources="sources" v-if="sources.length > 0" />
</div>
</template>
<script>
import player from "~/components/Player/index.vue"
export default {
data() {
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) {
let data = { context: this.context, videoId: id };
const responseNext = await Http.post({
@ -198,11 +234,9 @@ class Innertube {
response.data.output?.playabilityStatus?.status == ("ERROR" || undefined)
)
throw new Error(
`Could not get information for video: ${
response.status_code ||
response.data.output?.playabilityStatus?.status
} - ${
response.message || response.data.output?.playabilityStatus?.reason
`Could not get information for video: ${response.status_code ||
response.data.output?.playabilityStatus?.status
} - ${response.message || response.data.output?.playabilityStatus?.reason
}`
);
const responseInfo = response.data.output;

View File

@ -107,6 +107,8 @@ const innertubeModule = {
// Front page recommendation
async recommend() {
const response = await InnertubeAPI.getRecommendationsAsync();
if (!response.success)
throw new Error("An error occurred and innertube failed to respond");
@ -118,8 +120,28 @@ const innertubeModule = {
if (video) return video;
});
console.log(final);
return final;
const continuations = response.data.contents.singleColumnBrowseResultsRenderer.tabs[0]
.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) {