Fixed Folder upload to Team Drives
This commit is contained in:
commit
8a516024cb
|
|
@ -10,6 +10,8 @@ This project is heavily inspired from @out386 's telegram bot which is written i
|
|||
- Upload progress
|
||||
- Download/upload speeds and ETAs
|
||||
- Docker support
|
||||
- Uploading To Team Drives.
|
||||
- Index Link support
|
||||
|
||||
# Upcoming features (TODOs):
|
||||
- Mega link mirror support
|
||||
|
|
@ -51,6 +53,7 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
|
|||
- DOWNLOAD_STATUS_UPDATE_INTERVAL : A short interval of time in seconds after which the Mirror progress message is updated. (I recommend to keep it 5 seconds at least)
|
||||
- OWNER_ID : The Telegram user ID (not username) of the owner of the bot
|
||||
- AUTO_DELETE_MESSAGE_DURATION : Interval of time (in seconds), after which the bot deletes it's message (and command message) which is expected to be viewed instantly. Note: Set to -1 to never automatically delete messages
|
||||
- IS_TEAM_DRIVE : (Optional field) Set to "True" if GDRIVE_FOLDER_ID is from a Team Drive else False or Leave it empty.
|
||||
- INDEX_URL : (Optional field) Refer to https://github.com/maple3142/GDIndex/ The URL should not have any trailing '/'
|
||||
|
||||
Note: You can limit maximum concurrent downloads by changing the value of MAX_CONCURRENT_DOWNLOADS in aria.sh. By default, it's set to 2
|
||||
|
|
|
|||
|
|
@ -76,7 +76,11 @@ try:
|
|||
INDEX_URL = getConfig('INDEX_URL')
|
||||
except KeyError:
|
||||
INDEX_URL = None
|
||||
|
||||
try:
|
||||
IS_TEAM_DRIVE = getConfig('IS_TEAM_DRIVE')
|
||||
except KeyError:
|
||||
IS_TEAM_DRIVE = False
|
||||
|
||||
updater = tg.Updater(token=BOT_TOKEN)
|
||||
bot = updater.bot
|
||||
dispatcher = updater.dispatcher
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ def get_readable_message():
|
|||
msg += f"<i>{download.name()}</i> - "
|
||||
msg += download.status()
|
||||
if download.status() != MirrorStatus.STATUS_ARCHIVING:
|
||||
msg += f"<code>{get_progress_bar_string(download)} {download.progress()}</code> of " \
|
||||
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code> of " \
|
||||
f"{download.size()}" \
|
||||
f" at {download.speed()}ps, ETA: {download.eta()}\n\n"
|
||||
return msg
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from google.auth.transport.requests import Request
|
|||
from googleapiclient.http import MediaFileUpload
|
||||
import pickle
|
||||
import os
|
||||
from bot import LOGGER, parent_id, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL
|
||||
from bot import LOGGER, parent_id, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, IS_TEAM_DRIVE
|
||||
from bot.helper.ext_utils.fs_utils import get_mime_type
|
||||
from bot.helper.ext_utils.bot_utils import *
|
||||
|
||||
|
|
@ -95,7 +95,8 @@ class GoogleDriveHelper:
|
|||
resumable=False)
|
||||
response = self.__service.files().create(supportsTeamDrives=True,
|
||||
body=file_metadata, media_body=media_body).execute()
|
||||
self.__set_permission(response['id'])
|
||||
if not IS_TEAM_DRIVE:
|
||||
self.__set_permission(response['id'])
|
||||
drive_file = self.__service.files().get(fileId=response['id']).execute()
|
||||
download_url = self.__G_DRIVE_BASE_DOWNLOAD_URL.format(drive_file.get('id'))
|
||||
return download_url
|
||||
|
|
@ -114,7 +115,8 @@ class GoogleDriveHelper:
|
|||
self.status, response = drive_file.next_chunk()
|
||||
self._file_uploaded_bytes = 0
|
||||
# Insert new permissions
|
||||
self.__set_permission(response['id'])
|
||||
if not IS_TEAM_DRIVE:
|
||||
self.__set_permission(response['id'])
|
||||
# Define file instance and get url for download
|
||||
drive_file = self.__service.files().get(supportsTeamDrives=True, fileId=response['id']).execute()
|
||||
download_url = self.__G_DRIVE_BASE_DOWNLOAD_URL.format(drive_file.get('id'))
|
||||
|
|
@ -172,7 +174,8 @@ class GoogleDriveHelper:
|
|||
file_metadata["parents"] = [parent_id]
|
||||
file = self.__service.files().create(supportsTeamDrives=True, body=file_metadata).execute()
|
||||
file_id = file.get("id")
|
||||
self.__set_permission(file_id)
|
||||
if not IS_TEAM_DRIVE:
|
||||
self.__set_permission(file_id)
|
||||
LOGGER.info("Created Google-Drive Folder:\nName: {}\nID: {} ".format(file.get("name"), file_id))
|
||||
return file_id
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,11 @@ class MirrorListener(listeners.MirrorListeners):
|
|||
share_url = f'{INDEX_URL}/{download_dict[self.uid].name()}'
|
||||
share_url = share_url.replace(' ', '%20')
|
||||
if INDEX_URL is not None:
|
||||
<<<<<<< HEAD
|
||||
msg += f'\n\n Shareable link: <a href="{share_url}/">here</a>'
|
||||
=======
|
||||
msg += f'\n\n Shareable link: <a href="{share_url}">here</a>'
|
||||
>>>>>>> b31a39f11ab17c9d64721e6db23821d54c76e496
|
||||
|
||||
if len(download_dict) == 0:
|
||||
self.clean()
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ OWNER_ID =
|
|||
DOWNLOAD_DIR = "/home/username/mirror-bot/downloads"
|
||||
DOWNLOAD_STATUS_UPDATE_INTERVAL = 5
|
||||
AUTO_DELETE_MESSAGE_DURATION = 20
|
||||
INDEX_URL = ""
|
||||
IS_TEAM_DRIVE = ""
|
||||
INDEX_URL = ""
|
||||
|
|
|
|||
Loading…
Reference in New Issue