Giter Site home page Giter Site logo

m3u's Introduction

m3u Build Status Crates.io Crates.io docs.rs

A lib for reading and writing .m3u files - the de facto standard for multimedia playlists.

Example

Original M3U

extern crate m3u;

fn main() {

    // Create a multimedia media playlist.
    let playlist = vec![
        m3u::path_entry(r"Alternative\Band - Song.mp3"),
        m3u::path_entry(r"Classical\Other Band - New Song.mp3"),
        m3u::path_entry(r"Stuff.mp3"),
        m3u::path_entry(r"D:\More Music\Foo.mp3"),
        m3u::path_entry(r"..\Other Music\Bar.mp3"),
        m3u::url_entry(r"http://emp.cx:8000/Listen.pls").unwrap(),
        m3u::url_entry(r"http://www.example.com/~user/Mine.mp3").unwrap(),
    ];

    // Write the playlist to a file.
    {
        let mut file = std::fs::File::create("playlist.m3u").unwrap();
        let mut writer = m3u::Writer::new(&mut file);
        for entry in &playlist {
            writer.write_entry(entry).unwrap();
        }
    }

    // Read the playlist from the file.
    let mut reader = m3u::Reader::open("playlist.m3u").unwrap();
    let read_playlist: Vec<_> = reader.entries().map(|entry| entry.unwrap()).collect();
    assert_eq!(&playlist, &read_playlist);
}

Writes then reads a plain text UTF-8 file that looks like this:

Alternative\Band - Song.mp3
Classical\Other Band - New Song.mp3
Stuff.mp3
D:\More Music\Foo.mp3
..\Other Music\Bar.mp3
http://emp.cx:8000/Listen.pls
http://www.example.com/~user/Mine.mp3

Extended M3U

extern crate m3u;

fn main() {

    // Create a multimedia playlist, including the duration in seconds and name for each entry.
    let playlist = vec![
        m3u::path_entry(r"C:\Documents and Settings\I\My Music\Sample.mp3")
            .extend(123.0, "Sample artist - Sample title"),
        m3u::path_entry(r"C:\Documents and Settings\I\My Music\Greatest Hits\Example.ogg")
            .extend(321.0, "Example Artist - Example title"),
        m3u::path_entry(r"Sample.mp3")
            .extend(123.0, "Sample artist - Sample title"),
        m3u::path_entry(r"Greatest Hits\Example.ogg")
            .extend(321.0, "Example Artist - Example title"),
    ];

    // Write the playlist to the file.
    {
        let mut file = std::fs::File::create("playlist_ext.m3u").unwrap();
        let mut writer = m3u::Writer::new_ext(&mut file).unwrap();
        for entry in &playlist {
            writer.write_entry(entry).unwrap();
        }
    }

    // Read the playlist from the file.
    let mut reader = m3u::Reader::open_ext("playlist_ext.m3u").unwrap();
    let read_playlist: Vec<_> = reader.entry_exts().map(|entry| entry.unwrap()).collect();
    assert_eq!(&playlist, &read_playlist);
}

Writes then reads a plain text UTF-8 file in the Extended M3U format that looks like this:

#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
#EXTINF:123,Sample artist - Sample title
Sample.mp3
#EXTINF:321,Example Artist - Example title
Greatest Hits\Example.ogg

License

Licensed under either of

at your option.

Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

m3u's People

Contributors

mitchmindtree avatar algesten avatar

Watchers

Jonatan Littke avatar Francis Byrne avatar James Cloos avatar Carl Littke avatar Frida Issa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.