mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Update to newest gtk-rs crates
Some things were adapted accordingly and some warnings from clippy were fixed along the way.
This commit is contained in:
parent
863c9d19c3
commit
7c9c01d3ea
9 changed files with 359 additions and 406 deletions
|
|
@ -5,9 +5,9 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
base64 = "0.13.0"
|
||||
glib = { git = "https://github.com/gtk-rs/gtk-rs/", features = ["v2_64"] }
|
||||
gstreamer = "0.16.5"
|
||||
gstreamer-pbutils = "0.16.5"
|
||||
glib = "0.14.0"
|
||||
gstreamer = "0.17.0"
|
||||
gstreamer-pbutils = "0.17.0"
|
||||
log = "0.4.14"
|
||||
once_cell = "1.5.2"
|
||||
rand = "0.7.3"
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ pub(super) fn new() -> Result<ImportSession> {
|
|||
gstreamer::Element::link_many(&[&cdparanoiasrc, &queue, &audioconvert, &flacenc, &fakesink])?;
|
||||
|
||||
let bus = pipeline
|
||||
.get_bus()
|
||||
.ok_or(Error::u(String::from("Failed to get bus from pipeline.")))?;
|
||||
.bus()
|
||||
.ok_or_else(|| Error::u(String::from("Failed to get bus from pipeline.")))?;
|
||||
|
||||
// Run the pipeline into the paused state and wait for the resulting TOC message on the bus.
|
||||
|
||||
|
|
@ -38,21 +38,21 @@ pub(super) fn new() -> Result<ImportSession> {
|
|||
|
||||
let msg = bus.timed_pop_filtered(
|
||||
ClockTime::from_seconds(5),
|
||||
&vec![MessageType::Toc, MessageType::Error],
|
||||
&[MessageType::Toc, MessageType::Error],
|
||||
);
|
||||
|
||||
let toc = match msg {
|
||||
Some(msg) => match msg.view() {
|
||||
MessageView::Error(err) => Err(Error::os(err.get_error())),
|
||||
MessageView::Toc(toc) => Ok(toc.get_toc().0),
|
||||
MessageView::Error(err) => Err(Error::os(err.error())),
|
||||
MessageView::Toc(toc) => Ok(toc.toc().0),
|
||||
_ => Err(Error::u(format!(
|
||||
"Unexpected message from GStreamer: {:?}",
|
||||
msg
|
||||
))),
|
||||
},
|
||||
None => Err(Error::Timeout(format!(
|
||||
"Timeout while waiting for first message from GStreamer."
|
||||
))),
|
||||
None => Err(Error::Timeout(
|
||||
"Timeout while waiting for first message from GStreamer.".to_string(),
|
||||
)),
|
||||
}?;
|
||||
|
||||
pipeline.set_state(gstreamer::State::Ready)?;
|
||||
|
|
@ -72,33 +72,22 @@ pub(super) fn new() -> Result<ImportSession> {
|
|||
|
||||
let tmp_dir = create_tmp_dir()?;
|
||||
|
||||
for entry in toc.get_entries() {
|
||||
if entry.get_entry_type() == TocEntryType::Track {
|
||||
for entry in toc.entries() {
|
||||
if entry.entry_type() == TocEntryType::Track {
|
||||
let duration = entry
|
||||
.get_tags()
|
||||
.ok_or(Error::u(String::from("No tags in TOC entry.")))?
|
||||
.tags()
|
||||
.ok_or_else(|| Error::u(String::from("No tags in TOC entry.")))?
|
||||
.get::<Duration>()
|
||||
.ok_or(Error::u(String::from(
|
||||
"No duration tag found in TOC entry.",
|
||||
)))?
|
||||
.ok_or_else(|| Error::u(String::from("No duration tag found in TOC entry.")))?
|
||||
.get()
|
||||
.ok_or(Error::u(String::from(
|
||||
"Failed to unwrap duration tag from TOC entry.",
|
||||
)))?
|
||||
.mseconds()
|
||||
.ok_or(Error::u(String::from("Failed to unwrap track duration.")))?;
|
||||
.mseconds();
|
||||
|
||||
let number = entry
|
||||
.get_tags()
|
||||
.ok_or(Error::u(String::from("No tags in TOC entry.")))?
|
||||
.tags()
|
||||
.ok_or_else(|| Error::u(String::from("No tags in TOC entry.")))?
|
||||
.get::<TrackNumber>()
|
||||
.ok_or(Error::u(String::from(
|
||||
"No track number tag found in TOC entry.",
|
||||
)))?
|
||||
.get()
|
||||
.ok_or(Error::u(String::from(
|
||||
"Failed to unwrap track number tag from TOC entry.",
|
||||
)))?;
|
||||
.ok_or_else(|| Error::u(String::from("No track number tag found in TOC entry.")))?
|
||||
.get();
|
||||
|
||||
hasher.update(duration.to_le_bytes());
|
||||
|
||||
|
|
@ -140,7 +129,7 @@ pub(super) fn new() -> Result<ImportSession> {
|
|||
// This will also affect the filesink as expected.
|
||||
pipeline.set_state(gstreamer::State::Playing)?;
|
||||
|
||||
for msg in bus.iter_timed(ClockTime::none()) {
|
||||
for msg in bus.iter_timed(None) {
|
||||
match msg.view() {
|
||||
MessageView::Eos(..) => {
|
||||
info!("Finished ripping track {}.", track.number);
|
||||
|
|
@ -149,7 +138,7 @@ pub(super) fn new() -> Result<ImportSession> {
|
|||
}
|
||||
MessageView::Error(err) => {
|
||||
pipeline.set_state(gstreamer::State::Null)?;
|
||||
Err(Error::os(err.get_error()))?;
|
||||
return Err(Error::os(err.error()));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
|
@ -174,9 +163,7 @@ pub(super) fn new() -> Result<ImportSession> {
|
|||
|
||||
/// Create a new temporary directory and return its path.
|
||||
fn create_tmp_dir() -> Result<PathBuf> {
|
||||
let mut tmp_dir = glib::tmp_dir().ok_or(Error::u(String::from(
|
||||
"Failed to get temporary directory using glib::get_tmp_dir().",
|
||||
)))?;
|
||||
let mut tmp_dir = glib::tmp_dir();
|
||||
|
||||
let dir_name = format!("musicus-{}", rand::random::<u64>());
|
||||
tmp_dir.push(dir_name);
|
||||
|
|
|
|||
|
|
@ -19,30 +19,30 @@ pub(super) fn new(path: PathBuf) -> Result<ImportSession> {
|
|||
|
||||
let mut entries =
|
||||
std::fs::read_dir(path)?.collect::<std::result::Result<Vec<DirEntry>, std::io::Error>>()?;
|
||||
entries.sort_by(|entry1, entry2| entry1.file_name().cmp(&entry2.file_name()));
|
||||
entries.sort_by_key(|entry| entry.file_name());
|
||||
|
||||
for entry in entries {
|
||||
if entry.file_type()?.is_file() {
|
||||
let path = entry.path();
|
||||
|
||||
let uri = glib::filename_to_uri(&path, None).or(Err(Error::u(format!(
|
||||
"Failed to create URI from path: {:?}",
|
||||
path
|
||||
))))?;
|
||||
let uri = glib::filename_to_uri(&path, None)
|
||||
.map_err(|_| Error::u(format!("Failed to create URI from path: {:?}", path)))?;
|
||||
|
||||
let info = discoverer.discover_uri(&uri)?;
|
||||
|
||||
if !info.get_audio_streams().is_empty() {
|
||||
if !info.audio_streams().is_empty() {
|
||||
let duration = info
|
||||
.get_duration()
|
||||
.mseconds()
|
||||
.ok_or(Error::u(format!("Failed to get duration for {}.", uri)))?;
|
||||
.duration()
|
||||
.ok_or_else(|| Error::u(format!("Failed to get duration for {}.", uri)))?
|
||||
.mseconds();
|
||||
|
||||
let file_name = entry.file_name();
|
||||
let name = file_name.into_string().or(Err(Error::u(format!(
|
||||
"Failed to convert OsString to String: {:?}",
|
||||
entry.file_name()
|
||||
))))?;
|
||||
let name = file_name.into_string().map_err(|_| {
|
||||
Error::u(format!(
|
||||
"Failed to convert OsString to String: {:?}",
|
||||
entry.file_name()
|
||||
))
|
||||
})?;
|
||||
|
||||
hasher.update(duration.to_le_bytes());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue