Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import requests
- import subprocess
- directory = r'C:\Users\user\YandexDisk\A Gentle Intro To Game Dev Using C# and MonoGame'
- video_format = ".mp4"
- def delete_public_link(file_path):
- TOKEN = 'ВАШ ТОКЕН'
- headers = {
- 'Authorization': f'OAuth {TOKEN}',
- }
- params = {
- 'path': file_path.replace("\\","/")
- }
- url = "https://cloud-api.yandex.net/v1/disk/resources/unpublish"
- response = requests.put(url, headers=headers, params=params)
- if response.status_code == 200:
- print(f"Файл {file_path} распубликован.")
- else:
- print(f"Ошибка при распубликации файла: {response.status_code}, {response.text}")
- return "None"
- def get_public_link(file_path):
- TOKEN = 'ВАШ ТОКЕН'
- headers = {
- 'Authorization': f'OAuth {TOKEN}',
- }
- params = {
- 'path': file_path.replace("\\","/"),
- }
- url = "https://cloud-api.yandex.net/v1/disk/resources/publish"
- response = requests.put(url, headers=headers, params=params)
- if response.status_code == 200:
- print(f"Файл {file_path} опубликован.")
- else:
- print(f"Ошибка при публикации файла: {response.status_code}, {response.text}")
- return "None"
- get_url = "https://cloud-api.yandex.net/v1/disk/resources"
- response = requests.get(get_url, headers=headers, params=params)
- if response.status_code == 200:
- return response.json().get('public_url')
- else:
- print(f"Ошибка при получении ссылки: {response.status_code}, {response.text}")
- return "None"
- def list_files_in_directory(directory):
- file_list = []
- for root, dirs, files in os.walk(directory):
- for file in files:
- if file.endswith(video_format):
- path = root.replace("C:\\Users\\user\\YandexDisk\\", "")
- link = get_public_link(os.path.join(path, file))
- file = file.replace(video_format, '.mp3')
- file_list.append([root, file, link])
- return file_list
- def run_commands_in_batches(commands, batch_size=3):
- for i in range(0, len(commands), batch_size):
- batch = commands[i:i + batch_size]
- processes = [subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)
- for command in batch]
- for process in processes:
- stdout, stderr = process.communicate()
- print(f"Вывод: {stdout}")
- if stderr:
- print(f"Ошибки: {stderr}")
- def translate():
- files = list_files_in_directory(directory)
- commands = []
- for data in files:
- command = 'vot-cli --output="' + data[0] + '" --output-file "' + data[1] + '" --lang=en "' + data[2] + '"'
- commands.append(command)
- run_commands_in_batches(commands, batch_size=5)
- translate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement