diff --git a/src/command/dedupe.rs b/src/command/dedupe.rs
index 8cbaa43..a3ff954 100644
--- a/src/command/dedupe.rs
+++ b/src/command/dedupe.rs
@@ -1,6 +1,8 @@
use clap::{Arg, Error, ErrorKind};
use clap_nested::{Command};
+use crate::lib::m3u::{Playlist};
+
pub fn get_command<'a>() -> Command<'a, str>{
Command::new("dedupe")
.description("dedupe a m3u playlist")
@@ -16,8 +18,9 @@ pub fn get_command<'a>() -> Command<'a, str>{
// println!("Running dedupe, logging = {}", args);
match matches.values_of("playlist") {
Some(playlists) => {
- for playlist in playlists {
- println!("{}", playlist)
+ for path in playlists {
+ let playlist = Playlist::read(path)?;
+ println!("{:?}", playlist);
}
Ok(())
},
diff --git a/src/lib.rs b/src/lib.rs
deleted file mode 100644
index e69de29..0000000
diff --git a/src/lib/m3u.rs b/src/lib/m3u.rs
new file mode 100644
index 0000000..429cf31
--- /dev/null
+++ b/src/lib/m3u.rs
@@ -0,0 +1,33 @@
+use std::fs::File;
+use std::io::{self, BufRead};
+use std::path::Path;
+use std::string::String;
+
+fn read_lines
(filename: P) -> io::Result>>
+ where P: AsRef, {
+ let file = File::open(filename)?;
+ Ok(io::BufReader::new(file).lines())
+}
+
+#[derive(Debug)]
+pub struct Playlist {
+ path: String,
+ tracks: Box>
+}
+
+impl Playlist {
+ pub fn read(path: &str) -> Result {
+ let playlist_path: String = String::from(path);
+ let mut playlist_tracks: Vec = Vec::new();
+ let lines = read_lines(path)?;
+ lines.for_each(|read_line| {
+ if read_line.is_ok() {
+ let line = read_line.unwrap();
+ if line.len() > 0 && !line.starts_with("#") {
+ playlist_tracks.push(line)
+ }
+ }
+ });
+ Ok(Playlist { path: playlist_path, tracks: Box::new(playlist_tracks) })
+ }
+}
\ No newline at end of file
diff --git a/src/lib/mod.rs b/src/lib/mod.rs
new file mode 100644
index 0000000..033f1ae
--- /dev/null
+++ b/src/lib/mod.rs
@@ -0,0 +1 @@
+pub mod m3u;
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 866f9b2..93a93fe 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,7 @@ use clap::{Arg};
use clap_nested::{Commander};
mod command;
+mod lib;
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
diff --git a/test.m3u b/test.m3u
new file mode 100644
index 0000000..84aab3b
--- /dev/null
+++ b/test.m3u
@@ -0,0 +1,7 @@
+#EXTM3U
+
+#EXTINF:123, Sample artist - Sample title
+C:\Documents and Settings\I\My Music\Sample.mp3
+
+#EXTINF:321,Example Artist - Example title
+C:\Documents and Settings\I\My Music\Greatest Hits\Example.ogg
\ No newline at end of file