static gpointer
soundmenu_lastfm_now_playing_thread (gpointer userdata)
{
	gint rv;

	LastfmData *data = userdata;
	SoundmenuPlugin *soundmenu = data->soundmenu;
	SoundmenuLastfm *lastfm = soundmenu->clastfm;

	rv = LASTFM_track_update_now_playing (lastfm->session_id,
	                                      data->title,
	                                      data->album ? data->album : "",
	                                      data->artist,
	                                      data->length,
	                                      data->track_no,
	                                      0, NULL);

	if (rv != 0) {
		g_critical("Update current song on Last.fm failed");
	}

	soundmenu_lastfm_data_free (data);

	return NULL;
}
Ejemplo n.º 2
0
      bool cSession::ScrobbleOrUpdateTrack(const cMetaData& metaData, bool bScrobble)
      {
        std::cout<<"cSession::ScrobbleOrUpdateTrack "<<metaData.sArtist<<" - "<<metaData.sTitle<<std::endl;

        if (!IsLoggedIn()) {
          std::cerr<<"cSession::ScrobbleOrUpdateTrack Error not logged in to LastFM"<<std::endl;
          return false;
        }

        const std::string sArtistUTF8 = spitfire::string::ToUTF8(metaData.sArtist);
        const std::string sTitleUTF8 = spitfire::string::ToUTF8(metaData.sTitle);
        const std::string sAlbumUTF8 = spitfire::string::ToUTF8(metaData.sAlbum);

        char* szArtistUTF8 = new char[sArtistUTF8.length() + 1];
        strcpy(szArtistUTF8, sArtistUTF8.c_str());
        char* szTitleUTF8 = new char[sTitleUTF8.length() + 1];
        strcpy(szTitleUTF8, sTitleUTF8.c_str());
        char* szAlbumUTF8 = new char[sAlbumUTF8.length() + 1];
        strcpy(szAlbumUTF8, sAlbumUTF8.c_str());

        const uint64_t uiLengthSeconds = metaData.uiDurationMilliSeconds / 1000;

        int iResult = -1;

        if (bScrobble) {
          /*time_t rawtime;
          time(&rawtime);

          tm* ptm = gmtime(&rawtime);

          time_t started = mktime(ptm);
          if (ptm->tm_isdst) {
            ptm->tm_hour += 1;
            started = mktime(ptm);
          }*/

          // TODO: Start a background thread so we don't have to do this
          time_t started;
          time(&started);
          started -= 31; // simulate playtime

          iResult = LASTFM_track_scrobble(pSession, szTitleUTF8, szAlbumUTF8, szArtistUTF8, started, uiLengthSeconds, 0, 0, nullptr);
        } else iResult = LASTFM_track_update_now_playing(pSession, szTitleUTF8, szAlbumUTF8, szArtistUTF8, uiLengthSeconds, 0, 0, nullptr);

        delete [] szAlbumUTF8;
        delete [] szTitleUTF8;
        delete [] szArtistUTF8;

        const char* szStatus = nullptr;
        const int* iErrorCode = nullptr;
        const char* szErrorText = nullptr;
        LASTFM_status(pSession, &szStatus, &iErrorCode, &szErrorText);
        std::cout<<"cSession::ScrobbleOrUpdateTrack returning "<<(iResult == 0)<<", status="<<szStatus<<", error="<<iErrorCode<<", "<<szErrorText<<std::endl;
        return (iResult == 0);
      }