Skip to content

Commit 7d31fa0

Browse files
initial commit
0 parents  commit 7d31fa0

40 files changed

+2094
-0
lines changed

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}
9+
10+
jobs:
11+
deploy:
12+
name: Upload release to TestPyPI and PyPi
13+
14+
runs-on: ubuntu-latest
15+
16+
environment:
17+
name: pypi
18+
url: https://pypi.org/p/sonicbit
19+
20+
permissions:
21+
id-token: write
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
30+
- name: Install dependencies
31+
run: |
32+
pip install -r requirements.txt
33+
pip install -U build
34+
35+
- name: Build and package
36+
run: python3 -m build --sdist --wheel --outdir dist/ .
37+
38+
- name: Publish 📦 to Test PyPI
39+
uses: pypa/gh-action-pypi-publish@release/v1
40+
with:
41+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
42+
repository-url: https://test.pypi.org/legacy/
43+
skip-existing: true
44+
45+
- name: Publish 📦 to PyPI
46+
uses: pypa/gh-action-pypi-publish@release/v1
47+
with:
48+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# python cache and virtual environment
2+
.venv/
3+
__pycache__/
4+
5+
# program output
6+
*.cache
7+
8+
# build files
9+
dist/
10+
build/
11+
*.egg-info/
12+
13+
# development test files
14+
test.py
15+
test.json

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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.

format.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pip install autoflake black isort -q
2+
isort .
3+
black .
4+
autoflake --in-place --remove-all-unused-imports --recursive .

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests>=2.28.1

setup.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import re
2+
3+
from setuptools import find_packages, setup
4+
5+
with open("README.md", "r", encoding="utf-8") as fh:
6+
long_description = fh.read()
7+
8+
9+
def get_version() -> str:
10+
with open("sonicbit/__init__.py", "r") as f:
11+
version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)
12+
return version
13+
14+
15+
setup(
16+
name="sonicbit",
17+
version=get_version(),
18+
author="Adnan Ahmad",
19+
author_email="viperadnan@gmail.com",
20+
description="An unofficial Python SDK for SonicBit which uses the internal API to interact with the application.",
21+
long_description=long_description,
22+
long_description_content_type="text/markdown",
23+
url="https://github.com/viperadnan-git/sonicbit-python-sdk",
24+
license="GNU General Public License v3.0",
25+
keywords="sonicbit python sdk",
26+
packages=find_packages(),
27+
install_requires=["requests"],
28+
classifiers=[
29+
"Programming Language :: Python :: 3",
30+
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
31+
"Operating System :: OS Independent",
32+
],
33+
python_requires=">=3.10",
34+
)

sonicbit/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import logging
2+
3+
from sonicbit.handlers.token_file import TokenFileHandler
4+
from sonicbit.sonicbit import SonicBit
5+
6+
__version__ = "0.1.0"
7+
__all__ = ["SonicBit", "TokenFileHandler"]
8+
9+
logging.basicConfig(
10+
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
11+
)

sonicbit/constants.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Constants:
2+
API_DOMAIN = "v4.sonicbit.net"
3+
API_ORIGIN = "https://my.sonicbit.net"
4+
API_REFERER = "https://my.sonicbit.net/"
5+
API_BASE_URL = f"https://{API_DOMAIN}/api"
6+
7+
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15"
8+
9+
API_HEADERS = {
10+
"Accept": "application/json, text/plain, */*",
11+
"Accept-Encoding": "gzip, deflate, br",
12+
"Accept-Language": "en-IN,en-GB;q=0.9,en;q=0.8",
13+
"Connection": "keep-alive",
14+
"Host": API_DOMAIN,
15+
"Origin": API_ORIGIN,
16+
"Referer": API_REFERER,
17+
"User-Agent": USER_AGENT,
18+
}

0 commit comments

Comments
 (0)