Exemple #1
0
    def retry_queue(self):

        self.logger.info('Retrying scrobble cache.')
        a = True
        lastfm = LastFm(self.config)

        for key in self.cache:
            # do submissions retry
            try:
                a = lastfm.scrobble(self.cache[key][0], self.cache[key][1],
                                    self.cache[key][3])
                self.cache[key][2] += 1
            except:
                pass

            # if it was a failed submission
            if not a:
                # remove this record from retry cache, if we're at the retry limit
                if self.cache[key][2] >= MAX_CACHE_AGE:
                    self.logger.info(
                        u'MAX_CACHE_AGE for {key} : {artist} - {track}'.format(
                            key, self.cache[key][0], self.key[1]))
                    self.remove(key)
            else:
                # successful send to last.fm, remove from cache
                self.remove(key)
    def retry_queue(self):

        self.logger.info('Retrying scrobble cache.')
        a = True
        lastfm = LastFm(self.config)

        for key in self.cache:
            # do submissions retry
            try:
                a = lastfm.scrobble(self.cache[key][0], self.cache[key][1],
                        self.cache[key][3])
                self.cache[key][2] += 1
            except:
                pass

            # if it was a failed submission
            if not a:
                # remove this record from retry cache, if we're at the retry limit
                if self.cache[key][2] >= MAX_CACHE_AGE:
                    self.logger.info(u'MAX_CACHE_AGE for {key} : {artist} - {track}'.format(
                        key, self.cache[key][0], self.key[1]))
                    self.remove(key)
            else:
                # successful send to last.fm, remove from cache
                self.remove(key)
Exemple #3
0
def scrobble():
    status, res = get_entity(request, Track)
    if not status:
        return res

    t, submission = map(request.args.get, ['time', 'submission'])

    if t:
        try:
            t = int(t) / 1000
        except:
            return request.error_formatter(0, 'Invalid time value')
    else:
        t = int(time.time())

    lfm = LastFm(request.user, app.logger)

    if submission in (None, '', True, 'true', 'True', 1, '1'):
        lfm.scrobble(res, t)
    else:
        lfm.now_playing(res)

    return request.formatter({})
Exemple #4
0
def scrobble():
	status, res = get_entity(request, Track)
	if not status:
		return res

	t, submission = map(request.args.get, [ 'time', 'submission' ])

	if t:
		try:
			t = int(t) / 1000
		except:
			return request.error_formatter(0, 'Invalid time value')
	else:
		t = int(time.time())

	lfm = LastFm(request.user, app.logger)

	if submission in (None, '', True, 'true', 'True', 1, '1'):
		lfm.scrobble(res, t)
	else:
		lfm.now_playing(res)

	return request.formatter({})
def monitor_log(config):

    logger = logging.getLogger(__name__)
    st_mtime = False
    last_played = None

    try:
        f = open(config.get('plex-scrobble', 'mediaserver_log_location'))
    except IOError:
        logger.error('Unable to read log-file {0}. Shutting down.'.format(config.get(
          'plex-scrobble', 'mediaserver_log_location')))
        return
    f.seek(0, 2)

    account_name = config.get('plex-scrobble', 'account_name')

    while True:

        time.sleep(.03)

        # reset our file handle in the event the log file was not written to
        # within the last 60 seconds. This is a very crude attempt to support
        # the log file i/o rotation detection cross-platform.
        if int(time.time()) - int(os.fstat(f.fileno()).st_mtime) >= 60:

            if int(os.fstat(f.fileno()).st_mtime) == st_mtime: continue

            logger.debug('Possible log file rotation, resetting file handle (st_mtime={mtime})'.format(
                mtime=time.ctime(os.fstat(f.fileno()).st_mtime) ))
            f.close()

            try:
                f = open(config.get('plex-scrobble', 'mediaserver_log_location'))
            except IOError:
                logger.error('Unable to read log-file {0}. Shutting down.'.format(config.get(
                  'plex-scrobble', 'mediaserver_log_location')))
                return

            f.seek(0, 2)
            st_mtime = int(os.fstat(f.fileno()).st_mtime)

        line = f.readline()

        # read all new lines starting at the end. We attempt to match
        # based on a regex value. If we have a match, extract the media file
        # id and send it off to last.fm for scrobble.
        if line:
            played = parse_line(line, account_name)

            if not played: continue

            # when playing via a client, log lines are duplicated (seen via iOS)
            # this skips dupes. Note: will also miss songs that have been repeated
            if played == last_played:
                logger.warn('Dupe detection : {0}, not submitting'.format(last_played))
                continue

            metadata = fetch_metadata(played, config)

            if not metadata: continue

            # submit to last.fm
            lastfm = LastFm(config)
            a = lastfm.scrobble(metadata['artist'], metadata['track'],
                    metadata['album'])

            # scrobble was not successful , add to our retry queue
            if not a:
                cache = ScrobbleCache(config)
                cache.add(metadata['artist'], metadata['track'], metadata['album'])
                cache.close

            last_played = played
Exemple #6
0
def monitor_log(config):

    logger = logging.getLogger(__name__)
    st_mtime = False
    last_played = None

    try:
        f = open(config.get('plex-scrobble', 'mediaserver_log_location'))
    except IOError:
        logger.error('Unable to read log-file {0}. Shutting down.'.format(
            config.get('plex-scrobble', 'mediaserver_log_location')))
        return
    f.seek(0, 2)

    while True:

        time.sleep(.03)

        # reset our file handle in the event the log file was not written to
        # within the last 60 seconds. This is a very crude attempt to support
        # the log file i/o rotation detection cross-platform.
        if int(time.time()) - int(os.fstat(f.fileno()).st_mtime) >= 60:

            if int(os.fstat(f.fileno()).st_mtime) == st_mtime: continue

            logger.debug(
                'Possible log file rotation, resetting file handle (st_mtime={mtime})'
                .format(mtime=time.ctime(os.fstat(f.fileno()).st_mtime)))
            f.close()

            try:
                f = open(
                    config.get('plex-scrobble', 'mediaserver_log_location'))
            except IOError:
                logger.error(
                    'Unable to read log-file {0}. Shutting down.'.format(
                        config.get('plex-scrobble',
                                   'mediaserver_log_location')))
                return

            f.seek(0, 2)
            st_mtime = int(os.fstat(f.fileno()).st_mtime)

        line = f.readline()

        # read all new lines starting at the end. We attempt to match
        # based on a regex value. If we have a match, extract the media file
        # id and send it off to last.fm for scrobble.
        if line:
            played = parse_line(line)

            if not played: continue

            # when playing via a client, log lines are duplicated (seen via iOS)
            # this skips dupes. Note: will also miss songs that have been repeated
            if played == last_played:
                logger.warn(
                    'Dupe detection : {0}, not submitting'.format(last_played))
                continue

            metadata = fetch_metadata(played, config)

            if not metadata: continue

            # submit to last.fm
            lastfm = LastFm(config)
            a = lastfm.scrobble(metadata['artist'], metadata['track'],
                                metadata['album'])

            # scrobble was not successful , add to our retry queue
            if not a:
                cache = ScrobbleCache(config)
                cache.add(metadata['artist'], metadata['track'],
                          metadata['album'])
                cache.close

            last_played = played