diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2026-04-05 14:18:31 -0700 |
|---|---|---|
| committer | Pinapelz <donaldshan1@outlook.com> | 2026-04-05 14:18:31 -0700 |
| commit | 68a99b3607c614bad511fbf8aa25e3d0bb8c6dc4 (patch) | |
| tree | 463f51c567eecdd4372442101e1dc0cc33091449 | |
| parent | 1e56db585cf705126deee39d956215c05f89f2ba (diff) | |
GDrive to WebDAV
| -rw-r--r-- | Google_Drive_to_WebDAV.ipynb | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/Google_Drive_to_WebDAV.ipynb b/Google_Drive_to_WebDAV.ipynb new file mode 100644 index 0000000..a1c96d5 --- /dev/null +++ b/Google_Drive_to_WebDAV.ipynb @@ -0,0 +1,163 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyO80A9f3UeM4jwCCLOxzeSw", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "<a href=\"https://colab.research.google.com/github/pinapelz/nc-media-tools/blob/main/Google_Drive_to_WebDAV.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Google Drive Video to WebDAV\n", + "This script allows for a GDrive video to be downloaded and then automatically uplaoded via WebDAV\n", + "\n", + "# What this does?\n", + "- Downloads GDrive video via yt-dlp\n", + "- Upload via WebDAV\n", + "\n", + "Optionally if you are using Nextcloud you can also automatically generate a share\n", + "\n", + "# Usage\n", + "Fill in all the fields below. Then `Run all`" + ], + "metadata": { + "id": "L9cXBP9OPmFt" + } + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "vHGZttQWK8QJ" + }, + "outputs": [], + "source": [ + "# Install the dependencies needed\n", + "!pip install webdavclient3" + ] + }, + { + "cell_type": "code", + "source": [ + "from webdav3.client import Client\n", + "webdav_url = \"\" #@param {type:\"string\"}\n", + "username = \"\" #@param {type:\"string\"}\n", + "password = \"\" #@param {type:\"string\"}\n", + "options = {\n", + " 'webdav_hostname': webdav_url,\n", + " 'webdav_login': username,\n", + " 'webdav_password': password\n", + "}\n", + "client = Client(options)\n", + "try:\n", + " client.list()\n", + " print(\"Success! Connection successful\")\n", + "except:\n", + " print(\"Login failed. Please check that your login and WebDAV url are correct\")" + ], + "metadata": { + "id": "GAdz5SlkOIJO" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "import re\n", + "import gdown\n", + "video_url = \"\" #@param{type:\"string\"}\n", + "file_id = re.search(r\"(?<=/d/)[^/]+\", video_url).group(0)\n", + "url = f\"https://drive.google.com/uc?id={file_id}\"\n", + "downloaded_file = gdown.download(url, quiet=False)\n", + "print(downloaded_file)" + ], + "metadata": { + "id": "GtiPVBYSQ1_6" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Uploads the file to the path specified\n", + "download_path = \"\" #@param{type:\"string\"}\n", + "remote_filename = f\"{download_path}/\" + downloaded_file.split(\"/\")[-1]\n", + "client.upload_sync(remote_path=remote_filename, local_path=downloaded_file)\n", + "print(f\"Done! Your file has been uploaded to {remote_filename}\")" + ], + "metadata": { + "id": "3xYJpTl5SeVz" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# OPTIONAL NEXTCLOUD AUTO SHARE\n", + "- This uses Nextcloud API to create a public share URL automatically. Completes the workflow" + ], + "metadata": { + "id": "uabtse49Vy-L" + } + }, + { + "cell_type": "code", + "source": [ + "import requests\n", + "nextcloud_url = \"\" #@param {type:\"string\"}\n", + "api_url = f\"{nextcloud_url}/ocs/v2.php/apps/files_sharing/api/v1/shares\"\n", + "payload = {\n", + " \"path\": remote_filename,\n", + " \"shareType\": 3, # 3 = public link\n", + " \"permissions\": 31 # optional, full permissions (read/write/share)\n", + "}\n", + "\n", + "headers = {\n", + " \"OCS-APIRequest\": \"true\"\n", + "}\n", + "response = requests.post(api_url, auth=(username, password), headers=headers, data=payload)\n", + "if response.status_code == 200:\n", + " import xml.etree.ElementTree as ET\n", + " root = ET.fromstring(response.content)\n", + " ns = {\"ocs\": \"http://open-collaboration-services.org/ns\"}\n", + " url_elem = root.find(\".//url\")\n", + " if url_elem is not None:\n", + " share_link = url_elem.text\n", + " print(\"Share link:\", share_link+\"/download\")\n", + " else:\n", + " print(\"Could not find share URL in response\")\n", + "else:\n", + " print(\"Error:\", response.status_code, response.text)" + ], + "metadata": { + "id": "MSmhsS6PUxaG" + }, + "execution_count": null, + "outputs": [] + } + ] +}
\ No newline at end of file |
