def __init__(self, server, password, port, name): """Initialize the CMUS device.""" if server: self.cmus = remote.PyCmus(server=server, password=password, port=port) auto_name = f"cmus-{server}" else: self.cmus = remote.PyCmus() auto_name = "cmus-local" self._name = name or auto_name self.status = {}
def __init__(self, server, password, port, name): """Initialize the CMUS device.""" from pycmus import remote if server: self.cmus = remote.PyCmus(server=server, password=password, port=port) auto_name = "cmus-{}".format(server) else: self.cmus = remote.PyCmus() auto_name = "cmus-local" self._name = name or auto_name self.status = {}
def __init__(self, server, password, port, name): """Initialize the CMUS device.""" from pycmus import remote if server: port = port or 3000 self.cmus = remote.PyCmus(server=server, password=password, port=port) auto_name = "cmus-%s" % server else: self.cmus = remote.PyCmus() auto_name = "cmus-local" self._name = name or auto_name self.status = {} self.update()
def connect(self): """Connect to the cmus server.""" try: self.cmus = remote.PyCmus(server=self._server, port=self._port, password=self._password) except exceptions.InvalidPassword: _LOGGER.error("The provided password was rejected by cmus")
def get_cmus_status(): try: cmus = remote.PyCmus() dict = cmus.get_status_dict() status = dict['status'] if status == 'playing' or status == 'paused': return '{} ({} {} / {})'.format( pathlib.Path(dict['file']).stem, status, convert_seconds_to_sane_time(int(dict['position'])), convert_seconds_to_sane_time(int(dict['duration']))) else: return status except FileNotFoundError: return 'not running' except ConnectionRefusedError: return 'not running'
def main(port=5000, music_folder='music/'): """ Main function. :param int port: port where the server will be :param str music_folder: directory in which the music is """ # Create a new process in which execute cmus try: import subprocess cmus_process = subprocess.Popen(args=["cmus"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) except Exception as err: print('Impossible to open a new cmus instance: {}'.format(err)) finally: # Try to connect to cmus server max_time = 5 start_time = time.time() while True: try: print('Trying to connect to cmus... ', end='') cmus = remote.PyCmus() break except exceptions.CmusNotRunning: if (time.time() - start_time <= max_time): # If connection has been rejected but # the max time hasn't passed, we try # again time.sleep(1) continue else: print( '\nImpossible to connect to cmus. Exiting the program...' ) try: exit_cmus(cmus, cmus_process) except UnboundLocalError: pass finally: sys.exit(1) print('ok\n') # Get the songs we will play import music_extractor songs = music_extractor.MusicExtractor(music_folder) if not (songs.num_songs): print( "There aren't any songs in the chosen directory. Exiting program... " ) exit_cmus(cmus, cmus_process) sys.exit(1) # 'Reboot' cmus init_cmus(cmus, songs.music_folder, songs.songs_list[0][0]) # Open the web server try: from webserver.webapp import MusicControllerWeb flask_object = MusicControllerWeb(__name__, cmus, songs) flask_object.app.run(debug=False, host='0.0.0.0', threaded=True, port=port) except Exception as err: print('Some problem occured: ', end='') print(err) sys.exit('Exiting program...') # We delete the directory with the songs' covers within songs.del_covers_folder() # Before leaving the program, we close # the fork with cmus exit_cmus(cmus, cmus_process)
def __init__(self): self.cmus = remote.PyCmus()
try: r = requests.get(url=url, headers=header).content.decode('latin-1') return BeautifulSoup(r, 'html.parser') except Exception: return None def random_string(string_length=10): """Generate a random string of fixed length """ letters = string.ascii_letters return ''.join(random.choice(letters) for i in range(string_length)) status = None try: cmus = remote.PyCmus() status = cmus.get_status_dict() except FileNotFoundError: exit() cache_folder = pathlib.PosixPath("~/.music_art").expanduser().resolve() cache_file = cache_folder / 'cache.json' with open(str(cache_file), 'r') as f: cache = json.load(f) if status['file'] in cache: print(cache[status['file']]) exit() albumImage = False
def init(port=3000): """Initialize mpd.""" return remote.PyCmus(port=port)
def test_play(self, socket_mock): cmus = remote.PyCmus() with mock.patch.object(cmus, 'send_cmd') as send_mock: cmus.player_play() send_mock.assert_called_once_with('player-play\n')