(&self, playlist_id: String)
| 1202 | |
| 1203 | #[tracing::instrument(level = "debug", skip(self))] |
| 1204 | pub fn export_playlist(&self, playlist_id: String) -> Result<String> { |
| 1205 | let mut conn = self.pool.get().unwrap(); |
| 1206 | |
| 1207 | let binding = self.get_playlists( |
| 1208 | QueryablePlaylist { |
| 1209 | playlist_id: Some(playlist_id.clone()), |
| 1210 | ..Default::default() |
| 1211 | }, |
| 1212 | true, |
| 1213 | &mut conn, |
| 1214 | )?; |
| 1215 | let playlist = binding.first(); |
| 1216 | |
| 1217 | if playlist.is_none() { |
| 1218 | return Err("Playlist not found".into()); |
| 1219 | } |
| 1220 | |
| 1221 | let playlist = playlist.unwrap(); |
| 1222 | |
| 1223 | let playlist_songs = self.get_songs_by_options(GetSongOptions { |
| 1224 | playlist: Some(QueryablePlaylist { |
| 1225 | playlist_id: Some(playlist_id), |
| 1226 | ..Default::default() |
| 1227 | }), |
| 1228 | ..Default::default() |
| 1229 | })?; |
| 1230 | |
| 1231 | let mut ret = format!("#EXTM3U\n#PLAYLIST:{}\n", playlist.playlist_name); |
| 1232 | |
| 1233 | for s in playlist_songs { |
| 1234 | if let Some(path) = &s.song.path { |
| 1235 | let duration = s.song.duration.unwrap_or(0f64); |
| 1236 | let title = s.song.title.unwrap_or_default(); |
| 1237 | let album_info = s.album.as_ref().map_or(String::new(), |album| { |
| 1238 | format!("#EXTALB:{}", album.album_name.clone().unwrap_or_default()) |
| 1239 | }); |
| 1240 | let genre_info = if let Some(genre) = &s.genre { |
| 1241 | if !genre.is_empty() { |
| 1242 | format!( |
| 1243 | "#EXTGENRE:{}", |
| 1244 | genre |
| 1245 | .iter() |
| 1246 | .filter_map(|g| g.genre_name.clone()) |
| 1247 | .collect::<Vec<String>>() |
| 1248 | .join(",") |
| 1249 | ) |
| 1250 | } else { |
| 1251 | String::new() |
| 1252 | } |
| 1253 | } else { |
| 1254 | String::new() |
| 1255 | }; |
| 1256 | let cover_path = match s.song.song_cover_path_high { |
| 1257 | Some(cover) => format!("#EXTIMG:{}", cover), |
| 1258 | None => String::new(), |
| 1259 | }; |
| 1260 | let song_info = format!("#MOOSINF:{}", s.song.type_); |
| 1261 | let file_path = format!("file://{}", path); |
no test coverage detected