Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Update --> 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
hyugogirubato committed Apr 3, 2023
1 parent 093ba3c commit 6112871
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 10 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.2] - 2023-04-03

### Added

- Added new private endpoints.

### Changed

- Better support for default values.
- Renamed some function.
- Clearer exceptions.

### Fixed

- Fixed some endpoints.

## [1.0.1] - 2023-04-03

### Changed
Expand All @@ -15,5 +31,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Initial Release.

[1.0.2]: https://github.com/hyugogirubato/pyuptobox/releases/tag/v1.0.2
[1.0.1]: https://github.com/hyugogirubato/pyuptobox/releases/tag/v1.0.0
[1.0.0]: https://github.com/hyugogirubato/pyuptobox/releases/tag/v1.0.0
2 changes: 1 addition & 1 deletion pyuptobox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .client import Client
from .utils import *

__version__ = "1.0.1"
__version__ = "1.0.2"
75 changes: 67 additions & 8 deletions pyuptobox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import json
from pathlib import Path
import re

import requests
from bs4 import BeautifulSoup
from requests_toolbelt import MultipartEncoder
Expand All @@ -15,15 +17,15 @@ class Client:
}

def __init__(self):
self.token = None
self._token = None
self._web = "https://uptobox.com"
self._api = f"{self._web}/api"
self._session = requests.Session()

def _request(self, **kwargs) -> dict:
params = kwargs.get("params", {})
if self.token is not None:
params["token"] = self.token
if self._token is not None:
params["token"] = self._token

r = self._session.request(
method=kwargs.get("method", "GET").upper(),
Expand Down Expand Up @@ -85,12 +87,14 @@ def set_security_lock(self, lock: bool = False) -> None:

def get_point_conversion(self, points: int = 10) -> dict:
if points not in [10, 25, 50, 100]:
raise Exception("The number of points passed in parameter is incompatible.")
raise ValueError("The number of points passed in parameter is incompatible.")
return self._request(url=f"{self._api}/user/requestPremium", params={"points": points})["data"]

def get_voucher(self, quantity: int = 1) -> list:
def get_voucher(self, time: int = 30, quantity: int = 1) -> list:
if time not in [30, 365, 730]:
raise ValueError("The duration is invalid.")
return self._request(url=f"{self._api}/user/createVoucher", params={
"time": "30d",
"time": f"{time}d",
"quantity": quantity
})["data"]

Expand All @@ -103,15 +107,20 @@ def get_file_link(self, file_code: str, waiting_token: str = None) -> dict:
def get_file_info(self, file_codes: list) -> list:
return self._request(url=f"{self._api}/link/info", params={"fileCodes": ",".join(file_codes)})["data"]["list"]

def get_public_files(self, folder: str, hash: str, limit: int = 10, offset: int = 0) -> list:
def get_public_folders(self, folder: str, hash: str, limit: int = 10, offset: int = 0) -> list:
return self._request(url=f"{self._api}/user/public", params={
"folder": folder,
"hash": hash,
"limit": limit,
"offset": offset
})["data"]["list"]

def get_public_folders(self, path: str, order: str, dir: str, limit: int = 10, offset: int = 0) -> dict:
def get_public_files(self, path: str, limit: int = 10, offset: int = 0, order: str = "file_name", dir: str = "asc") -> dict:
if order not in ["file_name", "file_size", "file_size", "file_downloads", "transcoded"]:
raise ValueError("Invalid order value.")
if dir not in ["asc", "desc"]:
raise ValueError("Invalid dir value.")

return self._request(url=f"{self._api}/user/files", params={
"path": path,
"limit": limit,
Expand Down Expand Up @@ -187,3 +196,53 @@ def get_pin(self, file_code: str) -> dict:

def check_pin(self, pin: str, hash: str) -> dict:
return self._request(url=f"{self._api}/streaming", params={"pin": pin, "check": hash})["data"]

def transcode(self, file_code: str) -> dict:
return self._request(url=f"{self._api}/upload/transcode/id", params={"file_code": file_code})["data"]

def get_all_files(self) -> list:
return self._request(url=f"{self._api}/user/files/all")["data"]

def add_file(self, file_code: str) -> None:
self._request(url=f"{self._api}/user/file/alias", params={"file_code": file_code})

def get_stream(self, file_code: str) -> list:
KEYS = ["base", "id", "name"]
lines = self._request(url=f"https://uptostream.com/api/streaming/source/get", params={
"file_code": file_code
})["data"]["sources"].split("\n")

items = []
item = {}
for i in range(len(lines)):
if "function baseLink()" in lines[i]:
if item != {}:
items.append(item)
item = {}
item["base"] = lines[i + 1]
elif "function id()" in lines[i]:
item["id"] = lines[i + 1]
elif "function name()" in lines[i]:
item["name"] = lines[i + 1]
elif "var label" in lines[i]:
item["label"] = lines[i]
elif "var kind" in lines[i]:
item["kind"] = lines[i]
elif "var srclang" in lines[i]:
item["lang"] = lines[i]
elif "var format" in lines[i]:
item["format"] = lines[i]
items.append(item)
for i in range(len(items)):
for key in items[i].keys():
items[i][key] = re.search(r'"(.*?)"', items[i][key]).group(1)

if all([key in items[i] for key in KEYS]):
items[i]["link"] = "{base}/stream/{id}/{name}".format(
base=items[i]["base"],
id=items[i]["id"],
name=items[i]["name"]
)
for key in KEYS:
del items[i][key]
return items
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="pyuptobox",
version="1.0.0",
version="1.0.2",
description="Python SDK to interact with Uptobox API.",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 6112871

Please sign in to comment.