A tool to sync music with your favorite devices
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

*: finish ipod podcast support

Gee Sawra 44d57b19 6a32b969

+48 -18
+46 -18
src/gpod/gpod.rs
··· 42 42 } 43 43 44 44 impl Manager { 45 + fn unsafe_new(mountpoint: String, db_ptr: *mut Itdb_iTunesDB) -> Self { 46 + Self { mountpoint, db_ptr } 47 + } 48 + 45 49 pub fn new(mountpoint: String) -> Result<Self> { 46 50 unsafe { 47 51 g_type_init(); ··· 139 143 } 140 144 } 141 145 itdb_track_add(self.db_ptr, ipod_track, -1); 142 - itdb_playlist_add_track(itdb_playlist_mpl(self.db_ptr), ipod_track, -1); 146 + 147 + match track.kind { 148 + model::TrackKind::Unknown => panic!("unknown track kind, impossible!"), 149 + model::TrackKind::Music => { 150 + itdb_playlist_add_track(itdb_playlist_mpl(self.db_ptr), ipod_track, -1) 151 + } 152 + model::TrackKind::Podcast => { 153 + itdb_playlist_add_track(itdb_playlist_podcasts(self.db_ptr), ipod_track, -1) 154 + } 155 + }; 156 + 143 157 let copy_success = itdb_cp_finalize(ipod_track, mp.as_ptr(), path.as_ptr(), &mut error); 144 158 if copy_success.is_null() { 145 159 itdb_track_free(ipod_track); ··· 202 216 203 217 fn podcasts(&self) -> Result<impl Iterator<Item = Track>> { 204 218 unsafe { 205 - let pp = 'plgen: { 206 - let pl = itdb_playlist_podcasts(self.db_ptr); 207 - if pl.is_null() { 208 - let np = itdb_playlist_new(c_strdup("Podcasts"), 0); 209 - if np.is_null() { 210 - break 'plgen Err(anyhow!("could not create new Podcasts playlist")); 211 - } 212 - 213 - itdb_playlist_set_podcasts(np); 214 - break 'plgen Ok(np); 215 - } 216 - 217 - Ok(pl) 218 - }?; 219 - 220 219 Ok(ITunesDBTrack { 221 - tl: (*pp).members as *mut GList, 220 + tl: (*itdb_playlist_podcasts(self.db_ptr)).members as *mut GList, 222 221 kind: model::TrackKind::Podcast, 223 222 }) 224 223 } ··· 316 315 )); 317 316 } 318 317 318 + let mut error: *mut GError = ptr::null_mut(); 319 + let db_ptr = itdb_parse(mountpoint.as_ptr(), &mut error); 320 + if !error.is_null() { 321 + let error = *error; 322 + let err_msg = std::ffi::CString::from_raw(error.message); 323 + return Err(anyhow!( 324 + "read ipod database, code {}: {}", 325 + error.code, 326 + err_msg.to_string_lossy() 327 + )); 328 + } 329 + 330 + let pl = itdb_playlist_podcasts(db_ptr); 331 + if pl.is_null() { 332 + let np = itdb_playlist_new(c_strdup("Podcasts"), 0); 333 + if np.is_null() { 334 + return Err(anyhow!("could not create new Podcasts playlist")); 335 + } 336 + 337 + itdb_playlist_add(db_ptr, np, -1); 338 + itdb_playlist_set_podcasts(np); 339 + } 340 + 341 + // initialize and drop a Manager so that the itunesdb is properly written 342 + let m = Manager::unsafe_new(path.clone(), db_ptr); 343 + drop(m); 344 + 319 345 let serials = rusb::devices()? 320 346 .iter() 321 347 .filter_map(|d| { ··· 431 457 #[test] 432 458 fn podcasts() { 433 459 let m = Manager::new("/run/media/geesawra/IPOD/".to_owned()).unwrap(); 434 - m.podcasts().unwrap(); 460 + for podcast in m.podcasts().unwrap() { 461 + println!("podcast: {}", podcast); 462 + } 435 463 } 436 464 }
+2
src/model.rs
··· 64 64 } 65 65 66 66 #[derive(Debug, Clone, Copy, sqlx::Type, clap::ValueEnum)] 67 + #[repr(i64)] 67 68 pub enum TrackKind { 68 69 #[value(skip)] 69 70 Unknown, ··· 157 158 let title = tags.title().unwrap_or("Unknown Title".into()).to_string(); 158 159 let album = tags.album().unwrap_or("Unknown Album".into()).to_string(); 159 160 let genre = tags.genre().unwrap_or("Unknown Genre".into()).to_string(); 161 + tags.pictures() 160 162 161 163 let mut t = Self { 162 164 id: 0,