Skip to content

Commit

Permalink
Isn't it
Browse files Browse the repository at this point in the history
  • Loading branch information
corzani committed Nov 25, 2021
1 parent 75ea684 commit f7dd5d3
Show file tree
Hide file tree
Showing 9 changed files with 669 additions and 172 deletions.
11 changes: 7 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ license = MIT
license_files = LICENSE.txt
long_description = file: README.rst
long_description_content_type = text/x-rst; charset=UTF-8
url = https://github.com/pyscaffold/pyscaffold/
url = https://github.com/corzani/radio_81
# Add here related links, for example:
project_urls =
Documentation = https://pyscaffold.org/
# Documentation = https://pyscaffold.org/
# Source = https://github.com/pyscaffold/pyscaffold/
# Changelog = https://pyscaffold.org/en/latest/changelog.html
# Tracker = https://github.com/pyscaffold/pyscaffold/issues
Expand Down Expand Up @@ -49,6 +49,9 @@ package_dir =
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.8"
aiohttp==3.8.1
python-vlc==3.0.12118
inquirerpy~=0.3.0


[options.packages.find]
Expand All @@ -69,8 +72,8 @@ testing =

[options.entry_points]
# Add here console scripts like:
# console_scripts =
# script_name = radio81.module:function
console_scripts =
script_name = radio81.main:main
# For example:
# console_scripts =
# fibonacci = radio81.skeleton:run
Expand Down
11 changes: 11 additions & 0 deletions src/radio81/__main__.py
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()
72 changes: 72 additions & 0 deletions src/radio81/console.py
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())
Loading

0 comments on commit f7dd5d3

Please sign in to comment.