mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Refactor Voice and Audio
This commit is contained in:
parent
1c4dd13e72
commit
905f4b8e62
@ -16,7 +16,12 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from struct import pack
|
||||||
|
|
||||||
|
from pyrogram.api import types
|
||||||
from pyrogram.api.core import Object
|
from pyrogram.api.core import Object
|
||||||
|
from .photo_size import PhotoSize
|
||||||
|
from ...ext.utils import encode
|
||||||
|
|
||||||
|
|
||||||
class Audio(Object):
|
class Audio(Object):
|
||||||
@ -53,18 +58,10 @@ class Audio(Object):
|
|||||||
|
|
||||||
ID = 0xb0700006
|
ID = 0xb0700006
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, file_id: str, duration: int, *,
|
||||||
self,
|
thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||||
file_id: str,
|
performer: str = None, title: str = None,
|
||||||
duration: int,
|
client=None, raw=None):
|
||||||
thumb=None,
|
|
||||||
file_name: str = None,
|
|
||||||
mime_type: str = None,
|
|
||||||
file_size: int = None,
|
|
||||||
date: int = None,
|
|
||||||
performer: str = None,
|
|
||||||
title: str = None
|
|
||||||
):
|
|
||||||
self.file_id = file_id
|
self.file_id = file_id
|
||||||
self.thumb = thumb
|
self.thumb = thumb
|
||||||
self.file_name = file_name
|
self.file_name = file_name
|
||||||
@ -74,3 +71,30 @@ class Audio(Object):
|
|||||||
self.duration = duration
|
self.duration = duration
|
||||||
self.performer = performer
|
self.performer = performer
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|
||||||
|
self._client = client
|
||||||
|
self._raw = raw
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def parse(client, audio: types.Document, audio_attributes: types.DocumentAttributeAudio, file_name: str) -> "Audio":
|
||||||
|
return Audio(
|
||||||
|
file_id=encode(
|
||||||
|
pack(
|
||||||
|
"<iiqq",
|
||||||
|
9,
|
||||||
|
audio.dc_id,
|
||||||
|
audio.id,
|
||||||
|
audio.access_hash
|
||||||
|
)
|
||||||
|
),
|
||||||
|
duration=audio_attributes.duration,
|
||||||
|
performer=audio_attributes.performer,
|
||||||
|
title=audio_attributes.title,
|
||||||
|
mime_type=audio.mime_type,
|
||||||
|
file_size=audio.size,
|
||||||
|
thumb=PhotoSize.parse(client, audio.thumb),
|
||||||
|
file_name=file_name,
|
||||||
|
date=audio.date,
|
||||||
|
client=client,
|
||||||
|
raw=audio
|
||||||
|
)
|
||||||
|
@ -16,7 +16,10 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from pyrogram.api import types
|
||||||
from pyrogram.api.core import Object
|
from pyrogram.api.core import Object
|
||||||
|
from ...ext.utils import encode
|
||||||
|
from struct import pack
|
||||||
|
|
||||||
|
|
||||||
class Voice(Object):
|
class Voice(Object):
|
||||||
@ -44,17 +47,36 @@ class Voice(Object):
|
|||||||
|
|
||||||
ID = 0xb0700009
|
ID = 0xb0700009
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, file_id: str, duration: int, *,
|
||||||
self,
|
waveform: bytes = None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||||
file_id: str,
|
client=None, raw=None):
|
||||||
duration: int,
|
|
||||||
waveform: bytes = None,
|
|
||||||
mime_type: str = None,
|
|
||||||
file_size: int = None,
|
|
||||||
date: int = None):
|
|
||||||
self.file_id = file_id
|
self.file_id = file_id
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
self.waveform = waveform
|
self.waveform = waveform
|
||||||
self.mime_type = mime_type
|
self.mime_type = mime_type
|
||||||
self.file_size = file_size
|
self.file_size = file_size
|
||||||
self.date = date
|
self.date = date
|
||||||
|
|
||||||
|
self._client = client
|
||||||
|
self._raw = raw
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def parse(client, voice: types.Document, attributes: types.DocumentAttributeAudio) -> "Voice":
|
||||||
|
return Voice(
|
||||||
|
file_id=encode(
|
||||||
|
pack(
|
||||||
|
"<iiqq",
|
||||||
|
3,
|
||||||
|
voice.dc_id,
|
||||||
|
voice.id,
|
||||||
|
voice.access_hash
|
||||||
|
)
|
||||||
|
),
|
||||||
|
duration=attributes.duration,
|
||||||
|
mime_type=voice.mime_type,
|
||||||
|
file_size=voice.size,
|
||||||
|
waveform=attributes.waveform,
|
||||||
|
date=voice.date,
|
||||||
|
client=client,
|
||||||
|
raw=voice
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user