#播放列表 #多媒体 #音乐

m3u

一个用于读取和写入.m3u文件的crate——多媒体播放列表的事实标准

2个版本 (1个稳定版)

使用旧的Rust 2015

1.0.0 2017年1月6日
0.1.0 2017年1月2日

#20 in #播放列表

Download history 74/week @ 2024-03-13 95/week @ 2024-03-20 152/week @ 2024-03-27 104/week @ 2024-04-03 91/week @ 2024-04-10 108/week @ 2024-04-17 87/week @ 2024-04-24 68/week @ 2024-05-01 64/week @ 2024-05-08 81/week @ 2024-05-15 72/week @ 2024-05-22 74/week @ 2024-05-29 55/week @ 2024-06-05 87/week @ 2024-06-12 70/week @ 2024-06-19 49/week @ 2024-06-26

271 每月下载量
5 个crate 中使用

MIT/Apache

25KB
382

m3u 构建状态 Crates.io Crates.io

一个用于读取和写入.m3u文件的lib——多媒体播放列表的事实标准。

请阅读文档

示例

原始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);
}

写入并读取一个看起来像这样的纯文本UTF-8文件

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

扩展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);
}

写入并读取一个看起来像这样的扩展M3U格式的纯文本UTF-8文件

#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

许可证

根据以下其中之一许可

任选其一。

贡献

除非你明确说明,否则你提交的任何贡献,按照Apache-2.0许可证的定义,将按照上述方式双许可,没有任何额外的条款或条件。

依赖关系

~1.5MB
~49K SLoC