-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
669 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import os | ||
|
||
os.environ["VLC_VERBOSE"] = "-1" | ||
|
||
from radio81.console import start | ||
|
||
# Press the green button in the gutter to run the script. | ||
|
||
|
||
if __name__ == '__main__': | ||
start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from vlc import Meta | ||
|
||
import aiohttp | ||
import asyncio | ||
|
||
from radio81.genres import default_shoutcast_data | ||
from radio81.parser import select_genre, select_station | ||
from radio81.player import load_stations, ShoutCastPlayer, play_station, closePlayer, createShoutCastPlayer | ||
from radio81 import __version__ | ||
|
||
|
||
def logo(): | ||
print() | ||
print('██████╗ █████╗ ██████╗ ██╗ ██████╗ █████╗ ██╗') | ||
print('██╔══██╗██╔══██╗██╔══██╗██║██╔═══██╗ ██╔══██╗███║') | ||
print('██████╔╝███████║██║ ██║██║██║ ██║ ╚█████╔╝╚██║') | ||
print('██╔══██╗██╔══██║██║ ██║██║██║ ██║ ██╔══██╗ ██║') | ||
print('██║ ██║██║ ██║██████╔╝██║╚██████╔╝ ╚█████╔╝ ██║') | ||
print('╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═════╝ ╚════╝ ╚═╝') | ||
print(f'ALPHA {__version__} quit: CTRL+C') | ||
print('----------------------------------------------------') | ||
|
||
|
||
async def console_main(player: ShoutCastPlayer): | ||
logo() | ||
genres = default_shoutcast_data() | ||
selected_genre = await select_genre(genres) | ||
player.genre = selected_genre | ||
|
||
# Should I maintain this client session open? What would it imply? I guess nothing... | ||
async with aiohttp.ClientSession(base_url='https://directory.shoutcast.com') as session: | ||
stations = await load_stations(session, player, player.genre) | ||
station = await select_station(stations) | ||
|
||
try: | ||
media, url = await play_station(player, session, station) | ||
except Exception as e: | ||
print(e) | ||
media = None | ||
|
||
if media is None: | ||
print(f'Error on {station} ({station.id}) - SKIPPED') | ||
else: | ||
|
||
# This is very bad but I can't retrieve the metachanged event from VLC | ||
# So... at the moment I'll stick with this solution | ||
while True: | ||
media_title = media.get_meta(Meta.NowPlaying) | ||
title = media_title if media_title is not None else 'Retrieving title...' | ||
# It must be something better than this, if not the size of the window would change the behaviour | ||
print(f'=> {title}', end='\r') | ||
await asyncio.sleep(5) | ||
|
||
# Are you serious?!?!?!? MediaMetaChanged doesn't work? | ||
# All examples online are with polling :(. Damn... Is it still a bug? | ||
|
||
# print("Press enter for the next Rock station :). Don't you like classic rock? Go back to school...") | ||
|
||
# At the moment this is almost unreachable apart if you pass all the current genre stations :) | ||
closePlayer(player) | ||
|
||
|
||
def start(): | ||
async def start_radio(): | ||
player = createShoutCastPlayer() | ||
|
||
try: | ||
await console_main(player) | ||
except asyncio.CancelledError: | ||
closePlayer(player) | ||
|
||
asyncio.run(start_radio()) |
Oops, something went wrong.