Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master code v5 #256

Open
wants to merge 49 commits into
base: master-code-v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
93275a7
improve
jammesop007aha Apr 29, 2024
27252f3
improve
jammesop007aha Apr 29, 2024
082db54
improve
jammesop007aha Apr 29, 2024
321ad6c
improve
jammesop007aha Apr 29, 2024
80c9173
improve
jammesop007aha Apr 29, 2024
aabf1e9
improve
jammesop007aha Apr 29, 2024
a8a8764
improve
jammesop007aha Apr 29, 2024
d45ffb5
improve
jammesop007aha Apr 29, 2024
5e18bc4
improve
jammesop007aha Apr 29, 2024
7a3ba66
improve
jammesop007aha Apr 29, 2024
57ff2a9
improve
jammesop007aha Apr 29, 2024
1c373bd
improve
jammesop007aha Apr 29, 2024
5a86da7
improve
jammesop007aha Apr 29, 2024
4b86495
improve
jammesop007aha Apr 29, 2024
74549c4
improve
jammesop007aha Apr 29, 2024
38a0bc1
improve
jammesop007aha Apr 29, 2024
30dc376
improve
jammesop007aha Apr 29, 2024
5a0ba4d
improve
jammesop007aha Apr 29, 2024
6e4b449
improve
jammesop007aha Apr 29, 2024
9302cd4
improve
jammesop007aha Apr 29, 2024
0547e01
improve
jammesop007aha Apr 29, 2024
04ed9f4
improve
jammesop007aha Apr 29, 2024
4b991c6
improve
jammesop007aha Apr 29, 2024
c50d6d8
improve
jammesop007aha Apr 29, 2024
681eb20
improve
jammesop007aha Apr 29, 2024
826943e
improve
jammesop007aha Apr 29, 2024
8153e0a
improve
jammesop007aha Apr 29, 2024
38bfa83
improve
jammesop007aha Apr 29, 2024
9d485cf
improve
jammesop007aha Apr 29, 2024
22cab76
improve
jammesop007aha Apr 29, 2024
f9b52e2
improve
jammesop007aha Apr 29, 2024
04714c6
improve
jammesop007aha Apr 29, 2024
f424f44
improve
jammesop007aha Apr 29, 2024
6bfa9c1
improve
jammesop007aha Apr 29, 2024
6c05583
improve
jammesop007aha Apr 29, 2024
31cafe0
improve
jammesop007aha Apr 29, 2024
e0f137b
improve
jammesop007aha Apr 29, 2024
3338610
improve
jammesop007aha Apr 29, 2024
c8dd846
improve
jammesop007aha Apr 29, 2024
a3ae9d0
improve
jammesop007aha Apr 29, 2024
6b7913d
improve
jammesop007aha Apr 29, 2024
8f7acab
improve
jammesop007aha Apr 29, 2024
3cc4c60
improve
jammesop007aha Apr 29, 2024
bd20b5a
improve
jammesop007aha Apr 29, 2024
86293f1
improve
jammesop007aha Apr 29, 2024
a734638
improve
jammesop007aha Apr 29, 2024
24f7fff
improve
jammesop007aha Apr 29, 2024
cfff0df
improve
jammesop007aha Apr 29, 2024
d4cff2a
improve
jammesop007aha Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
# Personal configuration files
config.env
Thumbnails/*
list_drives.txt
categories.txt
cookies.txt
terabox.txt
downloads
*auth_token.txt
*.pyc
data*
.vscode
.idea
*.json
*.pickle
.netrc
log.txt
authorized_chats.txt
sudo_users.txt
accounts/*
cookies/*

15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
FROM anasty17/mltb:latest

WORKDIR /usr/src/app
RUN chmod 777 /usr/src/app

# There's no need to give execute permissions to the entire app directory
# RUN chmod 777 /usr/src/app

COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

# It's recommended to run updates and upgrades before installing any packages
RUN apt-get update && apt-get upgrade -y
RUN apt -qq update --fix-missing && \
apt -qq install -y mediainfo

# Use apt-get install instead of apt for better error messages
RUN apt-get install -y --no-install-recommends mediainfo

# Only copy the necessary files to reduce the image size
COPY . .

CMD ["bash", "start.sh"]
# Use exec to replace the current shell with the new command
CMD ["exec", "bash", "start.sh"]
196 changes: 122 additions & 74 deletions add_to_team_drive.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,125 @@
from __future__ import print_function
from google.oauth2.service_account import Credentials
import googleapiclient.discovery, json, progress.bar, glob, sys, argparse, time
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from google.auth.transport.requests import Request
import os, pickle

stt = time.time()

parse = argparse.ArgumentParser(
description='A tool to add service accounts to a shared drive from a folder containing credential files.')
parse.add_argument('--path', '-p', default='accounts',
help='Specify an alternative path to the service accounts folder.')
parse.add_argument('--credentials', '-c', default='./credentials.json',
help='Specify the relative path for the credentials file.')
parse.add_argument('--yes', '-y', default=False, action='store_true', help='Skips the sanity prompt.')
parsereq = parse.add_argument_group('required arguments')
parsereq.add_argument('--drive-id', '-d', help='The ID of the Shared Drive.', required=True)

args = parse.parse_args()
acc_dir = args.path
did = args.drive_id
credentials = glob.glob(args.credentials)

try:
open(credentials[0], 'r')
print('>> Found credentials.')
except IndexError:
print('>> No credentials found.')
sys.exit(0)

if not args.yes:
# input('Make sure the following client id is added to the shared drive as Manager:\n' + json.loads((open(
# credentials[0],'r').read()))['installed']['client_id'])
input('>> Make sure the **Google account** that has generated credentials.json\n is added into your Team Drive '
'(shared drive) as Manager\n>> (Press any key to continue)')

creds = None
if os.path.exists('token_sa.pickle'):
with open('token_sa.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(credentials[0], scopes=[
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.member'
])
# creds = flow.run_local_server(port=0)
creds = flow.run_console()
# Save the credentials for the next run
with open('token_sa.pickle', 'wb') as token:
pickle.dump(creds, token)

drive = googleapiclient.discovery.build("drive", "v3", credentials=creds)
batch = drive.new_batch_http_request()

aa = glob.glob('%s/*.json' % acc_dir)
pbar = progress.bar.Bar("Readying accounts", max=len(aa))
for i in aa:
ce = json.loads(open(i, 'r').read())['client_email']
batch.add(drive.permissions().create(fileId=did, supportsAllDrives=True, body={
"role": "organizer",
"type": "user",
"emailAddress": ce
}))
pbar.next()
pbar.finish()
print('Adding...')
batch.execute()

print('Complete.')
hours, rem = divmod((time.time() - stt), 3600)
minutes, sec = divmod(rem, 60)
print("Elapsed Time:\n{:0>2}:{:0>2}:{:05.2f}".format(int(hours), int(minutes), sec))
from google.auth.exceptions import RefreshError
from google.auth.scopes import SCOPES
import argparse
import json
import progress.bar
import glob
import os
import sys
import time

def file_exists(file_path: str) -> bool:
"""Check if a file exists.

Args:
file_path (str): The path of the file to check.

Returns:
bool: True if the file exists, False otherwise.
"""
return os.path.isfile(file_path)

def get_time_str(seconds: float) -> str:
"""Format elapsed time as hours, minutes, and seconds.

Args:
seconds (float): The elapsed time in seconds.

Returns:
str: The elapsed time in the format hh:mm:ss.ss
"""
hours, rem = divmod(seconds, 3600)
minutes, seconds = divmod(rem, 60)
return f"{int(hours):0>2}:{int(minutes):0>2}:{seconds:05.2f}"

def get_drive_service(credentials: Credentials) -> build:
"""Get the Google Drive service.

Args:
credentials (google.oauth2.credentials.Credentials): The OAuth 2.0 credentials.

Returns:
googleapiclient.discovery.Resource: The Google Drive service.
"""
return build("drive", "v3", credentials=credentials)

def add_service_accounts_to_drive(drive_id: str, account_folder: str, credentials_file: str, yes: bool) -> None:
"""Add service accounts to a shared drive.

Args:
drive_id (str): The ID of the shared drive.
account_folder (str): The path to the folder containing service account credentials.
credentials_file (str): The path to the credentials file.
yes (bool): Whether to skip the sanity prompt.
"""
if not file_exists(credentials_file):
print(">> No credentials found.")
sys.exit(0)

if not yes:
input(
'>> Make sure the Google account that has generated ' + credentials_file + ' '
'is added into your Team Drive (shared drive) as Manager\n>> (Press any key to continue)'
)

credentials = Credentials.from_authorized_user_file(credentials_file, SCOPES)

if not credentials or not credentials.valid:
if credentials and credentials.expired and credentials.refresh_token:
try:
credentials.refresh(Request())
except RefreshError:
print("The credentials have expired and cannot be refreshed.")
sys.exit(1)
else:
print(">> Please run `gcloud auth application-default login` to authenticate.")
sys.exit(1)

drive = get_drive_service(credentials)
batch = drive.new_batch_http_request()

aa = glob.glob(f"{account_folder}/*.json")
pbar = progress.bar.Bar("Readying accounts", max=len(aa))
for i in aa:
ce = json.loads(open(i, 'r').read())['client_email']
batch.add(
drive.permissions().create(
fileId=drive_id,
supportsAllDrives=True,
body={
"role": "organizer",
"type": "user",
"emailAddress": ce
}
)
)
pbar.next()
pbar.finish()
print('Adding...')
batch.execute()

print('Complete.')
elapsed_time = get_time_str(time.time() - stt)
print(f"Elapsed Time:\n{elapsed_time}")

if __name__ == "__main__":
stt = time.time()

parse = argparse.ArgumentParser(
description='A tool to add service accounts to a shared drive from a folder containing credential files.'
)
parse.add_argument('--path', '-p', default='accounts', help='Specify an alternative path to the service accounts folder.')
parse.add_argument('--credentials', '-c', default='./credentials.json',
help='Specify the relative path for the credentials file.')
parse.add_argument('--yes', '-y', default=False, action='store_true',
help='Skips the sanity prompt.')
parsereq = parse.add_argument_group('required arguments')
parsereq.add_argument('--drive-id', '-d', help='The ID of the Shared Drive.', required=True)

args = parse.parse_args()

add_service_accounts_to_drive(args.drive_id, args.path, args.credentials, args.yes)
12 changes: 10 additions & 2 deletions aria.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
tracker_list=$(curl -Ns https://ngosang.github.io/trackerslist/trackers_all_http.txt | awk '$0' | tr '\n\n' ',')
#!/bin/bash

# Get the trackers list and remove any empty lines
tracker_list=$(curl -Ns https://ngosang.github.io/trackerslist/trackers_all_http.txt | awk 'NF' | tr '\n' ',')

# Remove the trailing comma from the tracker list
tracker_list=${tracker_list%,}

# Start aria2c with the specified options and the tracker list
aria2c --allow-overwrite=true --auto-file-renaming=true --bt-enable-lpd=true --bt-detach-seed-only=true \
--bt-remove-unselected-file=true --bt-tracker="[$tracker_list]" --check-certificate=false \
--check-integrity=true --continue=true --content-disposition-default-utf8=true --daemon=true \
--disk-cache=40M --enable-rpc=true --follow-torrent=mem --force-save=true --http-accept-gzip=true \
--max-connection-per-server=10 --max-concurrent-downloads=10 --max-file-not-found=0 --max-tries=20 \
--min-split-size=10M --optimize-concurrent-downloads=true --peer-id-prefix=-qB4390- --reuse-uri=true \
--peer-agent=qBittorrent/4.3.9 --quiet=true --rpc-max-request-size=1024M --seed-ratio=0 --split=10 \
--summary-interval=0 --user-agent=Wget/1.12
--summary-interval=0 --user-agent=Wget/1.12
Loading