|
| 1 | +# SonicBit Python SDK |
| 2 | + |
| 3 | +An unofficial Python SDK for SonicBit which uses the internal API to interact with the application. |
| 4 | + |
| 5 | +> [!WARNING] |
| 6 | +> This SDK is provided as-is and is not officially supported by Sonicbit. The author is not responsible for any damages or losses caused by the use of this SDK. Use it at your own risk. Please use it responsibly and with the understanding that it may not be fully functional or reliable. Check Sonicbit's terms of service for more information. |
| 7 | +
|
| 8 | +## Installation |
| 9 | + |
| 10 | +Install the package using pip: |
| 11 | + |
| 12 | +```bash |
| 13 | +pip install sonicbit |
| 14 | +``` |
| 15 | + |
| 16 | +Install bleeding edge version: |
| 17 | + |
| 18 | +```bash |
| 19 | +pip install git+https://github.com/viperadnan-git/sonicbit-python-sdk.git |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +> [!IMPORTANT] |
| 25 | +> This SDK is still in development and may not be fully functional. Please report any issues or bugs you encounter. |
| 26 | +> The below documentation is generated by AI and is subject to change as the SDK evolves. |
| 27 | +
|
| 28 | +To use the SDK, you need to create an instance of the `SonicBit` class and provide your email and password: |
| 29 | + |
| 30 | +```python |
| 31 | +from sonicbit import SonicBit |
| 32 | + |
| 33 | +sb = SonicBit(email='your_email@example.com', password='your_password') |
| 34 | +``` |
| 35 | + |
| 36 | +Once you have an instance of `SonicBit`, you can use its various methods to interact with the application. For example, to list the files in your storage: |
| 37 | + |
| 38 | +```python |
| 39 | +files = sb.list_files() |
| 40 | +print(files) |
| 41 | +``` |
| 42 | + |
| 43 | +### Token Handling |
| 44 | + |
| 45 | +By default, the SDK will store your authentication token in a file named `.sonicbit.cache` in the current working directory. If you want to specify a different location for the token file, you can pass a `token_handler` argument to the `SonicBit` constructor: |
| 46 | + |
| 47 | +```python |
| 48 | +sb = SonicBit(email='your_email@example.com', password='your_password', token_handler=MyTokenHandler()) |
| 49 | +``` |
| 50 | + |
| 51 | +The `token_handler` should implement the following methods: |
| 52 | + |
| 53 | +- `read(email: str) -> str | None`: Reads the token for the given email from the token file. |
| 54 | +- `write(email: str, token: str) -> None`: Writes the token for the given email to the token file. |
| 55 | + |
| 56 | +The `token_handler` is optional and will default to a `TokenFileHandler` if not provided. |
| 57 | + |
| 58 | +> [!TIP] |
| 59 | +> You can use the `BaseTokenHandler` class to store and update tokens in a database or other storage mechanism. Simply implement the `read` and `write` methods and pass an instance of your custom class to the `SonicBit` constructor. This will allow you to store tokens in a secure location and easily update them as needed. |
| 60 | +
|
| 61 | +### User Module |
| 62 | + |
| 63 | +The `User` module provides methods for interacting with the user's account, such as getting their user details and storage details. |
| 64 | + |
| 65 | +#### User Details |
| 66 | + |
| 67 | +To get the user's details, you can use the `get_user_details` method: |
| 68 | + |
| 69 | +```python |
| 70 | +details = sb.get_user_details() |
| 71 | +print(details) |
| 72 | +``` |
| 73 | + |
| 74 | +This will print a `UserDetails` object containing information about the user's account, such as their email, plan name, and more. |
| 75 | + |
| 76 | +#### Storage Details |
| 77 | + |
| 78 | +To get the storage details, you can use the `get_storage_details` method: |
| 79 | + |
| 80 | +```python |
| 81 | +details = sb.get_storage_details() |
| 82 | +print(details) |
| 83 | +``` |
| 84 | + |
| 85 | +This will print a `StorageDetails` object containing information about the user's storage, such as their total storage size, free space, and more. |
| 86 | + |
| 87 | +#### Clear Storage |
| 88 | + |
| 89 | +To clear the user's storage, you can use the `clear_storage` method: |
| 90 | + |
| 91 | +```python |
| 92 | +success = sb.clear_storage() |
| 93 | +print(success) |
| 94 | +``` |
| 95 | + |
| 96 | +This will return `True` if the storage was successfully cleared, or `False` if there was an error. |
| 97 | + |
| 98 | +### Torrent Management |
| 99 | + |
| 100 | +The `Torrent` module provides methods for interacting with the user's torrents, such as adding, listing, and deleting torrents. |
| 101 | + |
| 102 | +#### Add Torrent |
| 103 | + |
| 104 | +To add a torrent, you can use the `add_torrent` method: |
| 105 | + |
| 106 | +```python |
| 107 | +torrents = sb.add_torrent("https://example.com/torrent.torrent") |
| 108 | +print(torrents) |
| 109 | +``` |
| 110 | + |
| 111 | +This will return a list of torrent hashes that were added. |
| 112 | + |
| 113 | +#### List Torrents |
| 114 | + |
| 115 | +To list the user's torrents, you can use the `list_torrents` method: |
| 116 | + |
| 117 | +```python |
| 118 | +torrents = sb.list_torrents() |
| 119 | +print(torrents) |
| 120 | +``` |
| 121 | + |
| 122 | +This will print a `TorrentList` object containing information about each torrent in the user's storage, such as the torrent name, hash, size, progress, and more. |
| 123 | + |
| 124 | +#### Get Torrent Details |
| 125 | + |
| 126 | +To get the details of a torrent, you can use the `get_torrent_details` method: |
| 127 | + |
| 128 | +```python |
| 129 | +details = sb.get_torrent_details("hash") |
| 130 | +print(details) |
| 131 | +``` |
| 132 | + |
| 133 | +This will print a `TorrentDetails` object containing information about the torrent, such as the files it contains, the download rate, and more. |
| 134 | + |
| 135 | +#### Delete Torrent |
| 136 | + |
| 137 | +To delete a torrent, you can use the `delete_torrent` method: |
| 138 | + |
| 139 | +```python |
| 140 | +success = sb.delete_torrent("hash") |
| 141 | +print(success) |
| 142 | +``` |
| 143 | + |
| 144 | +This will return `True` if the torrent was successfully deleted, or `False` if there was an error. |
| 145 | + |
| 146 | +### Remote Download Management |
| 147 | + |
| 148 | +The `RemoteDownload` module provides methods for interacting with the user's remote downloads, such as adding, listing, and deleting remote downloads. |
| 149 | + |
| 150 | +#### Add Remote Download |
| 151 | + |
| 152 | +To add a remote download, you can use the `add_remote_download` method: |
| 153 | + |
| 154 | +```python |
| 155 | +success = sb.add_remote_download("https://example.com/file.torrent", PathInfo.root()) |
| 156 | +print(success) |
| 157 | +``` |
| 158 | + |
| 159 | +This will return `True` if the remote download was successfully added, or `False` if there was an error. |
| 160 | + |
| 161 | +#### List Remote Downloads |
| 162 | + |
| 163 | +To list the user's remote downloads, you can use the `list_remote_downloads` method: |
| 164 | + |
| 165 | +```python |
| 166 | +downloads = sb.list_remote_downloads() |
| 167 | +print(downloads) |
| 168 | +``` |
| 169 | + |
| 170 | +This will print a `RemoteTaskList` object containing information about each remote download in the user's storage, such as the download URL, progress, and more. |
| 171 | + |
| 172 | +#### Delete Remote Download |
| 173 | + |
| 174 | +To delete a remote download, you can use the `delete_remote_download` method: |
| 175 | + |
| 176 | +```python |
| 177 | +success = sb.delete_remote_download(id) |
| 178 | +print(success) |
| 179 | +``` |
| 180 | + |
| 181 | +This will return `True` if the remote download was successfully deleted, or `False` if there was an error. |
| 182 | + |
| 183 | +### File Management |
| 184 | + |
| 185 | +The `File` module provides methods for interacting with the user's files, such as listing, deleting, and moving files. |
| 186 | + |
| 187 | +#### List Files |
| 188 | + |
| 189 | +To list the user's files, you can use the `list_files` method: |
| 190 | + |
| 191 | +```python |
| 192 | +files = sb.list_files() |
| 193 | +print(files) |
| 194 | +``` |
| 195 | + |
| 196 | +This will print a `FileList` object containing information about each file in the user's storage, such as the file name, size, and more. |
| 197 | + |
| 198 | +#### Delete File |
| 199 | + |
| 200 | +To delete a file, you can use the `delete_file` method: |
| 201 | + |
| 202 | +```python |
| 203 | +success = sb.delete_file("path/to/file") |
| 204 | +print(success) |
| 205 | +``` |
| 206 | + |
| 207 | +This will return `True` if the file was successfully deleted, or `False` if there was an error. |
| 208 | + |
| 209 | +## Contributing |
| 210 | + |
| 211 | +Contributions are welcome! If you find a bug or have a suggestion for a new feature, please open an issue or submit a pull request on the GitHub repository. |
| 212 | + |
| 213 | +## License |
| 214 | + |
| 215 | +This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for more details. |
0 commit comments