Skip to content

Commit

Permalink
Trying to fix issue 32
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelSolVargas committed Jan 22, 2023
1 parent 10e38a8 commit a72c4c7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
4 changes: 3 additions & 1 deletion HEROKU.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h1 align="center">Configuring Heroku</h1>

Nobody wants to run the Vulkan process on their machine, so we host the process on Heroku, a cloud platform that contains free accounts.<br>
> Heroku doesn't offer free services anymore
Nobody wants to run the Vulkan process on their machine, so we host the process on Heroku, <s>a cloud platform that contains free</s>.<br>
To configure the Vulkan to run in your Heroku account you will need to:

- Create an application project in Heroku.
Expand Down
21 changes: 15 additions & 6 deletions Handlers/PlayHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ async def run(self, track: str) -> HandlerResponse:

return response
else: # If multiple songs added
# If more than 10 songs, download and load the first 5 to start the play right away
if len(songs) > 10:
fiveFirstSongs = songs[0:5]
songs = songs[5:]
await self.__downloadSongsAndStore(fiveFirstSongs, processInfo)

# Trigger a task to download all songs and then store them in the process playlist
asyncio.create_task(self.__downloadSongsAndStore(songs, processInfo))

Expand All @@ -92,13 +98,10 @@ async def run(self, track: str) -> HandlerResponse:
embed = self.embeds.DOWNLOADING_ERROR()
return HandlerResponse(self.ctx, embed, error)
except Exception as error:
print(f'ERROR IN PLAYHANDLER -> {traceback.format_exc()}', {type(error)})
if isinstance(error, VulkanError): # If error was already processed
print(
f'DEVELOPER NOTE -s> PlayController Error: {traceback.format_exc()}', {type(error)})
embed = self.embeds.CUSTOM_ERROR(error)
else:
print(
f'DEVELOPER NOTE -> PlayController Error: {traceback.format_exc()}, {type(error)}')
error = UnknownError()
embed = self.embeds.UNKNOWN_ERROR()

Expand All @@ -108,13 +111,19 @@ async def __downloadSongsAndStore(self, songs: List[Song], processInfo: ProcessI
playlist = processInfo.getPlaylist()
queue = processInfo.getQueueToPlayer()
playCommand = VCommands(VCommandsType.PLAY, None)
tooManySongs = len(songs) > 100

# Trigger a task for each song to be downloaded
tasks: List[asyncio.Task] = []
for song in songs:
for index, song in enumerate(songs):
# If there is a lot of songs being downloaded, force a sleep to try resolve the Http Error 429 "To Many Requests"
# Trying to fix the issue https://github.com/RafaelSolVargas/Vulkan/issues/32
if tooManySongs and index % 3 == 0:
await asyncio.sleep(0.5)
task = asyncio.create_task(self.__down.download_song(song))
tasks.append(task)

# In the original order, await for the task and then if successfully downloaded add in the playlist
# In the original order, await for the task and then, if successfully downloaded, add to the playlist
processManager = self.config.getProcessManager()
for index, task in enumerate(tasks):
await task
Expand Down
2 changes: 2 additions & 0 deletions Music/Downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def __download_title(self, title: str) -> dict:
return {}

if self.__is_multiple_musics(extracted_info):
if len(extracted_info['entries']) == 0:
return {}
return extracted_info['entries'][0]
else:
print(f'DEVELOPER NOTE -> Failed to extract title {title}')
Expand Down
7 changes: 4 additions & 3 deletions Music/Song.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self, identifier: str, playlist, requester: str) -> None:
self.__playlist = playlist

def finish_down(self, info: dict) -> None:
if info is None:
if info is None or info == {}:
self.destroy()
return None

Expand All @@ -20,7 +20,8 @@ def finish_down(self, info: dict) -> None:
if key in info.keys():
self.__info[key] = info[key]
else:
print(f'DEVELOPER NOTE -> {key} not found in info of music: {self.identifier}')
print(
f'DEVELOPER NOTE -> Required information [{key}] was not found in the music: {self.identifier}')
self.destroy()
return

Expand Down Expand Up @@ -64,7 +65,7 @@ def problematic(self) -> bool:
return self.__problematic

def destroy(self) -> None:
print(f'DEVELOPER NOTE -> Music self destroying {self.__identifier}')
print(f'MUSIC ERROR -> Music self destroying {self.__identifier}')
self.__problematic = True
self.__playlist.destroy_song(self)

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ The config file is located at ```./config/Configs.py```, it doesn't require any
<hr>
<br>

## **🚀 Heroku**
## **🚀 Heroku (Not free anymore)**
> *Heroku doesn't offer free host services anymore.* <br>
To deploy and run your Bot in Heroku 24/7, follow the instructions in the [Heroku Instructions](HEROKU.md) page.

## 🧪 Tests
Expand Down
Binary file modified requirements.txt
Binary file not shown.

0 comments on commit a72c4c7

Please sign in to comment.