diff --git a/docs/stremio/addons/stremio-gdrive.mdx b/docs/stremio/addons/stremio-gdrive.mdx index f6a6ab0..6d9662b 100644 --- a/docs/stremio/addons/stremio-gdrive.mdx +++ b/docs/stremio/addons/stremio-gdrive.mdx @@ -1,14 +1,19 @@ --- -title: Stremio Gdrive +title: Stremio GDrive description: Stremio addon for fetching videos from your google drive. keywords: [stremio, addons, http, google drive, guide, setup, configuration, install, link] tags: [stremio-addon, stremio-addon:http-streams] +toc_max_heading_level: 2 --- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import Details from '@theme/Details'; + ```mdx-code-block import StremioAddonButtons from '@site/src/components/StremioAddonButtons'; - + ```

Description

@@ -18,8 +23,193 @@ Stremio-gdrive is a self-hosted Stremio addon that allows you to view files from For it to work, you will need to join some team drives. You can find some [here](https://t.me/s/teamdrives).

Configuration

+ +I will go through the steps to set up this addon through a Cloudflare Worker. -As mentioned earlier, this addon needs to be self-hosted. +:::tip +**This guide should be followed on its [dedicated page](/stremio/addons/stremio-gdrive), not from the setup page.** + +::: + +

Setting up our Google App

+ +1. Go to the [Google Cloud Console](https://console.cloud.google.com/). + + If this is your first time using Google Cloud, you will be prompted to agree to the terms of service: + + ![Google Cloud Console](/img/stremio/gdrive/google_cloud_onboarding.png) + +2. Create a new project and select it: + +
+ 1. Click on `Select a project` in the top left: + + ![Create a new project](/img/stremio/gdrive/google_cloud_create_project_1.png) + + 2. Click on `New Project`: + + ![Create a new project](/img/stremio/gdrive/google_cloud_create_project_2.png) + + 3. Enter a project name and click on `Create`: + + ![Create a new project](/img/stremio/gdrive/google_cloud_create_project_3.png) + + - The project name can be anything you want, e.g., `Stremio-Gdrive`. Leave the `Organization` field blank. + + 4. Once the project has been created, you will get a notification: + + ![Create a new project](/img/stremio/gdrive/google_cloud_create_project_4.png) + + - Click `Select Project`. + + :::note + You may also use the same dropdown from step i to select the project. + ::: +
+3. Setup our Google Auth Platform + + 1. Go to the [Google Cloud Console](https://console.cloud.google.com/). + 2. In the search bar at the top, search for `Google Auth Platform` and click on the result: + + ![Google OAuth Platform](/img/stremio/gdrive/google_cloud_oauth_search_results.png) + + 3. You should be met with a message telling you that `Google Auth Platform not configured yet`, click on `Get Started`: + + ![Google OAuth Platform](/img/stremio/gdrive/google_auth_platform_0.png) + + 4. Fill in the form: + + ![Google OAuth Platform](/img/stremio/gdrive/google_auth_platform_1.png) + + 1. `App Information`: + - Set `App Name` to `Stremio GDrive`. + - Set `User Support Email` to your email. It should appear in the dropdown. + 2. `Audience`: + - Set `User Type` to `External`. + 3. `Contact Information` + - Add any email address, you can use the same one you used earlier for `User Support Email`. + 4. `Finish` + - Check the box to agree to the `Google API Services: User Data Policy` + + + 5. Once you have filled in the form, click on `Create` + +4. Enable the Google Drive API. + + 1. Go to the [Google Cloud Console](https://console.cloud.google.com/). + 2. In the search bar at the top, search for `Google Drive API` and click on the result: + + ![Google Drive API](/img/stremio/gdrive/google_cloud_gdrive_api_search_results.png) + + 3. Click on `Enable`: + + ![Google Drive API](/img/stremio/gdrive/google_cloud_gdrive_api.png) + +5. Create an OAuth client. + + 1. Go back to the `Google Auth Platform` page. + 2. Click on `Clients` in the sidebar and then click on `+ Create Client`: + + ![Google OAuth Platform](/img/stremio/gdrive/google_cloud_auth_platform_clients.png) + + 3. Fill in the form: + + ![Google OAuth Platform](/img/stremio/gdrive/google_cloud_auth_platform_clients_form.png) + + - `Application Type`: Set this to `Desktop app`. + - `Name`: You can set this to anything such as `Stremio GDrive`. + + + 4. Click on `Create`. + +6. Publish the app. + + 1. Go back to the `Google Auth Platform` page. + 2. Click on `Audience` in the sidebar and then click on `Publish`: + + ![Google OAuth Platform](/img/stremio/gdrive/google_cloud_auth_platform_publish.png) + + +

Setting up the Cloudflare Worker

+ +1. Go to the [Cloudflare Workers](https://workers.cloudflare.com/) page and click `Log In` or `Sign Up` if you don't have an account. + +2. Once logged in, you should be taken to the Cloudflare Workers & Pages dashboard. Click on `Create`: + + ![Cloudflare Workers](/img/stremio/gdrive/cloudflare_workers_pages_overview.png) + +3. Once on the create page, make sure you're on the `Workers` tab and click `Create Worker`: + + ![Cloudflare Workers](/img/stremio/gdrive/cloudflare_create_an_application_workers.png) + +4. You'll be asked to give a name to your worker. You can name it anything, this will be the URL you enter into Stremio to access your addon. Click `Deploy` once named. + + ![Cloudflare Workers](/img/stremio/gdrive/cloudflare_create_a_worker.png) + +5. Once its done being deployed, you should be shown a success message. Click the `Edit code` button: + + ![Cloudflare Workers](/img/stremio/gdrive/cloudflare_create_a_worker_success.png) + +6. You should be taken to the Cloudflare Worker editor: + + ![Cloudflare Workers](/img/stremio/gdrive/cloudflare_worker_editor.png) + +7. Now, we will paste the Cloudflare Worker script from the [Stremio GDrive GitHub](https://github.com/Viren070/stremio-gdrive) into the editor. + + 1. Go to the [worker.js file](https://github.com/Viren070/stremio-gdrive-addon/blob/main/worker.js) + 2. Click the Copy icon + 3. Go back to the Cloudflare Worker editor and paste the script in the editor. + + + + +8. Now, we need to add our Google OAuth credentials to the script. + + To do this, we need to go back to the Google Cloud Console and get our `Client ID` and `Client Secret`. + + 1. Go to the [Google Cloud Console](https://console.cloud.google.com/). + 2. In the search bar at the top, search for `Google Auth Platform` and click on the result: + + ![Google OAuth Platform](/img/stremio/gdrive/google_cloud_oauth_search_results.png) + + 3. Click on `Clients` and click on the download icon for the client you created earlier: + + ![Google OAuth Platform](/img/stremio/gdrive/google_auth_platform_clients_download.png) + + 4. A pop-up will appear with your `Client ID` and `Client Secret`. Copy these values into the inputs below at [Google OAuth Tool](#OAuth Tool). + + ![Google OAuth Platform](/img/stremio/gdrive/google_auth_platform_clients_download_menu.png) + + 5. Click the `Get Authorisation Code` button below to get the Authorisation code. + :::tip + You will be redirected to a Google OAuth page where you will need to sign in and allow the app to access your Google Drive. + You may encounter a warning page, click on `Advanced` and then `Go to... (unsafe)`. + ::: + + 6. Once you have allowed the app, you will be redirected back to this page with the Authorisation code filled in. + Click the `Get Credentials` button to get the credentials. + + 7. You will be shown a success message and a block of code will appear. Copy this code into the Cloudflare Worker script. + + 8. Once you have added your credentials, your script should look something like this: + + ![Cloudflare Workers](/img/stremio/gdrive/cloudflare_finished_worker_script.png) + +9. Click `Deploy` in the top right to save your changes and deploy the worker. + +11. Once deployed, you should see a green success message at the bottom. Click `Visit` next to the deploy button to go to the addon URL. + +12. You should be redirected to the /manifest.json. if not, append `/manifest.json` to the URL. + +13. Copy the URL and [add it to Stremio](/stremio/faq#how-do-i-install-an-addon-manually). + + + + +### OAuth Tool + +import GoogleOAuth from '@site/src/components/GoogleOAuth'; + + -You can use [this GitHub repository](https://github.com/ShuvamJaswal/Gdrive-Stremio-Update) to set it up. diff --git a/docs/stremio/addons/stremio-gdrive/callback.mdx b/docs/stremio/addons/stremio-gdrive/callback.mdx new file mode 100644 index 0000000..f9ecb20 --- /dev/null +++ b/docs/stremio/addons/stremio-gdrive/callback.mdx @@ -0,0 +1,7 @@ +import Callback from '@site/src/components/GoogleOAuth/Callback'; + + + +# Google Drive Callback + +You will automatically be redirected back to the addon guide after you have authenticated with Google. \ No newline at end of file diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 40a66ec..deffa35 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -23,7 +23,7 @@ const config: Config = { // may want to replace "en" with "zh-Hans". i18n: { defaultLocale: 'en-GB', - locales: ['en-GB', 'es'], + locales: ['en-GB'], }, future: { diff --git a/src/components/GoogleOAuth/Callback.tsx b/src/components/GoogleOAuth/Callback.tsx new file mode 100644 index 0000000..7d74f96 --- /dev/null +++ b/src/components/GoogleOAuth/Callback.tsx @@ -0,0 +1,28 @@ +// this component is used to catch responses from google OAuth. Upon load, we check if the +// Url contains the code parameter. if it does we extract the code, and open +// the /stremio/addons/stremio-gdrive/ page with the code as a query parameter. + +import React from "react"; +import useBaseUrl from "@docusaurus/useBaseUrl"; +import { sessionKeys } from "."; +import { showToast } from "../Toasts"; + +export default function Catcher(): JSX.Element { + const redirectUrl = useBaseUrl('/stremio/addons/stremio-gdrive#oauth-tool'); + React.useEffect(() => { + const url = new URL(window.location.href); + const code = url.searchParams.get("code"); + if (code) { + sessionStorage.setItem(sessionKeys.authorisationCode, code); + window.location.href = redirectUrl; + } + const error = url.searchParams.get("error"); + if (error) { + console.error("Google OAuth Error: ", error); + sessionStorage.setItem(sessionKeys.oauthError, error); + window.location.href = redirectUrl; + } + }, []); + + return <>; +} \ No newline at end of file diff --git a/src/components/GoogleOAuth/index.tsx b/src/components/GoogleOAuth/index.tsx new file mode 100644 index 0000000..49ea294 --- /dev/null +++ b/src/components/GoogleOAuth/index.tsx @@ -0,0 +1,199 @@ +import React, { useState } from "react"; +import CodeBlock from "@theme/CodeBlock"; +import { showToast } from "../Toasts"; +import './styles.css'; +import useBaseUrl from "@docusaurus/useBaseUrl"; + +const scopes = ['https://www.googleapis.com/auth/drive']; +const oauthUrl = "https://accounts.google.com/o/oauth2/v2/auth"; +const tokenUrl = "https://oauth2.googleapis.com/token"; + +export const sessionKeys = { + clientId: "Viren070Guides_OAuthTool_clientId", + clientSecret: "Viren070Guides_OAuthTool_clientSecret", + authorisationCode: "Viren070Guides_OAuthTool_authorisationCode", + oauthError: "Viren070Guides_OAuthTool_oauthError" +}; + +// Function to obtain the refresh token +const openAuthorisationUrl = (clientId: string, redirectUrl: string) => { + + if (clientId.length === 0) { + showToast("Client ID is required", "error"); + return; + } + + const url = new URL(oauthUrl); + url.searchParams.append("client_id", clientId); + url.searchParams.append("redirect_uri", redirectUrl); + url.searchParams.append("response_type", "code"); + url.searchParams.append("scope", scopes.join(" ")); + url.searchParams.append("prompt", "consent"); + + // open the url in current tab + + window.open(url.toString(), "_self"); + +}; + + + +export default function CodeGenerator(): JSX.Element { + const [clientId, setClientId] = useState(""); + const [clientSecret, setClientSecret] = useState(""); + const [authorisationCode, setAuthorisationCode] = useState(""); + const [refreshToken, setRefreshToken] = useState(""); + const [redirectUrl, setRedirectUrl] = useState(""); + + const callbackPath = useBaseUrl('/stremio/addons/stremio-gdrive/callback'); + + React.useEffect(() => { + // set the redirect url to the current page + setRedirectUrl(window.location.origin + callbackPath); + // load the stored values from session storage if they exist + + const storedClientId = sessionStorage.getItem(sessionKeys.clientId); + const storedClientSecret = sessionStorage.getItem(sessionKeys.clientSecret); + const storedAuthorisationCode = sessionStorage.getItem(sessionKeys.authorisationCode); + const storedOauthError = sessionStorage.getItem(sessionKeys.oauthError); + if (storedOauthError) { + showToast(`Google OAuth Error: ${storedOauthError}`, "error"); + sessionStorage.removeItem(sessionKeys.oauthError); + } + if (storedClientId) { + setClientId(storedClientId); + } + if (storedClientSecret) { + setClientSecret(storedClientSecret); + } + if (storedAuthorisationCode) { + setAuthorisationCode(storedAuthorisationCode); + sessionStorage.removeItem(sessionKeys.authorisationCode); + showToast("Authorisation code obtained successfully. Click `Get Credentials` to complete the process", "success"); + } + }, []); + + const handleClientIdChange = (e: React.ChangeEvent) => { + const value = e.target.value; + setClientId(value); + sessionStorage.setItem(sessionKeys.clientId, value); + // reset the authorisation code since its no longer valid with different client id + setAuthorisationCode(""); + sessionStorage.removeItem(sessionKeys.authorisationCode); + }; + + const handleClientSecretChange = (e: React.ChangeEvent) => { + const value = e.target.value; + setClientSecret(value); + sessionStorage.setItem(sessionKeys.clientSecret, value); + // reset the authorisation code since its no longer valid with different client secret + setAuthorisationCode(""); + sessionStorage.removeItem(sessionKeys.authorisationCode); + }; + + const getRefreshCode = () => { + if (!clientId || clientId.length === 0) { + showToast("Client ID is required", "error"); + return; + } + + if (!clientSecret || clientSecret.length === 0) { + showToast("Client Secret is required", "error"); + return; + } + + if (!authorisationCode || authorisationCode.length === 0) { + showToast("Authorisation Code is required", "error"); + return; + } + + const data = new URLSearchParams({ + client_id: clientId, + client_secret: clientSecret, + code: authorisationCode, + grant_type: "authorization_code", + redirect_uri: redirectUrl + }); + + const response = fetch(tokenUrl, { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded" + }, + body: data.toString() + }); + + response.then(handleResponse); + } + + const handleResponse = (res: Response) => { + if (res.ok) { + res.json().then((data) => { + showToast("Refresh token obtained successfully. Copy the code and paste it into your script.", "success"); + setRefreshToken(data.refresh_token); + // reset the authorisation code as it can no longer be used + setAuthorisationCode(""); + sessionStorage.removeItem(sessionKeys.authorisationCode); + }); + } else { + let text = res.text(); + text.then((data) => { + showToast(`Error getting the refresh token:${data}`, "error"); + }); + // reset any previously obtained refresh token + setRefreshToken(""); + } + }; + + const getCodeBlock = () => { + return ( + +{ +`var credentials = { + "client_id": "${clientId}", + "client_secret": "${clientSecret}", + "refresh_token": "${refreshToken}" +};` +} + + ); + }; + + + return ( + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + + setAuthorisationCode(e.target.value)} /> +
+
+ +
+
+ {refreshToken.length > 0 && getCodeBlock()} +
+
+

+ View the source code for this tool +

+
+ + ); +} \ No newline at end of file diff --git a/src/components/GoogleOAuth/styles.css b/src/components/GoogleOAuth/styles.css new file mode 100644 index 0000000..7fcba0c --- /dev/null +++ b/src/components/GoogleOAuth/styles.css @@ -0,0 +1,50 @@ + +.google-auth-form-container { + max-width: 600px; + margin: 0 auto; + outline: 1px solid var(--ifm-color-primary); + padding: 15px; + border-radius: var(--ifm-global-radius); +} + +.google-auth-form-container > * { + margin-top: 10px; +} + +.google-auth-form-label { + display: block; + margin-bottom: 5px; + font-weight: bold; + margin-left: 10px; +} + +.google-auth-form-input { + width: 100%; + padding: 10px; + margin-bottom: 20px; + border: 1px solid var(--ifm-color-primary); + box-sizing: border-box; +} + +.google-auth-form-input:focus { + outline: none; + border-color: var(--ifm-color-primary-darkest); + box-shadow: 0 0 5px var(--ifm-color-primary-darkest); +} + + +.google-auth-form-button { + width: 100%; + size: 16px; + font-size: 16px; + font-weight: bold; +} + +.google-auth-form-button:hover { + transform: scale(1.025); + box-shadow: 0 0 5px var(--ifm-color-primary-darkest); + border-color: 0 0 5px var(--ifm-color-primary-darkest); + outline: none; +} + + diff --git a/src/css/custom.css b/src/css/custom.css index 13f1db6..c0d129f 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -102,3 +102,35 @@ .hidden-tabs { display: none; } + + +.default-themed-button { + background: var(--ifm-color-primary); + color: white; + border: none; + padding: 15px; + cursor: pointer; + border-radius: var(--ifm-global-radius); + margin: 0 auto; + box-shadow: var(--button-box-shadow); + transition: transform 0.2s, box-shadow 0.2s, background 0.2s; +} + +.default-themed-button:disabled { + background: #ccc; + cursor: not-allowed; + box-shadow: none; +} + +.default-themed-button:disabled:hover { + transform: none; + box-shadow: none; +} + +.custom-button:hover { + transform: scale(1.05); + box-shadow: var(--button-hover-box-shadow); + color: white; +} + + diff --git a/static/img/stremio/gdrive/cloudflare_create_a_worker.png b/static/img/stremio/gdrive/cloudflare_create_a_worker.png new file mode 100644 index 0000000..815786c Binary files /dev/null and b/static/img/stremio/gdrive/cloudflare_create_a_worker.png differ diff --git a/static/img/stremio/gdrive/cloudflare_create_a_worker_success.png b/static/img/stremio/gdrive/cloudflare_create_a_worker_success.png new file mode 100644 index 0000000..ac832df Binary files /dev/null and b/static/img/stremio/gdrive/cloudflare_create_a_worker_success.png differ diff --git a/static/img/stremio/gdrive/cloudflare_create_an_application_workers.png b/static/img/stremio/gdrive/cloudflare_create_an_application_workers.png new file mode 100644 index 0000000..cd5a117 Binary files /dev/null and b/static/img/stremio/gdrive/cloudflare_create_an_application_workers.png differ diff --git a/static/img/stremio/gdrive/cloudflare_finished_worker_script.png b/static/img/stremio/gdrive/cloudflare_finished_worker_script.png new file mode 100644 index 0000000..54053b9 Binary files /dev/null and b/static/img/stremio/gdrive/cloudflare_finished_worker_script.png differ diff --git a/static/img/stremio/gdrive/cloudflare_worker_editor.png b/static/img/stremio/gdrive/cloudflare_worker_editor.png new file mode 100644 index 0000000..5a4b0ff Binary files /dev/null and b/static/img/stremio/gdrive/cloudflare_worker_editor.png differ diff --git a/static/img/stremio/gdrive/cloudflare_workers_pages_overview.png b/static/img/stremio/gdrive/cloudflare_workers_pages_overview.png new file mode 100644 index 0000000..a771488 Binary files /dev/null and b/static/img/stremio/gdrive/cloudflare_workers_pages_overview.png differ diff --git a/static/img/stremio/gdrive/google_auth_platform_0.png b/static/img/stremio/gdrive/google_auth_platform_0.png new file mode 100644 index 0000000..723fe1e Binary files /dev/null and b/static/img/stremio/gdrive/google_auth_platform_0.png differ diff --git a/static/img/stremio/gdrive/google_auth_platform_1.png b/static/img/stremio/gdrive/google_auth_platform_1.png new file mode 100644 index 0000000..12fcd4f Binary files /dev/null and b/static/img/stremio/gdrive/google_auth_platform_1.png differ diff --git a/static/img/stremio/gdrive/google_auth_platform_clients_download.png b/static/img/stremio/gdrive/google_auth_platform_clients_download.png new file mode 100644 index 0000000..221c444 Binary files /dev/null and b/static/img/stremio/gdrive/google_auth_platform_clients_download.png differ diff --git a/static/img/stremio/gdrive/google_auth_platform_clients_download_menu.png b/static/img/stremio/gdrive/google_auth_platform_clients_download_menu.png new file mode 100644 index 0000000..25f358c Binary files /dev/null and b/static/img/stremio/gdrive/google_auth_platform_clients_download_menu.png differ diff --git a/static/img/stremio/gdrive/google_cloud_auth_platform_clients.png b/static/img/stremio/gdrive/google_cloud_auth_platform_clients.png new file mode 100644 index 0000000..f0a891c Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_auth_platform_clients.png differ diff --git a/static/img/stremio/gdrive/google_cloud_auth_platform_clients_form.png b/static/img/stremio/gdrive/google_cloud_auth_platform_clients_form.png new file mode 100644 index 0000000..3f658bc Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_auth_platform_clients_form.png differ diff --git a/static/img/stremio/gdrive/google_cloud_auth_platform_publish.png b/static/img/stremio/gdrive/google_cloud_auth_platform_publish.png new file mode 100644 index 0000000..b55bf95 Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_auth_platform_publish.png differ diff --git a/static/img/stremio/gdrive/google_cloud_create_project_1.png b/static/img/stremio/gdrive/google_cloud_create_project_1.png new file mode 100644 index 0000000..bf15956 Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_create_project_1.png differ diff --git a/static/img/stremio/gdrive/google_cloud_create_project_2.png b/static/img/stremio/gdrive/google_cloud_create_project_2.png new file mode 100644 index 0000000..5bdb640 Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_create_project_2.png differ diff --git a/static/img/stremio/gdrive/google_cloud_create_project_3.png b/static/img/stremio/gdrive/google_cloud_create_project_3.png new file mode 100644 index 0000000..2742b0b Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_create_project_3.png differ diff --git a/static/img/stremio/gdrive/google_cloud_create_project_4.png b/static/img/stremio/gdrive/google_cloud_create_project_4.png new file mode 100644 index 0000000..349c86b Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_create_project_4.png differ diff --git a/static/img/stremio/gdrive/google_cloud_gdrive_api.png b/static/img/stremio/gdrive/google_cloud_gdrive_api.png new file mode 100644 index 0000000..16f2aca Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_gdrive_api.png differ diff --git a/static/img/stremio/gdrive/google_cloud_gdrive_api_search_results.png b/static/img/stremio/gdrive/google_cloud_gdrive_api_search_results.png new file mode 100644 index 0000000..9fcab1d Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_gdrive_api_search_results.png differ diff --git a/static/img/stremio/gdrive/google_cloud_oauth_search_results.png b/static/img/stremio/gdrive/google_cloud_oauth_search_results.png new file mode 100644 index 0000000..b61ac25 Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_oauth_search_results.png differ diff --git a/static/img/stremio/gdrive/google_cloud_onboarding.png b/static/img/stremio/gdrive/google_cloud_onboarding.png new file mode 100644 index 0000000..e687126 Binary files /dev/null and b/static/img/stremio/gdrive/google_cloud_onboarding.png differ