### Basic file download with pySmartDL Source: http://itaybb.github.io/pySmartDL/index.html Initialize a SmartDL object with a URL and destination, then start the download process. ```python from pySmartDL import SmartDL url = “https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip” dest = “C:\Downloads" # or ‘~/Downloads/’ on linux obj = SmartDL(url, dest) obj.start() # [*] 0.23 Mb / 0.37 Mb @ 88.00Kb/s [##########——–] [60%, 2s left] path = obj.get_dest() ``` -------------------------------- ### Basic Download with pySmartDL Source: http://itaybb.github.io/pySmartDL/_sources/code.rst.txt Demonstrates how to initialize and start a download using the SmartDL class. Specify the URL and destination path. The download progress is shown in real-time. ```python from pySmartDL import SmartDL url = "https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip" dest = "C:\\Downloads\\" # or '~/Downloads/' on linux obj = SmartDL(url, dest) obj.start() # [*] 0.23 Mb / 0.37 Mb @ 88.00Kb/s [##########--------] [60%, 2s left] path = obj.get_dest() ``` -------------------------------- ### Non-blocking download with progress information Source: http://itaybb.github.io/pySmartDL/examples.html This example demonstrates how to perform a download in a non-blocking manner and continuously retrieve download status, speed, ETA, and progress information. ```python import time from pySmartDL import SmartDL url_100mb_file = ['http://www.ovh.net/files/100Mio.dat'] obj = SmartDL(url_100mb_file, progress_bar=False) obj.start(blocking=False) while not obj.isFinished(): print("Speed: %s" % obj.get_speed(human=True)) print("Already downloaded: %s" % obj.get_dl_size(human=True)) print("Eta: %s" % obj.get_eta(human=True)) print("Progress: %d%%" % (obj.get_progress()*100)) print("Progress bar: %s" % obj.get_progress_bar()) print("Status: %s" % obj.get_status()) print("\n"*2+"="*50+"\n"*2) time.sleep(0.2) if obj.isSuccessful(): print("downloaded file to '%s'" % obj.get_dest()) print("download task took %ss" % obj.get_dl_time(human=True)) print("File hashes:") print(" * MD5: %s" % obj.get_data_hash('md5')) print(" * SHA1: %s" % obj.get_data_hash('sha1')) print(" * SHA256: %s" % obj.get_data_hash('sha256')) else: print("There were some errors:") for e in obj.get_errors(): print(str(e)) # Do something with obj.get_dest() ``` -------------------------------- ### Hash checking with blocking download Source: http://itaybb.github.io/pySmartDL/examples.html This example demonstrates how to perform a hash check after a download completes. It uses a blocking download and catches a `HashFailedException` if the check fails. ```python from pySmartDL import SmartDL, HashFailedException urls = ["https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip", "http://www.bevc.net/dl/7za920.zip", "http://ftp.jaist.ac.jp/pub/sourceforge/s/project/se/sevenzip/7-Zip/9.20/7za920.zip", "http://www.mirrorservice.org/sites/downloads.sourceforge.net/s/se/sevenzip/7-Zip/9.20/7za920.zip"] obj = SmartDL(urls, progress_bar=False) # use connect_default_logger=True if you'd like to get debugging info to the console obj.add_hash_verification('sha256' ,'2a3afe19c180f8373fa02ff00254d5394fec0349f5804e0ad2f6067854ff28ac') try: obj.start() # Do something with obj.get_dest() except HashFailedException: print("Hash check failed!") ``` -------------------------------- ### Hash verification with non-blocking start Source: http://itaybb.github.io/pySmartDL/_sources/examples.rst.txt Sets up hash verification for a download initiated with `obj.start(blocking=False)`. The hash check will occur after the download is finished and `isFinished()` returns true. The `HashFailedException` will be raised if the check fails. ```python from pySmartDL import SmartDL urls = ["https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip", "http://www.bevc.net/dl/7za920.zip", "http://ftp.jaist.ac.jp/pub/sourceforge/s/project/se/sevenzip/7-Zip/9.20/7za920.zip", "http://www.mirrorservice.org/sites/downloads.sourceforge.net/s/se/sevenzip/7-Zip/9.20/7za920.zip"] ``` -------------------------------- ### Hash checking with non-blocking download Source: http://itaybb.github.io/pySmartDL/examples.html This example shows how to perform a hash check with a non-blocking download. The download status is monitored in a loop, and success or failure is checked after the download finishes. ```python from pySmartDL import SmartDL urls = ["https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip", "http://www.bevc.net/dl/7za920.zip", "http://ftp.jaist.ac.jp/pub/sourceforge/s/project/se/sevenzip/7-Zip/9.20/7za920.zip", "http://www.mirrorservice.org/sites/downloads.sourceforge.net/s/se/sevenzip/7-Zip/9.20/7za920.zip"] obj = SmartDL(urls, progress_bar=False) # use connect_default_logger=True if you'd like to get debugging info to the console obj.add_hash_verification('sha256' ,'2a3afe19c180f8373fa02ff00254d5394fec0349f5804e0ad2f6067854ff28ac') obj.start(blocking=False) while not obj.isFinished(): do_your_stuff() if obj.isSuccessful(): print("Success!") # Do something with obj.get_dest() else: print("Download failed with the following exceptions:") for e in obj.get_errors(): print(unicode(e)) ``` -------------------------------- ### Hash verification with blocking start Source: http://itaybb.github.io/pySmartDL/_sources/examples.rst.txt Performs a hash verification after download when `obj.start()` is called with `blocking=True`. Raises `HashFailedException` if the downloaded file's hash does not match the expected hash. ```python from pySmartDL import SmartDL, HashFailedException urls = ["https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip", "http://www.bevc.net/dl/7za920.zip", "http://ftp.jaist.ac.jp/pub/sourceforge/s/project/se/sevenzip/7-Zip/9.20/7za920.zip", "http://www.mirrorservice.org/sites/downloads.sourceforge.net/s/se/sevenzip/7-Zip/9.20/7za920.zip"] obj = SmartDL(urls, progress_bar=False) # use connect_default_logger=True if you'd like to get debugging info to the console obj.add_hash_verification('sha256' ,'2a3afe19c180f8373fa02ff00254d5394fec0349f5804e0ad2f6067854ff28ac') try: obj.start() # Do something with obj.get_dest() except HashFailedException: print("Hash check failed!") ``` -------------------------------- ### Download a file to a temporary location without progress bar Source: http://itaybb.github.io/pySmartDL/examples.html This example shows how to download a file to a temporary location without displaying a progress bar. The library automatically selects a temporary path if none is provided. ```python from pySmartDL import SmartDL url = "https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip" obj = SmartDL(url, progress_bar=False) # Because we didn't pass a destination path to the constructor, temporary path was chosen. obj.start() # Do something with obj.get_dest() ``` -------------------------------- ### Pass custom options to urllib.request.Request Source: http://itaybb.github.io/pySmartDL/examples.html This example shows how to pass custom arguments, such as headers, to the underlying `urllib.request.Request` object for more control over the HTTP request. ```python from pySmartDL import SmartDL request_args = {"headers": {"User-Agent": "pySmartDL/1.3.2"}} obj = SmartDL("http://httpbin.org/headers", request_args=request_args, progress_bar=False) obj.start() data = obj.get_json() print(data) ``` -------------------------------- ### Get all exceptions from ManagedThreadPoolExecutor Source: http://itaybb.github.io/pySmartDL/code.html Retrieves a list of all exceptions that occurred during the execution of tasks in the thread pool. Returns an empty list if no exceptions were raised. ```python List of Exception instances ``` -------------------------------- ### Get the first exception from ManagedThreadPoolExecutor Source: http://itaybb.github.io/pySmartDL/code.html Retrieves the first exception that occurred during task execution in the thread pool. Returns None if no exceptions were raised. ```python Exception instance ``` -------------------------------- ### Basic File Download with pySmartDL Source: http://itaybb.github.io/pySmartDL/code.html Demonstrates how to initiate a file download using pySmartDL. Specify the URL and destination path. The library handles the download process and provides progress information. ```python from pySmartDL import SmartDL url = "https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip" dest = "C:\\Downloads\\" # or '~/Downloads/' on linux obj = SmartDL(url, dest) obj.start() # [*] 0.23 Mb / 0.37 Mb @ 88.00Kb/s [##########--------] [60%, 2s left] path = obj.get_dest() ``` -------------------------------- ### Download using mirror URLs Source: http://itaybb.github.io/pySmartDL/examples.html Demonstrates downloading a file using a list of mirror URLs. The library will attempt to download from the first available working URL. ```python from pySmartDL import SmartDL urls = ["http://totally_fake_website/7za.zip" ,"https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip"] obj = SmartDL(urls, progress_bar=False) obj.start() print(obj.isSuccessful()) # Returns True, even though the first link is not working. # Do something with obj.get_dest() ``` -------------------------------- ### SmartDL Class Initialization Source: http://itaybb.github.io/pySmartDL/_sources/code.rst.txt Initializes a new download task using the SmartDL class. ```APIDOC ## Class: pySmartDL.SmartDL ### Description The main class for managing file downloads. It handles the download process, including progress tracking and destination management. ### Parameters - **url** (string) - Required - The URL of the file to download. - **dest** (string) - Required - The destination path where the file will be saved. ### Methods - **start()** - Starts the download process. - **get_dest()** - Returns the destination path of the downloaded file. - **stop()** - Cancels the current download task. - **isSuccessful()** - Returns True if the download was successful, False otherwise. - **get_errors()** - Returns a list of exceptions encountered during the download process. ### Request Example from pySmartDL import SmartDL url = "https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip" dest = "C:\\Downloads\\" obj = SmartDL(url, dest) obj.start() ``` -------------------------------- ### Download using mirror URLs Source: http://itaybb.github.io/pySmartDL/_sources/examples.rst.txt Supports downloading files from multiple mirror URLs. The library will attempt to download from the first available mirror. `isSuccessful()` returns True if at least one mirror worked. ```python from pySmartDL import SmartDL urls = ["http://totally_fake_website/7za.zip" ,"https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip"] obj = SmartDL(urls, progress_bar=False) obj.start() print(obj.isSuccessful()) # Returns True, even though the first link is not working. # Do something with obj.get_dest() ``` -------------------------------- ### Download with Hash Verification Source: http://itaybb.github.io/pySmartDL/_sources/examples.rst.txt Demonstrates a non-blocking download with SHA256 hash verification and error handling. ```python obj = SmartDL(urls, progress_bar=False) # use connect_default_logger=True if you'd like to get debugging info to the console obj.add_hash_verification('sha256' ,'2a3afe19c180f8373fa02ff00254d5394fec0349f5804e0ad2f6067854ff28ac') obj.start(blocking=False) while not obj.isFinished(): do_your_stuff() if obj.isSuccessful(): print("Success!") # Do something with obj.get_dest() else: print("Download failed with the following exceptions:") for e in obj.get_errors(): print(unicode(e)) ``` -------------------------------- ### pySmartDL.SmartDL Initialization Source: http://itaybb.github.io/pySmartDL/code.html Initializes the SmartDL class for downloading files. It supports multiple URLs as mirrors, custom destinations, progress bars, and thread management. ```APIDOC ## pySmartDL.SmartDL (main class) ### Description The main SmartDL class for handling file downloads. ### Parameters * **urls** (string or list of strings) - Download URL(s). Can be used for mirrors. Supports unsafe and unicode characters. * **dest** (string) - Destination path for the download. Defaults to a temporary directory. Can be a folder or a full path including filename. * **progress_bar** (bool) - If True, displays a progress bar. Defaults to True. * **fix_urls** (bool) - If True, attempts to fix URLs with unsafe characters. Defaults to True. * **threads** (int) - Number of threads to use for downloading. Defaults to 5. * **timeout** (int) - Timeout for network operations in seconds. Defaults to 5. * **logger** (logging.Logger instance) - An optional logger instance. * **connect_default_logger** (bool) - If True, connects a default logger. Defaults to False. * **request_args** (dict) - Arguments to pass to `urllib.request.Request`. * **verify** (bool) - If True, validates SSL certificates. Defaults to True. ### Return Type SmartDL instance ### Notes on `dest` parameter: * If `dest` exists and is a folder, the file is downloaded into it with its original filename. * If `dest` does not exist, folders will be created, and the last part of the path will be used as the filename. * To download to a non-existent folder and let the module determine the filename, ensure the path ends with `os.sep`. * If no path is provided, `%TEMP%/pySmartDL/` will be used. ``` -------------------------------- ### System and Threading Utilities Source: http://itaybb.github.io/pySmartDL/code.html Utilities for hashing, logging, and managing thread pools. ```APIDOC ## get_file_hash ### Description Calculates a file's hash using a specified algorithm. ### Parameters - **algorithm** (string) - Required - Hashing algorithm (e.g., md5, sha1). - **path** (string) - Required - The file path. ### Response - **string** - The calculated hash. ## ManagedThreadPoolExecutor ### Description A subclass of ThreadPoolExecutor for managing concurrent tasks. ### Methods - **submit(fn, *args, **kwargs)**: Submits a callable for execution. - **get_exceptions()**: Returns a list of all raised exceptions. - **get_exception()**: Returns the first raised exception. ``` -------------------------------- ### Exception Handling Source: http://itaybb.github.io/pySmartDL/_sources/code.rst.txt List of exceptions that may be raised during the download process. ```APIDOC ## Exceptions - **HashFailedException**: Raised when the hash check of the downloaded file fails. - **CanceledException**: Raised when the user cancels the task using SmartDL.stop(). - **urllib2.HTTPError**: Raised due to server-side issues. - **urllib2.URLError**: Raised due to connectivity issues reaching the server. - **exceptions.IOError**: Raised due to local I/O problems, such as insufficient disk space. ``` -------------------------------- ### Download a file to a specified destination Source: http://itaybb.github.io/pySmartDL/examples.html Use this to download a file from a URL to a specific local directory. Ensure the destination path is valid. ```python from pySmartDL import SmartDL url = "https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip" dest = "C:\\Downloads\\" # or '~/Downloads/' on linux obj = SmartDL(url, dest) obj.start() # [*] 0.23 / 0.37 MB @ 88.00KB/s [##########--------] [60%, 2s left] path = obj.get_dest() ``` -------------------------------- ### pySmartDL.SmartDL Methods Source: http://itaybb.github.io/pySmartDL/code.html Methods available on the SmartDL instance for managing and monitoring downloads. ```APIDOC ## pySmartDL.SmartDL Methods ### `add_basic_authentication(username, password)` #### Description Uses HTTP Basic Access authentication for the connection. #### Parameters * **username** (string) - Username for authentication. * **password** (string) - Password for authentication. ### `add_hash_verification(algorithm, hash)` #### Description Adds hash verification to the download. If the hash is incorrect, it will try different mirrors. Raises `HashFailedException` if all mirrors fail verification. If the downloaded file already exists and the hash matches, it won't be downloaded again. #### Parameters * **algorithm** (string) - Hashing algorithm (e.g., 'sha256', 'md5'). Must be supported by `hashlib`. * **hash** (string) - The expected hash code of the file. ### `fetch_hash_sums()` #### Description Attempts to fetch UNIX hash sum files (e.g., SHA256SUMS) from the same directory as the download URL. If successful, it calls `add_hash_verification`. Returns `True` if a matching hash was found, `False` otherwise. #### Return Type bool ### `start(blocking=None)` #### Description Starts the download task. Raises `RuntimeError` if the object is already downloading. #### Parameters * **blocking** (bool) - If `True`, blocks the thread until the download is finished. Defaults to `True`. #### Warning In non-blocking mode, exceptions are not raised directly. Use `isSuccessful()` and `get_errors()` to check for issues. ### `get_eta(human=False)` #### Description Gets the estimated time of download completion in seconds. #### Parameters * **human** (bool) - If `True`, returns a human-readable formatted string. Defaults to `False`. #### Return Type int or string ### `get_speed(human=False)` #### Description Gets the current transfer speed in bytes per second. #### Parameters * **human** (bool) - If `True`, returns a human-readable formatted string. Defaults to `False`. #### Return Type int or string ### `get_progress()` #### Description Returns the current download progress as a float between 0 and 1. #### Return Type float ### `get_progress_bar(length=20)` #### Description Returns the current download progress as a string containing a progress bar. #### Parameters * **length** (int) - The length of the progress bar in characters. Defaults to 20. #### Return Type string ### `isFinished()` #### Description Returns `True` if the download task is finished, `False` otherwise. #### Return Type bool ### `isSuccessful()` #### Description Returns `True` if the download was successful, `False` otherwise. May fail due to hash check errors, unavailable mirrors, or local I/O problems. #### Warning Raises `RuntimeError` if called before the download task is finished. #### Return Type bool ``` -------------------------------- ### Non-blocking download with status updates Source: http://itaybb.github.io/pySmartDL/_sources/examples.rst.txt Initiates a download in a non-blocking mode, allowing you to retrieve download status information like speed, progress, and ETA during the download process. Requires manual checking of `isFinished()`. ```python import time from pySmartDL import SmartDL url_100mb_file = ['http://www.ovh.net/files/100Mio.dat'] obj = SmartDL(url_100mb_file, progress_bar=False) obj.start(blocking=False) while not obj.isFinished(): print("Speed: %s" % obj.get_speed(human=True)) print("Already downloaded: %s" % obj.get_dl_size(human=True)) print("Eta: %s" % obj.get_eta(human=True)) print("Progress: %d%%" % (obj.get_progress()*100)) print("Progress bar: %s" % obj.get_progress_bar()) print("Status: %s" % obj.get_status()) print("\n"*2+"="*50+"\n"*2) time.sleep(0.2) if obj.isSuccessful(): print("downloaded file to '%s'" % obj.get_dest()) print("download task took %ss" % obj.get_dl_time(human=True)) print("File hashes:") print(" * MD5: %s" % obj.get_data_hash('md5')) print(" * SHA1: %s" % obj.get_data_hash('sha1')) print(" * SHA256: %s" % obj.get_data_hash('sha256')) else: print("There were some errors:") for e in obj.get_errors(): print(str(e)) # Do something with obj.get_dest() ``` -------------------------------- ### Formatting and Information Utilities Source: http://itaybb.github.io/pySmartDL/code.html Functions for progress bars, human-readable formatting, and file information. ```APIDOC ## progress_bar ### Description Returns a textual representation of a progress bar. ### Parameters - **progress** (float) - Required - Number between 0 and 1. - **length** (int) - Optional - Length of the bar in characters (default: 20). ### Response - **string** - The progress bar string. ## get_filesize ### Description Fetches the size of a file over HTTP. ### Parameters - **url** (string) - Required - URL address. - **timeout** (int) - Optional - Timeout in seconds (default: 15). ### Response - **int** - Size in bytes. ## sizeof_human ### Description Converts a file size in bytes to a human-readable string. ### Parameters - **num** (int) - Required - Size in bytes. ### Response - **string** - Formatted size string. ``` -------------------------------- ### Download Control Methods Source: http://itaybb.github.io/pySmartDL/code.html Methods to manage the lifecycle of a download task. ```APIDOC ## wait(raise_exceptions=False) ### Description Blocks until the download is finished. ### Parameters #### Query Parameters - **raise_exceptions** (bool) - Optional - If true, this function will raise exceptions. Default is False. ## stop() ### Description Stops the download. ## pause() ### Description Pauses the download. ## resume() / unpause() ### Description Continues the download. ``` -------------------------------- ### File and URL Utilities Source: http://itaybb.github.io/pySmartDL/code.html Functions for combining files, fixing URL strings, and checking HTTP capabilities. ```APIDOC ## combine_files ### Description Combines multiple source files into a single destination file. ### Parameters - **parts** (list of strings) - Required - Source files. - **dest** (string) - Required - Destination file. - **chunkSize** (int) - Optional - Fetching chunk size (default: 4194304). ## url_fix ### Description Fixes unsafe characters in a URL string, similar to how browsers handle user input. ### Parameters - **s** (string) - Required - URL address. - **charset** (string) - Optional - Target charset (default: 'utf-8'). ### Response - **string** - The fixed URL string. ## is_HTTPRange_supported ### Description Checks if a server allows Byte serving using HTTP headers. ### Parameters - **url** (string) - Required - URL address. - **timeout** (int) - Optional - Timeout in seconds (default: 15). ### Response - **bool** - True if supported, False otherwise. ``` -------------------------------- ### Fetch data to memory instead of a file Source: http://itaybb.github.io/pySmartDL/examples.html Use this method to fetch the content of a URL directly into memory as bytes, rather than saving it to a file. This is useful for processing data immediately. ```python from pySmartDL import SmartDL url = "http://wiki.python.org/moin/Python2orPython3" # it's also possible to pass unsafe and unicode characters in url obj = SmartDL(url, progress_bar=False) obj.start() data = obj.get_data() # HTML tags! # Do something with data ``` -------------------------------- ### Fetch data to memory Source: http://itaybb.github.io/pySmartDL/_sources/examples.rst.txt Downloads the content of a URL directly into memory as a string, rather than saving it to a file. Useful for processing small files or API responses. ```python from pySmartDL import SmartDL url = "http://wiki.python.org/moin/Python2orPython3" # it's also possible to pass unsafe and unicode characters in url obj = SmartDL(url, progress_bar=False) obj.start() data = obj.get_data() # HTML tags! # Do something with data ``` -------------------------------- ### Download Status and Information Source: http://itaybb.github.io/pySmartDL/code.html Methods to retrieve the current state and metadata of the download task. ```APIDOC ## get_status() ### Description Returns the current status of the task. Possible values: ready, downloading, paused, combining, finished. ### Response - **status** (string) - The current status of the task. ## get_errors() ### Description Get errors happened while downloading. ### Response - **errors** (list) - List of Exception instances. ## get_dest() ### Description Get the destination path of the downloaded file. ### Response - **path** (string) - The destination path. ``` -------------------------------- ### Create a debugging logger Source: http://itaybb.github.io/pySmartDL/code.html Instantiates a logger that outputs debugging information to the console. This is useful for development and troubleshooting. ```python logging.Logger instance ``` -------------------------------- ### SmartDL Class Methods Source: http://itaybb.github.io/pySmartDL/genindex.html Methods available within the pySmartDL.SmartDL class for managing download operations. ```APIDOC ## SmartDL Methods ### Description Methods for controlling and retrieving information about download tasks. ### Methods - **add_basic_authentication()**: Adds basic authentication to the download request. - **add_hash_verification()**: Enables hash verification for the downloaded file. - **fetch_hash_sums()**: Fetches hash sums for verification. - **get_data()**: Retrieves the downloaded data. - **get_data_hash()**: Returns the hash of the downloaded data. - **get_dest()**: Returns the destination path of the file. - **get_dl_size()**: Returns the size of the download. - **get_dl_time()**: Returns the time taken for the download. - **get_errors()**: Returns a list of errors encountered. - **get_eta()**: Returns the estimated time of arrival for completion. - **get_final_filesize()**: Returns the final size of the file. - **get_json()**: Returns download information in JSON format. - **get_progress()**: Returns the current progress of the download. - **get_progress_bar()**: Returns the progress bar object. - **get_speed()**: Returns the current download speed. - **get_status()**: Returns the current status of the download. - **isFinished()**: Checks if the download is finished. - **isSuccessful()**: Checks if the download was successful. - **limit_speed()**: Limits the download speed. - **pause()**: Pauses the download. - **resume()**: Resumes a paused download. - **start()**: Starts the download process. - **stop()**: Stops the download process. - **unpause()**: Unpauses the download. - **wait()**: Waits for the download to complete. ``` -------------------------------- ### Dummy Logger Class Source: http://itaybb.github.io/pySmartDL/code.html A placeholder logger class where all logging methods (debug, warning, etc.) are no-ops. Useful when logging is not required or needs to be conditionally disabled. ```python class pySmartDL.utils.DummyLogger ``` -------------------------------- ### Data Retrieval Methods Source: http://itaybb.github.io/pySmartDL/code.html Methods to access the downloaded content and statistics. ```APIDOC ## get_data(binary=False, bytes=-1) ### Description Returns the downloaded data. Raises RuntimeError if called before task is finished. ### Parameters #### Query Parameters - **binary** (bool) - Optional - If true, reads as binary. Else, reads as text. - **bytes** (int) - Optional - Number of bytes to read. Negative values read until EOF. Default is -1. ## get_json() ### Description Returns the JSON in the downloaded data. Raises RuntimeError if not finished or JSONDecodeError if invalid. ### Response - **data** (dict) - The parsed JSON data. ``` -------------------------------- ### Format duration into human-readable string Source: http://itaybb.github.io/pySmartDL/code.html Converts a duration in seconds into a human-readable string. Supports short format and millisecond display. ```python >>> time_human(175799789) '6 years, 2 weeks, 4 days, 17 hours, 16 minutes, 29 seconds' >>> time_human(589, fmt_short=True) '9m49s' ``` -------------------------------- ### Format file size into human-readable string Source: http://itaybb.github.io/pySmartDL/code.html Converts a file size in bytes into a human-readable format (e.g., KB, MB, GB). ```python >>> sizeof_human(175799789) '167.7 MB' ``` -------------------------------- ### pySmartDL Utility Functions Source: http://itaybb.github.io/pySmartDL/genindex.html Utility functions provided by the pySmartDL.utils module. ```APIDOC ## pySmartDL.utils Functions ### Description Helper functions for file handling, formatting, and network utilities. ### Functions - **calc_chunk_size()**: Calculates the appropriate chunk size. - **combine_files()**: Combines multiple files into one. - **create_debugging_logger()**: Creates a logger for debugging purposes. - **get_file_hash()**: Calculates the hash of a file. - **get_filesize()**: Retrieves the size of a file. - **get_random_useragent()**: Returns a random user-agent string. - **is_HTTPRange_supported()**: Checks if HTTP Range is supported by the server. - **progress_bar()**: Utility for displaying a progress bar. - **sizeof_human()**: Formats file size into a human-readable string. - **time_human()**: Formats time duration into a human-readable string. - **url_fix()**: Fixes URL formatting issues. ``` -------------------------------- ### Generate textual progress bar Source: http://itaybb.github.io/pySmartDL/code.html Creates a visual progress bar string based on a progress float. Specify the desired length of the bar in characters. ```python >>> progress_bar(0.6) '[##########--------]' ``` -------------------------------- ### Disable SSL verification in pySmartDL Source: http://itaybb.github.io/pySmartDL/examples.html Use the verify=False parameter in the SmartDL constructor to skip SSL certificate validation. This is useful for testing or when dealing with self-signed certificates. ```python from pySmartDL import SmartDL obj = SmartDL("https://github.com/iTaybb/pySmartDL/raw/master/test/7za920.zip", verify=False) obj.start() # Do something with obj.get_dest() ``` -------------------------------- ### Submit a callable to ManagedThreadPoolExecutor Source: http://itaybb.github.io/pySmartDL/code.html Submits a function to be executed asynchronously by the thread pool. Returns a Future object representing the execution. ```python A Future representing the given call. ``` -------------------------------- ### Fix URL with unsafe characters Source: http://itaybb.github.io/pySmartDL/code.html Use this function to correct URLs containing unsafe characters, similar to how browsers handle user input. It ensures the URL is properly encoded. ```python >>> url_fix(u'http://de.wikipedia.org/wiki/Elf (Begriffsklärung)') 'http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.