Skip to content

Commit

Permalink
Release 0.3.0
Browse files Browse the repository at this point in the history
- Added `URLIO`
  • Loading branch information
romanin-rf committed Dec 6, 2024
1 parent 69b7a1c commit 8623bf4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "seaplayer-audio"
version = "0.2.0"
version = "0.3.0"
description = "A library for async/sync playback audio."
repository = "https://github.com/romanin-rf/seaplayer-audio"
authors = ["Romanin <[email protected]>"]
Expand Down
20 changes: 7 additions & 13 deletions seaplayer_audio/audiosources/urlio.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from urllib.request import urlopen
from tempfile import TemporaryFile
from io import IOBase, BufferedReader, BytesIO, DEFAULT_BUFFER_SIZE
from io import BufferedReader, BytesIO, DEFAULT_BUFFER_SIZE
from typing_extensions import (
Iterable,
Self,
Literal, Optional,
Literal, Optional,
NoReturn, deprecated
)
from .._types import URLOpenRet

# ! URL IO Class
class URLIO(BufferedReader):
# ^ Hidden init methods

def __open_buffer(self, buffer_type: Literal['temp', 'mem']) -> BufferedReader:
if buffer_type == 'mem':
return BytesIO()
elif buffer_type == 'temp':
return TemporaryFile('wb+')
return TemporaryFile('wb+', delete=True, delete_on_close=True)
raise ValueError(buffer_type)

def __getsize(self) -> int:
ct = self.tell()
size = self.__buffer.seek(0, 2)
Expand Down Expand Up @@ -57,7 +57,7 @@ def __read_preparation(self, size: int) -> None:
self.__fullload()

def __seek_preparation(self, offset: int, whence: int) -> None:
if (not self.__full) and (offset > 0):
if (not self.__full) and (offset >= 0):
if whence == 0:
s = self.__getsize() - offset
if s > 0:
Expand Down Expand Up @@ -91,15 +91,9 @@ def __init__(
self.__stream: URLOpenRet = urlopen(self.__url)
self.__buffer = self.__open_buffer(self.__buffer_type)
self.__full = False
print(f"[ DIR ]: {dir(self)}")

# ^ Magic Methods

def __getattribute__(self, item: str):
__class_name__ = super().__getattribute__('__class__').__name__
print(f'[ CALL ]: {__class_name__}.{item}')
return super().__getattribute__(item)

def __del__(self) -> None:
if self.closefd and (not self.closed):
self.close()
Expand Down Expand Up @@ -139,7 +133,7 @@ def closefd(self) -> bool:

@property
def length(self) -> Optional[int]:
if hasattr(self.__stream):
if hasattr(self.__stream, 'length'):
if isinstance(self.__stream.length, int):
return self.__stream.length
return None
Expand Down

0 comments on commit 8623bf4

Please sign in to comment.