#Help me how can i return the title,artist using audiotags it panicked when option return none

3 messages · Page 1 of 1 (latest)

toxic pilot
#

`

#[allow(unused_imports)]
#[allow(non_snake_case)]

use rust_play::audio::playing;
use rust_play::files::get_files;
use audiotags::Tag;

#[allow(dead_code)]
#[derive(Debug)]
struct Song{
file_path:String,
title:String,
artist:String,
song_name:String,
}

fn main(){

let files = get_files::get_mp3_files();

for file in files{
println!("{}",file);
create_song_struct(&file);

}

}

fn create_song_struct(file_path:&str) {

let tags = Tag::default().read_from_path(&file_path).unwrap();

let title = tags.title().unwrap();
let artist = tags.artist().unwrap();
let track = tags.track();

println!("title:{:?}\nartist:{:?}\ntrack:{:?}",title,artist,track);
}

`

quaint dragon
#

Please format your code (run rustfmt), at least when you show it to others. Also use proper code fences:
```rs
code here
```

Reformatting it for you (and removing some spurious elements):

use rust_play::files::get_files;
use audiotags::Tag;

#[derive(Debug)]
struct Song {
    file_path: String,
    title: String,
    artist: String,
    song_name: String,
}

fn main() {
  let files = get_files::get_mp3_files();
  for file in files {
    println!("{}",file);
    create_song_struct(&file);
  }
}

fn create_song_struct(file_path: &str) {
  let tags = Tag::default().read_from_path(&file_path).unwrap();
  let title = tags.title().unwrap();
  let artist = tags.artist().unwrap();
  let track = tags.track();
  println!("title:{:?}\nartist:{:?}\ntrack {:?}", title, artist, track);
}
#

As for your question, don't use unwrap if you don't want to panic on None