import requests import os import base64 def download_file(file_info, destination_folder, file_number, total_files, api_key): file_id, file_name = file_info download_url = f"https://pixeldrain.com/api/file/{file_id}?download" local_filename = os.path.join(destination_folder, file_name) print(f"Downloading file {file_number} of {total_files}: {file_name}") # Properly format the API key for basic auth api_key_encoded = base64.b64encode(f":{api_key}".encode()).decode() headers = {'Authorization': f'Basic {api_key_encoded}'} with requests.get(download_url, headers=headers, stream=True) as r: r.raise_for_status() total_length = int(r.headers.get('content-length', 0)) downloaded = 0 with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): downloaded += len(chunk) f.write(chunk) if total_length > 0: done = int(50 * downloaded / total_length) print(f"\r[{'=' * done}{' ' * (50-done)}] {done * 2}%", end='') print() return local_filename def get_file_info_from_list(list_id, start_index=0): list_url = f"https://pixeldrain.com/api/list/{list_id}" response = requests.get(list_url) response.raise_for_status() list_data = response.json() return [(file['id'], file['name']) for file in list_data['files'][start_index:]] def main(): api_key = 'RandomAPIKey' # Replace with your API key list_id = 'ABCDEFGH' # Replace with your list ID start_index = 0 # Replace with your starting index destination_folder = 'C:/RandomFolder' file_infos = get_file_info_from_list(list_id, start_index) total_files = len(file_infos) for i, file_info in enumerate(file_infos, start=start_index + 1): download_file(file_info, destination_folder, i, total_files, api_key) print("All files downloaded.") if __name__ == "__main__": main()