CStdString CScrobbler::GetConnectionState() { if (!CanScrobble()) return ""; return (m_strSessionID.IsEmpty()) ? g_localizeStrings.Get(15208) : g_localizeStrings.Get(15207); }
void CScrobbler::AddSong(const MUSIC_INFO::CMusicInfoTag &tag, bool lastfmradio) { ClearSubmissionState(); if (!CanScrobble() || !tag.Loaded()) return; if (tag.GetArtist().empty() || tag.GetTitle().IsEmpty()) return; // our tags are stored as UTF-8, so no conversion needed m_CurrentTrack.length = tag.GetDuration(); m_CurrentTrack.strArtist = StringUtils::Join(tag.GetArtist(), g_advancedSettings.m_musicItemSeparator); m_CurrentTrack.strAlbum = tag.GetAlbum(); m_CurrentTrack.strTitle = tag.GetTitle(); m_CurrentTrack.strMusicBrainzID = tag.GetMusicBrainzTrackID(); if (lastfmradio) // TODO Set source more appropriately m_CurrentTrack.strSource = "L" + tag.GetComment(); else m_CurrentTrack.strSource = "P"; m_CurrentTrack.strRating = ""; m_CurrentTrack.strLength.Format("%d", m_CurrentTrack.length); m_CurrentTrack.strStartTime.Format("%d", time(NULL)); m_CurrentTrack.strTrackNum.Format("%d",tag.GetTrackNumber()); CURL::Encode(m_CurrentTrack.strArtist); CURL::Encode(m_CurrentTrack.strTitle); CURL::Encode(m_CurrentTrack.strAlbum); CURL::Encode(m_CurrentTrack.strMusicBrainzID); m_bNotified = false; m_bSubmitted = !((lastfmradio && g_guiSettings.GetBool("scrobbler.lastfmsubmitradio")) || (!lastfmradio && g_guiSettings.GetBool("scrobbler.lastfmsubmit") && (m_CurrentTrack.length > SCROBBLER_MIN_DURATION || !m_CurrentTrack.strMusicBrainzID.IsEmpty()))); }
void CScrobbler::Init() { if (!CanScrobble()) return; ResetState(); LoadCredentials(); LoadJournal(); if (!IsRunning()) Create(); }
CStdString CScrobbler::GetFilesCached() { CStdString strCachedTracks; if (!CanScrobble()) return strCachedTracks; CSingleLock lock(m_queueLock); CStdString strFormat = g_localizeStrings.Get(15210); strCachedTracks.Format(strFormat, m_vecSubmissionQueue.size()); return strCachedTracks; }
CStdString CScrobbler::GetSubmitInterval() { CStdString strInterval; if (!CanScrobble()) return strInterval; CStdString strFormat = g_localizeStrings.Get(15209); int seconds = m_CurrentTrack.length - m_submissionTimer/2; strInterval.Format(strFormat, std::max(seconds, m_failedHandshakeDelay)); return strInterval; }
void CScrobbler::Init() { if (!CanScrobble()) return; ResetState(); LoadCredentials(); LoadJournal(); if (!ThreadHandle()) Create(); }
void CScrobbler::SubmitQueue() { if (CanScrobble()) { { CSingleLock lock(m_actionLock); m_action = SCROBBLER_ACTION_SUBMIT; } m_hEvent.Set(); } }
CStdString CScrobbler::GetSubmitState() { CStdString strState; CStdString strFormat = g_localizeStrings.Get(15212); if (!CanScrobble()) return strState; if (m_bSubmitting) strState = g_localizeStrings.Get(15211); else if (!g_application.IsPlayingAudio() || m_bBadAuth || m_bBanned) strState.Format(strFormat, 0); else if (m_strSessionID.IsEmpty()) strState.Format(strFormat, m_failedHandshakeDelay); else { int seconds = m_CurrentTrack.length - m_submissionTimer/2; strState.Format(strFormat, std::max(0, seconds)); } return strState; }
void CScrobbler::UpdateStatus() { // Called from CApp::ProcessSlow() every ~500ms. if (!CanScrobble()) return; if (g_application.IsPaused() || (g_application.GetPlaySpeed() != 1)) return; m_submissionTimer++; // Try to notify Last.fm of our currently playing after ~5s of playback. // Don't try too hard, this is optional and doesn't affect the users library. if (!m_bNotified && m_submissionTimer >= 10) { m_bNotified = true; // Only try once { CSingleLock lock(m_actionLock); m_action = SCROBBLER_ACTION_NOWPLAYING; } m_hEvent.Set(); return; } // Scrobble the track after 50% playback or 240s, whichever occurs first. // Just toss it in the queue here. We'll try to submit the queue at the // end of playback. if (!m_bSubmitted && (m_submissionTimer > m_CurrentTrack.length || m_submissionTimer >= 480)) { CSingleLock lock(m_queueLock); m_bSubmitted = true; m_vecSubmissionQueue.push_back(m_CurrentTrack); lock.Leave(); SaveJournal(); CLog::Log(LOGDEBUG, "%s: Queued track for submission", m_strLogPrefix.c_str()); } }