bool InsertItems::UpdateItem(const PlaylistItemPtr& updated_item) { for (int i=0; i<items_.size(); i++) { PlaylistItemPtr item = items_[i]; if (item->Metadata().url() == updated_item->Metadata().url()) { items_[i] = updated_item; return true; } } return false; }
void Player::EngineMetadataReceived(const Engine::SimpleMetaBundle& bundle) { PlaylistItemPtr item = app_->playlist_manager()->active()->current_item(); if (!item) return; Engine::SimpleMetaBundle bundle_copy = bundle; // Maybe the metadata is from icycast and has "Artist - Title" shoved // together in the title field. const int dash_pos = bundle_copy.title.indexOf('-'); if (dash_pos != -1 && bundle_copy.artist.isEmpty()) { // Split on " - " if it exists, otherwise split on "-". const int space_dash_pos = bundle_copy.title.indexOf(" - "); if (space_dash_pos != -1) { bundle_copy.artist = bundle_copy.title.left(space_dash_pos).trimmed(); bundle_copy.title = bundle_copy.title.mid(space_dash_pos + 3).trimmed(); } else { bundle_copy.artist = bundle_copy.title.left(dash_pos).trimmed(); bundle_copy.title = bundle_copy.title.mid(dash_pos + 1).trimmed(); } } Song song = item->Metadata(); song.MergeFromSimpleMetaBundle(bundle_copy); // Ignore useless metadata if (song.title().isEmpty() && song.artist().isEmpty()) return; app_->playlist_manager()->active()->SetStreamMetadata(item->Url(), song); }
// If song had a CUE and the CUE still exists, the metadata from it will // be applied here. PlaylistItemPtr PlaylistBackend::RestoreCueData( PlaylistItemPtr item, std::shared_ptr<NewSongFromQueryState> state) { // we need library to run a CueParser; also, this method applies only to // file-type PlaylistItems if (item->type() != "File") { return item; } CueParser cue_parser(app_->library_backend()); Song song = item->Metadata(); // we're only interested in .cue songs here if (!song.has_cue()) { return item; } QString cue_path = song.cue_path(); // if .cue was deleted - reload the song if (!QFile::exists(cue_path)) { item->Reload(); return item; } SongList song_list; { QMutexLocker locker(&state->mutex_); if (!state->cached_cues_.contains(cue_path)) { QFile cue(cue_path); cue.open(QIODevice::ReadOnly); song_list = cue_parser.Load(&cue, cue_path, QDir(cue_path.section('/', 0, -2))); state->cached_cues_[cue_path] = song_list; } else { song_list = state->cached_cues_[cue_path]; } } for (const Song& from_list : song_list) { if (from_list.url().toEncoded() == song.url().toEncoded() && from_list.beginning_nanosec() == song.beginning_nanosec()) { // we found a matching section; replace the input // item with a new one containing CUE metadata return PlaylistItemPtr(new SongPlaylistItem(from_list)); } } // there's no such section in the related .cue -> reload the song item->Reload(); return item; }
xrme::State Remote::state() const { const Playlist* active = player_->playlists()->active(); const PlaylistItemPtr current_item = player_->GetCurrentItem(); xrme::State ret; ret.can_go_next = active->next_row() != -1; ret.can_go_previous = active->previous_row() != -1; ret.can_seek = current_item && !current_item->Metadata().is_stream(); switch (player_->GetState()) { case Engine::Playing: ret.playback_state = xrme::State::PlaybackState_Playing; break; case Engine::Paused: ret.playback_state = xrme::State::PlaybackState_Paused; break; case Engine::Idle: case Engine::Empty: ret.playback_state = xrme::State::PlaybackState_Stopped; break; } ret.position_millisec = player_->engine()->position_nanosec() / kNsecPerMsec; ret.volume = double(player_->GetVolume()) / 100; if (current_item) { const Song m = current_item->Metadata(); ret.metadata.title = m.title(); ret.metadata.artist = m.artist(); ret.metadata.album = m.album(); ret.metadata.albumartist = m.albumartist(); ret.metadata.composer = m.composer(); ret.metadata.genre = m.genre(); ret.metadata.track = m.track(); ret.metadata.disc = m.disc(); ret.metadata.year = m.year(); ret.metadata.length_millisec = m.length_nanosec() / kNsecPerMsec; ret.metadata.rating = m.rating(); } return ret; }
QVariantMap Mpris1TrackList::GetMetadata(int pos) const { PlaylistItemPtr item = app_->player()->GetItemAt(pos); if (!item) return QVariantMap(); return Mpris1::GetMetadata(item->Metadata()); }