How to use the pylast.LastFMNetwork function in pylast

To help you get started, we’ve selected a few pylast examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ioggstream / iposonic / test / test_scrobble.py View on Github external
def test_get_album_1():
    network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=
                                   API_SECRET, username=lastfm_user.get('username'), password_hash=pylast.md5(lastfm_user.get('password')))

    top_albums = [(x.item.title, x.item.artist.name)
                  for x in u.get_top_albums()]
    top_albums = [(x.item.title, x.item.artist.name)
                  for x in u.get_top_albums()]
github ioggstream / iposonic / test / test_scrobble.py View on Github external
# scrobble playground (for now)
#
from __future__ import unicode_literals
from nose import *
import time
import pylast
from test_iposonic import harn_setup

API_KEY = "b725246f2c3e1738153c656928483570"
API_SECRET = "e08b9a80defa4ccd9fda4d4e89d5eb19"

username = "ioggstream"
password = "secret"
password_hash = pylast.md5(password)

network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=
                               API_SECRET, username=username, password_hash=password_hash)


def test_get_user():
    u = network.get_user('ioggstream')
    u.get_library()
    u.get_country()
    u.get_neighbours()
    u.get_loved_tracks()
    u.get_top_artists()
    u.get_url()
    u.get_top_tags()
    u.get_top_albums()
    u.get_friends()
    u.get_name()
    u.get_playlists()
github BlackLight / platypush / platypush / plugins / lastfm / __init__.py View on Github external
:param username: Last.FM username
        :type api_key: str

        :param password: Last.FM password, used to sign the requests
        :type api_key: str
        """

        import pylast
        super().__init__()

        self.api_key = api_key
        self.api_secret = api_secret
        self.username = username
        self.password = password

        self.lastfm = pylast.LastFMNetwork(
            api_key = self.api_key,
            api_secret = self.api_secret,
            username = self.username,
            password_hash = pylast.md5(self.password))
github paurieraf / musicbucket-bot / src / bot / music / lastfm.py View on Github external
def __init__(self):
        self.network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET)
github jesseward / plex-lastfm-scrobbler / plex_scrobble / scrobble_cache.py View on Github external
def retry_queue(self):

        self.logger.info('Retrying scrobble cache.')

        for key in self.cache:
            # do submissions retry
            try:
                self.cache[key][2] += 1
                lastfm = pylast.LastFMNetwork(
                    api_key=self.api_key,
                    api_secret=self.api_secret,
                    username=self.user_name,
                    password_hash=pylast.md5(self.password))
                lastfm.scrobble(self.cache[key][0],
                                self.cache[key][1],
                                timestamp=int(time.time()),
                                album=self.cache[key][3])
            except:
                self.logger.warning('Failed to resubmit artist={artist}, title={title}, album={album}, age={age}'.format(
                    artist=self.cache[key][0],
                    title=self.cache[key][1],
                    album=self.cache[key][3],
                    age=self.cache[key][2]))
                if self.cache[key][2] >= ScrobbleCache.MAX_CACHE_AGE:
                    self.logger.info('MAX_CACHE_AGE for {key} : {artist} - {title}'.format(key=key, artist=self.cache[key][0], title=self.cache[key][1]))
github tetrapus / Karkat / plugins / web / lastfm.py View on Github external
self.userfile = server.get_config_dir(self.FILENAME)
        try:
            self.users = json.load(open(self.userfile))
        except:
            # File doesn't exist or is corrupt
            os.makedirs(server.get_config_dir(), exist_ok=True)
            self.users = {}
            self.savefile()

        self.compare_file = server.get_config_dir(self.COMPARE_FILE)

        if not os.path.exists(self.compare_file):
            with open(self.compare_file, "w") as conf:
                conf.write("{}")

        self.network = pylast.LastFMNetwork(
            api_key    = apikeys["key"],
            api_secret = apikeys["secret"]
        )

        self.lastcompare = 0
        super().__init__(server)
github mps-youtube / mps-youtube / mps_youtube / commands / lastfm.py View on Github external
g.message = '"pylast" module not found\n see %s' % (pylast_url)
        return

    # TODO: Add option to read lastfm config from file or env variable
    key = config.LASTFM_API_KEY.get
    secret = config.LASTFM_API_SECRET.get
    password = config.LASTFM_PASSWORD.get # already hashed
    username = config.LASTFM_USERNAME.get

    if not (key and secret and password and username):
        if verbose:
            util.xprint("Not all Last.fm credentials were set.")
        return

    try:
        g.lastfm_network = pylast.LastFMNetwork(api_key=key, api_secret=secret,
                                                username=username,
                                                password_hash=password)
        if verbose:
            g.message = "Last.fm authentication successful!"
    except (pylast.WSError, pylast.MalformedResponseError, pylast.NetworkError):
        if verbose:
            g.message = "Last.fm connection error: %s" % (str(e))
github vintasoftware / hub.rocks / tracks / mixins.py View on Github external
def scrobble(self, artist, title, timestamp=None):
        if timestamp is None:
            timestamp = int(time.time())

        if settings.LASTFM_API_KEY and self.establishment.lastfm_username:
            network = pylast.LastFMNetwork(
                api_key=settings.LASTFM_API_KEY,
                api_secret=settings.LASTFM_API_SECRET,
                username=self.establishment.lastfm_username,
                password_hash=self.establishment.lastfm_hashed_password)

            network.scrobble(artist=artist, title=title, timestamp=timestamp)
        else:
            logging.info("last.fm not setup, would scrobble {} for {}".format(
                         title, self.establishment.username))
github home-assistant / home-assistant / homeassistant / components / sensor / lastfm.py View on Github external
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Last.fm sensor platform."""
    import pylast as lastfm
    from pylast import WSError

    api_key = config[CONF_API_KEY]
    users = config.get(CONF_USERS)

    lastfm_api = lastfm.LastFMNetwork(api_key=api_key)

    entities = []
    for username in users:
        try:
            lastfm_api.get_user(username).get_image()
            entities.append(LastfmSensor(username, lastfm_api))
        except WSError as error:
            _LOGGER.error(error)
            return

    add_entities(entities, True)
github exaile / exaile / plugins / lastfmlove / lastfmlove_preferences.py View on Github external
def check_connection(self):
        """
            Checks API key and secret for validity
            and opens the URI for access permission
        """
        api_key = settings.get_option('plugin/lastfmlove/api_key', 'K')

        try:
            pylast.LastFMNetwork(
                api_key=api_key,
                api_secret=settings.get_option('plugin/lastfmlove/api_secret', 'S'),
                username=settings.get_option('plugin/ascrobbler/user', ''),
                password_hash=settings.get_option('plugin/ascrobbler/password', ''),
            )
        except pylast.WSError as e:
            GLib.idle_add(
                self.message.show_error,
                self.errors[int(e.get_id())],
                _('Please make sure the entered data is correct.'),
            )
        else:
            application_launched = Gtk.show_uri(
                Gdk.Screen.get_default(),
                'http://www.last.fm/api/auth?api_key={0}'.format(api_key),
                Gdk.CURRENT_TIME,