Skip to content

Commit

Permalink
further fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Safone authored and AsmSafone committed Jun 20, 2024
1 parent 84a59e2 commit 147c235
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pyLint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
commit_user_email: [email protected]
commit_options: '--no-verify'
commit_message: 'auto: refactor'
commit_author: Safone <owner@safone.tech>
commit_author: Safone <safone@safone.dev>
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:latest
FROM python:3.9-slim-buster

# Updating Packages
RUN apt update && apt upgrade -y
Expand All @@ -11,9 +11,14 @@ COPY requirements.txt /requirements.txt
RUN cd /
RUN pip3 install --upgrade pip
RUN pip3 install -U -r requirements.txt

# Setting up working directory
RUN mkdir /MusicPlayer
WORKDIR /MusicPlayer

# Preparing for the Startup
COPY startup.sh /startup.sh
RUN chmod +x /startup.sh

# Running Music Player Bot
CMD ["/bin/bash", "/startup.sh"]
2 changes: 1 addition & 1 deletion core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from core.song import Song
from core.admins import is_sudo, is_admin
from core.stream import app, ydl, safone, pytgcalls, skip_stream, start_stream
from core.stream import app, ytdl, safone, pytgcalls, start_stream
from core.groups import (
get_group, get_queue, set_group, set_title, all_groups, clear_queue,
set_default, shuffle_queue)
Expand Down
2 changes: 1 addition & 1 deletion core/admins.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def is_admin(message: Message):
user = await message.chat.get_member(message.from_user.id)
if user.status in [
enums.ChatMemberStatus.OWNER,
enums.ChatMemberStatus.ADMINISTRATOR
enums.ChatMemberStatus.ADMINISTRATOR,
]:
return True
elif message.from_user.id in config.SUDOERS:
Expand Down
4 changes: 3 additions & 1 deletion core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ async def decorator(client: Client, message: Message, *args):
in [
admin.user.id
async for admin in (
await message.chat.get_members(filter=enums.ChatMembersFilter.ADMINISTRATORS)
await message.chat.get_members(
filter=enums.ChatMembersFilter.ADMINISTRATORS
)
)
]
):
Expand Down
2 changes: 1 addition & 1 deletion core/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import asyncio
import aiofiles
from config import config
from pyrogram import enums
from core.song import Song
from pyrogram import enums
from pytube import Playlist
from spotipy import Spotify
from core.groups import get_group
Expand Down
58 changes: 45 additions & 13 deletions core/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@
"geo_bypass": True,
"nocheckcertificate": True,
}
ydl = YoutubeDL(ydl_opts)
app = Client(config.SESSION, api_id=config.API_ID, api_hash=config.API_HASH)
app = Client(
"MusicPlayerUB",
api_id=config.API_ID,
api_hash=config.API_HASH,
session_string=config.SESSION,
in_memory=True,
)
ytdl = YoutubeDL(ydl_opts)
pytgcalls = PyTgCalls(app)


Expand Down Expand Up @@ -82,9 +88,11 @@ async def start_stream(song: Song, lang):
song.source,
song.duration,
song.request_msg.chat.id,
song.requested_by.mention
if song.requested_by
else song.request_msg.sender_chat.title,
(
song.requested_by.mention
if song.requested_by
else song.request_msg.sender_chat.title
),
),
quote=False,
)
Expand All @@ -98,36 +106,60 @@ def get_quality(song: Song) -> MediaStream:
if group["stream_mode"] == "video":
if config.QUALITY.lower() == "high":
return MediaStream(
song.remote, AudioQuality.HIGH, VideoQuality.FHD_1080p, headers=song.headers
song.remote,
AudioQuality.HIGH,
VideoQuality.FHD_1080p,
headers=song.headers,
)
elif config.QUALITY.lower() == "medium":
return MediaStream(
song.remote, AudioQuality.MEDIUM, VideoQuality.HD_720p, headers=song.headers
song.remote,
AudioQuality.MEDIUM,
VideoQuality.HD_720p,
headers=song.headers,
)
elif config.QUALITY.lower() == "low":
return MediaStream(
song.remote, AudioQuality.LOW, VideoQuality.SD_480p, headers=song.headers
song.remote,
AudioQuality.LOW,
VideoQuality.SD_480p,
headers=song.headers,
)
else:
print("WARNING: Invalid Quality Specified. Defaulting to High!")
return MediaStream(
song.remote, AudioQuality.HIGH, VideoQuality.FHD_1080p, headers=song.headers
song.remote,
AudioQuality.HIGH,
VideoQuality.FHD_1080p,
headers=song.headers,
)
else:
if config.QUALITY.lower() == "high":
return MediaStream(
song.remote, AudioQuality.HIGH, video_flags=MediaStream.Flags.IGNORE, headers=song.headers
song.remote,
AudioQuality.HIGH,
video_flags=MediaStream.Flags.IGNORE,
headers=song.headers,
)
elif config.QUALITY.lower() == "medium":
return MediaStream(
song.remote, AudioQuality.MEDIUM, video_flags=MediaStream.Flags.IGNORE, headers=song.headers
song.remote,
AudioQuality.MEDIUM,
video_flags=MediaStream.Flags.IGNORE,
headers=song.headers,
)
elif config.QUALITY.lower() == "low":
return MediaStream(
song.remote, AudioQuality.LOW, video_flags=MediaStream.Flags.IGNORE, headers=song.headers
song.remote,
AudioQuality.LOW,
video_flags=MediaStream.Flags.IGNORE,
headers=song.headers,
)
else:
print("WARNING: Invalid Quality Specified. Defaulting to High!")
return MediaStream(
song.remote, AudioQuality.HIGH, video_flags=MediaStream.Flags.IGNORE, headers=song.headers
song.remote,
AudioQuality.HIGH,
video_flags=MediaStream.Flags.IGNORE,
headers=song.headers,
)
Loading

0 comments on commit 147c235

Please sign in to comment.