-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption2.rs
46 lines (40 loc) · 1.04 KB
/
option2.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use reqwest;
use std::collections::Vec;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
struct Playlist {
segments: Vec<String>,
}
impl Playlist {
fn new() -> Self {
Playlist { segments: Vec::new() }
}
fn add_segment(&mut self, segment: String) {
self.segments.push(segment);
}
fn sort(&mut self) {
self.segments.sort();
}
}
fn fetch_playlist(url: &str) -> Result<Playlist, reqwest::Error> {
let mut response = reqwest::get(url)?;
let mut playlist = Playlist::new();
let mut lines = response.text()?.lines();
for line in lines {
if line.starts_with("#EXTINF:") {
let segment = line.trim_start_matches("#EXTINF:").trim().to_string();
playlist.add_segment(segment);
}
}
playlist.sort();
Ok(playlist)
}
fn main() {
let url = "https://example.com/playlist.m3u8";
let playlist = fetch_playlist(url).unwrap();
println!("Sorted playlist:");
for segment in playlist.segments {
println!("{}", segment);
}
}