Skip to content

Commit

Permalink
deploy via script
Browse files Browse the repository at this point in the history
  • Loading branch information
kaangiray26 committed Jun 30, 2023
1 parent d47ac47 commit 3657b46
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 24 deletions.
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
implementation project(':capacitor-app')
implementation project(':capacitor-browser')
implementation project(':capacitor-filesystem')
implementation project(':capacitor-share')

}
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
<!-- Permissions -->

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/
include ':capacitor-browser'
project(':capacitor-browser').projectDir = new File('../node_modules/@capacitor/browser/android')

include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacitor/filesystem/android')

include ':capacitor-share'
project(':capacitor-share').projectDir = new File('../node_modules/@capacitor/share/android')
2 changes: 1 addition & 1 deletion docs/min/youtube-trending.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 40 additions & 20 deletions extractors/youtube-trending.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
const extractor = () => {
async function get_posts(page = 1, request = null, args = null) {
return await fetch("https://m.youtube.com/feed/trending", {
if (page == 1) {
return await fetch("https://m.youtube.com/feed/trending", {
headers: {
UserAgent: "Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36"
}
})
.then(response => response.text())
.then(str => new DOMParser().parseFromString(str, "text/html"))
.then(dom => [...dom.querySelectorAll("script")])
.then(scripts => scripts.filter(script => script.text.startsWith('var ytInitialData')).pop())
.then(script => JSON.parse(new Function(script.innerHTML + "return ytInitialData")()))
.then(data => data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents.slice(0, -1))
.then(items => items.map(item => item.itemSectionRenderer.contents[0]))
.then(items => items.filter(item => item.videoWithContextRenderer))
.then(items => items.map(item => ({
title: item.videoWithContextRenderer.headline.runs[0].text,
author: item.videoWithContextRenderer.shortBylineText.runs[0].text,
url: "https://m.youtube.com/watch?v=" + item.videoWithContextRenderer.navigationEndpoint.watchEndpoint.videoId,
id: item.videoWithContextRenderer.navigationEndpoint.watchEndpoint.videoId,
dt: null,
image: item.videoWithContextRenderer.thumbnail.thumbnails.slice(-1)[0].url,
page: "/discover/youtube/" + item.videoWithContextRenderer.navigationEndpoint.watchEndpoint.videoId,
})))
}

return await fetch("https://m.youtube.com/youtubei/v1/browse?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8&prettyPrint=false", {
method: "POST",
headers: {
UserAgent: "Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36"
}
UserAgent: "Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36",
"X-Goog-EOM-Visitor-Id": ""
},
body: JSON.stringify({
context: {
client: {
clientName: "MWEB",
clientVersion: "2.20230627.03.00"
}
},
continuation: "4qmFsgKbAhIKRkV0cmVuZGluZxr0AUNCQjZzZ0ZIU1RKNk5EWkVialpRT0VOTloyOUpkRFZsU2w5ZlNFcHBOekE1VjIxWlMxcEJiMXBsV0ZKbVkwZEdibHBXT1hwaWJVWjNZekpvZG1SR09YbGFWMlJ3WWpJMWFHSkNTV1pYVkd4UFYyNXdRMVpITVcxa2VtaGFaREIwUkdWclJuUlJNVUo2WTIxU2NVMUhTalJQUjNSRFduaHZiVUZCUW14aVowRkNVa1ZWUVVGVlVrWkJRVVZCVW10V01HTnRWblZhUjJ4MVduZEJRa0ZSU1VKQlVVRkNRVUZCUWtGUlJEWnVUV1U1UTFGSlNVVkKaAhVicm93c2UtZmVlZEZFdHJlbmRpbmc%3D"
})
})
.then(response => response.text())
.then(str => new DOMParser().parseFromString(str, "text/html"))
.then(dom => [...dom.querySelectorAll("script")])
.then(scripts => scripts.filter(script => script.text.startsWith('var ytInitialData')).pop())
.then(script => JSON.parse(new Function(script.innerHTML + "return ytInitialData")()))
.then(data => data.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents.slice(0, -1))
.then(items => items.map(item => item.itemSectionRenderer.contents[0]))
.then(items => items.filter(item => item.videoWithContextRenderer))
.then(items => items.map(item => ({
title: item.videoWithContextRenderer.headline.runs[0].text,
author: item.videoWithContextRenderer.shortBylineText.runs[0].text,
url: "https://m.youtube.com/watch?v=" + item.videoWithContextRenderer.navigationEndpoint.watchEndpoint.videoId,
id: item.videoWithContextRenderer.navigationEndpoint.watchEndpoint.videoId,
dt: null,
image: item.videoWithContextRenderer.thumbnail.thumbnails.slice(-1)[0].url,
page: "/discover/youtube/" + item.videoWithContextRenderer.navigationEndpoint.watchEndpoint.videoId,
})))
.then(res => res.json())
}

async function get_post(id, request = null, args = null) {
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@capacitor/app": "^5.0.3",
"@capacitor/browser": "^5.0.3",
"@capacitor/core": "^5.0.5",
"@capacitor/filesystem": "^5.0.5",
"@capacitor/share": "^5.0.4",
"@popperjs/core": "^2.11.8",
"@vueuse/core": "^10.2.0",
Expand All @@ -28,4 +29,4 @@
"terser": "^5.18.2",
"vite": "^4.3.9"
}
}
}
4 changes: 4 additions & 0 deletions src/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ textarea {
visibility: hidden;
}

.circle {
border-radius: 50%;
}

@keyframes loading {
0% {
width: 25%;
Expand Down
133 changes: 133 additions & 0 deletions src/components/Backup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<template>
<div class="card border-0">
<div class="card-body p-3">
<div class="d-flex flex-column rounded theme-shadow">
<h6 class="fw-bold m-0 px-3 pt-3">Backup Utility</h6>
<div class="d-flex flex-column p-3">
<div class="d-flex justify-content-between">
<button type="button" class="btn btn-dark text-light p-2 flex-fill me-1" @click="save_backup">Export
backup</button>
<button type="button" class="btn btn-dark text-light p-2 flex-fill ms-1"
@click="prompt_backup">Import
backup</button>
</div>
</div>
<div v-if="img_visible">
<div class="d-flex flex-column p-3 pt-0">
<span class="text-muted mb-2">Save this image to your device.</span>
<div class="d-flex square">
<img :src="img_src" class="img-post rounded theme-shadow" @contextmenu="save_image">
</div>
</div>
</div>
<input type="file" id="upload" @change="load_backup" hidden>
<div v-if="message_visible" class="p-3 pt-0">
<div class="bg-light border rounded p-3">
<span class="fw-bold text-muted">Backup imported successfully!</span>
</div>
</div>
</div>
</div>
</div>
</template>

<script setup>
import { onActivated, ref } from 'vue';
import { Filesystem, Directory } from '@capacitor/filesystem';
import { Share } from '@capacitor/share';
const pos = 9424;
const img_src = ref(null);
const img_visible = ref(false);
const message_visible = ref(false);
async function save_image() {
let photo = await Filesystem.writeFile({
path: `endless_backup_${Date.now()}.png`,
data: img_src.value,
directory: Directory.External,
});
await Share.share({
url: photo.uri,
});
}
async function save_backup() {
img_visible.value = false;
message_visible.value = false;
// Prepare our data
let upvoted = JSON.parse(localStorage.getItem("upvoted"));
let commented = JSON.parse(localStorage.getItem("commented"));
let data = JSON.stringify({
upvoted: upvoted,
commented: commented,
});
// Convert data into Uint8Array
let b_data = new TextEncoder().encode(data);
// Read sample png file
let b_sample = await fetch("/images/bitmap.png")
.then(res => res.blob())
.then(blob => blob.arrayBuffer())
.then(buffer => new Uint8Array(buffer))
.catch(err => null);
// Combine sample, magic numbers and our data
let combined = new Uint8Array(b_sample.length + b_data.length);
combined.set(b_sample);
combined.set(b_data, b_sample.length);
// Convert to blob
let blob = new Blob([combined], { type: "image/png" });
// Convert to base64
let reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => {
img_src.value = reader.result;
img_visible.value = true;
}
}
async function prompt_backup() {
img_visible.value = false;
message_visible.value = false;
document.getElementById("upload").click();
}
async function load_backup(obj) {
// Get file
let file = obj.target.files[0];
if (!file) return;
// Read file as array buffer
let buffer = await file.arrayBuffer();
let arr = new Uint8Array(buffer);
// Get our data after position
let data = arr.slice(pos);
// Convert to string
let str = new TextDecoder().decode(data);
// Parse data
let parsed = JSON.parse(str);
// Save data
localStorage.setItem("upvoted", JSON.stringify(parsed.upvoted));
localStorage.setItem("commented", JSON.stringify(parsed.commented));
// Show message
message_visible.value = true;
}
onActivated(() => {
img_visible.value = false;
message_visible.value = false;
})
</script>
16 changes: 14 additions & 2 deletions src/components/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
<div class="input-group mt-2">
<span class="input-group-text" :class="{ 'bi bi-circle': !reloaded, 'bi bi-circle-fill': reloaded }"
id="basic-addon2"></span>
<button type="button" class="btn btn-touch-border click-effect" @click="reload_extractors">Reload
<button type="button" class="btn btn-touch-border click-effect flex-fill text-start"
@click="reload_extractors">Reload
extractors</button>
</div>
<div class="input-group mt-2">
<span class="input-group-text bi bi-save" id="basic-addon2"></span>
<button type="button" class="btn btn-touch-border click-effect flex-fill text-start"
@click="goto_backup">Backup</button>
</div>
<div class="d-flex justify-content-evenly align-items-center mt-3">
<router-link to="/profile/saved" class="btn btn-touch click-effect"
:class="{ 'bg-dark text-light': path == '/profile/saved' }">Saved</router-link>
Expand All @@ -39,7 +45,9 @@ const path = computed(() => router.currentRoute.value.path);
const reloading = ref(false);
const reloaded = ref(false);
async function reload_extractors(obj) {
const position = ref(0);
async function reload_extractors() {
if (reloading.value) return;
reloading.value = true;
Expand All @@ -58,6 +66,10 @@ async function reload_extractors(obj) {
reloaded.value = true;
}
async function goto_backup() {
router.push("/backup")
}
async function change_server(obj) {
if (!obj.target.value.length) return;
localStorage.setItem('server', JSON.stringify(obj.target.value));
Expand Down
Binary file added src/public/images/bitmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router';

import Home from "/components/Home.vue"
import Discover from "/components/Discover.vue"
import Backup from "/components/Backup.vue"

import Feed from "/pages/Feed.vue"
import Post from "/pages/Post.vue"
Expand Down Expand Up @@ -50,6 +51,10 @@ const routes = [
component: ProfileCommented
}
]
},
{
path: "/backup",
component: Backup
}
];

Expand Down

0 comments on commit 3657b46

Please sign in to comment.