Skip to content

YuantongL/YTokeBackend

Repository files navigation

YToke-backend

This is the dedicated backend for the YToke~ app.

Introduction

This is basically a Maven Java app hosted on Google App Engine, you can clone this and run/debug on your local computer. This backend serves the YToke~ client MacOS app, providing API for search video, report video tag and video impressions. A noSQL database hosted on Google Cloud Firestore is used to save the video statistics.

Some sample request includes:

GET  https://ytokebackend.appspot.com/videos?q=[VideoName]&page=3
POST https://ytokebackend.appspot.com/video/stats/tag
POST https://ytokebackend.appspot.com/video/stats/impression

When a client asks the backend for videos, it asks the Invidious API (will be closed on October 1st, we will have to switch to something else) for Youtube video search, and then query the database for video statistics, it then combine those results and return to the client.

Run and debug locally

Since this is a Maven Java application, to run the application locally, use the Maven App Engine plugin.

I personally use Eclipse SDE for local development, relative tutorials include: Creating an App Engine Standard Application Deploying App Engine Standard Applications from Eclipse

You also have to use Google Cloud datastore emulator for a local database by running:

gcloud beta emulators datastore start

A few environment variables needs to be set in the project settings to point to local database, this is an example of what I use

DATASTORE_DATASET=ytokebackend
DATASTORE_EMULATOR_HOST=localhost:8081
DATASTORE_EMULATOR_HOST_PATH=localhost:8081/datastore
DATASTORE_HOST=http://localhost:8081
DATASTORE_PROJECT_ID=ytokebackend
DATASTORE_USE_PROJECT_ID_AS_APP_ID=true
GOOGLE_CLOUD_PROJECT=ytokebackend

You can view the app at localhost:8080.

You can also use IntelliJ or other IDEs you prefer, but make sure follow the setup steps of that particular IDE on Google Cloud docs. Eventually I think I will have to switch to other IDE because Eclipse's poor performance on Mac comparing to others.

Deploying to App Engine

I will handle the deployment of this project to Google App Engine. Basically I follow standard Google App Engine doc in JAVA.

To deploy the app to App Engine, run

mvn clean appengine:deploy

After the deploy finishes, you can view your application at https://YOUR_PROJECT.appspot.com, where YOUR_PROJECT is your Google Cloud project ID. You can see the new version deployed on the App Engine section of the Google Cloud Console.

Contribute

I'm not backend expert, opinions and corrections are welcomed! Currently a "popular videos" feature is under development, feel free to contribute as you like!

Donation

Donation will be used to pay for the costs generated by Google App Engine (for hosting the backend). Thank you for supporting this project!

Donate

License

YToke-backend is a open source app. The software is under the terms of the GNU General Public License V3.

GNU GPLv3 Image