def lfm_logout(self): self.__class__.storage.config_set('apis/last.fm/username', None) self.__class__.storage.config_set('apis/last.fm/session_key', None) self.__class__._lfm_network = None self.current = None interface = harkfm.Interface() interface.login()
def save_settings(self, form): form = json.loads(form) storage = harkfm.Storage() for key in form: if type(form[key]) is str and form[key].isdigit(): form[key] = int(form[key]) storage.config_set('settings/' + key, form[key]) interface = harkfm.Interface() interface.index()
def __init__(self, props=None): if props is None: props = {} if self.__class__.storage is None: self.__class__.storage = harkfm.Storage() if self.__class__.engine is None: self.__class__.engine = harkfm.Engine() if self.__class__.interface is None: self.__class__.interface = harkfm.Interface() if self.__class__.logger is None: self.__class__.logger = logging.getLogger('root') self.app = None self._artist = None self._artist_corrected = None self.artist_img = None self.artist_url = None self.artist_wiki = None self.artist_listeners = 0 self.artist_plays_global = 0 self.artist_plays = 0 self.artist_tags = [] self.artist_similar = [] self.artist_gender = None self.artist_country = None self._track = None self._track_corrected = None self.track_url = None self.track_wiki = None self.track_duration = 3 * 60 # default tracks to 3 minutes self.track_plays = 0 self.track_tags = [] self.track_loved = None self._album = None self._album_corrected = None self.album_img = None self.album_url = None self.album_wiki = None self.album_year = 0 self.start = 0 self.listened = 0 self.queued = 0 self._corrected_gn = False self._corrected_lfm = False for prop in props.keys(): setattr(self, prop, props[prop])
def login(self, query): form = self._deserialize(query) storage = harkfm.Storage() api_key = harkfm.Engine.config['apis']['last.fm']['key'] api_secret = harkfm.Engine.config['apis']['last.fm']['secret'] try: network = pylast.get_lastfm_network(api_key, api_secret) session_key = pylast.SessionKeyGenerator(network).get_session_key(form['username'], pylast.md5(form['password'])) storage.config_set('apis/last.fm/session_key', session_key) interface = harkfm.Interface() interface.index() except Exception as e: harkfm.Interface.logger.error('%s %s', type(e), e)
def current(self, value): if value != self.__class__._current: old = self.__class__._current self.__class__._current = value if self.__class__._current is not None: self.__class__._current.start = int(time.time()) self.__class__._current.correct() if self.__class__._lfm_network is not None: # Song has changed if value != old: self.tts() self.scrobble() # Re-render index if visible interface = harkfm.Interface() interface.index()
import harkfm formatter = logging.Formatter( fmt= '[%(asctime)s] [%(levelname).4s] [%(filename)s:%(lineno)03d] %(message)s', datefmt='%H:%M:%S') handler = logging.StreamHandler() handler.setFormatter(formatter) logger = logging.getLogger('root') logger.setLevel(logging.INFO) logger.addHandler(handler) app = QApplication(sys.argv) window = QMainWindow(flags=Qt.Window) ui = PyQt5.uic.loadUi( os.path.join(os.path.dirname(sys.argv[0]), 'harkfm/interface.ui'), window) # Init the interface interface = harkfm.Interface(window, ui) # Start track scanner scanner = harkfm.Scanner() window.show() exit_code = app.exec_() if exit_code == 0: engine = harkfm.Engine() engine.scrobble() while engine.scrobbling: time.sleep(0.1) sys.exit(exit_code)
def unlove(self): engine.current.unlove() interface = harkfm.Interface() interface.index()