modifikasi skrip berikut * di bagian # Daftar file id diganti dengan menambahkan #@param…
- User
modifikasi skrip berikut
- di bagian # Daftar file id diganti dengan menambahkan #@param {type:"string"}
- setiap file yang terdapat kalimat [javx357.com] dihapus, contoh: jika file [javx357.com]TEST.mp4, maka akan menjadi TEST.mp4
from google.colab import auth from googleapiclient.discovery import build from googleapiclient.http import MediaIoBaseDownload from tqdm.notebook import tqdm import io import time
Authenticate and create the service client for Drive API
auth.authenticate_user() drive_service = build('drive', 'v3')
Daftar file_id yang ingin Anda download
file_ids = [ '1S-jQn_QHZgMK9DkjoofxVqez9QeJEtCb', '1pCFlHHjdfPktqkYziJQD0yBmcNx5rjaK', '1a2Ul3xPCGFK0DLZLwb8pg_kU-qsjLVd_', '1Oy8EC0wG4Czie6sy-ivj7nQM6y9Mxx6_', '1Py2PFvzrGbcEwo504rt0BZQ7HiLEl-fx', # Tambahkan file_id lainnya di sini ]
Destination path where you want to save the files
dst_pth = '/content/drive/MyDrive/COPYS/' # Ubah sesuai dengan direktori tujuan Anda
def download_file(file_id, dst_pth): # Request the file metadata to get the file size file_metadata = drive_service.files().get(fileId=file_id, fields='name,size').execute() file_size = int(file_metadata.get('size', 0)) file_name = file_metadata.get('name')
code# Request the file request = drive_service.files().get_media(fileId=file_id) # Create a file handle to write the file to fh = io.FileIO(os.path.join(dst_pth, file_name), mode='wb') # Create a downloader object downloader = MediaIoBaseDownload(fh, request) # Custom format for the progress bar custom_tqdm_format = '{desc} |{bar}| {n_fmt}/{total_fmt} [{rate_noinv_fmt}{postfix}]' def adjust_units(size_in_bytes): units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] unit_index = 0 while size_in_bytes >= 1024 and unit_index < len(units) - 1: size_in_bytes /= 1024.0 unit_index += 1 return size_in_bytes, units[unit_index] # Create a progress bar object pbar = tqdm(total=file_size, desc=f'Downloading {file_name}', unit='B', unit_scale=True, bar_format=custom_tqdm_format) # Start the download process and update the progress bar done = False start_time = time.time() while not done: status, done = downloader.next_chunk() elapsed_time = time.time() - start_time download_speed = status.progress() * file_size / elapsed_time if elapsed_time > 0 else 0 pbar.set_postfix_str(f'Speed: {download_speed / (1024 * 1024):,.2f} MB/s, Elapsed: {elapsed_time:,.2f} s') pbar.update(status.resumable_progress - pbar.n) # Update progress # Close the file handle after downloading is complete fh.close() pbar.close() print(f'File downloaded to {os.path.join(dst_pth, file_name)}') - Assistant
- User
menambahkan #@param {type:"string"} itu pada setiap file_ids bukan keseluruhan, jadi nanti berupa form yang nantinya akan diisi file_id secara copy paste
- Assistant
- User
jika salah satu file_id tidak bisa di download, apakah skrip di atas akan melanjutkan ke file_id selanjutnya?
- Assistant