feat: update m3u8
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,12 +1,11 @@
|
|||||||
|
.idea/
|
||||||
|
test.m3u8
|
||||||
|
|
||||||
# ---> Rust
|
# ---> Rust
|
||||||
# Generated by Cargo
|
# Generated by Cargo
|
||||||
# will have compiled files and executables
|
# will have compiled files and executables
|
||||||
/target/
|
/target/
|
||||||
|
|
||||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
|
||||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
|
||||||
Cargo.lock
|
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
|
|||||||
1312
Cargo.lock
generated
Normal file
1312
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
m3u8-rs = "1.0.5"
|
m3u8-rs = "1.0.5"
|
||||||
reqwest = "0.10.1"
|
reqwest = { version = "0.10.1", features = ["blocking", "json"] }
|
||||||
http = "0.2.0"
|
http = "0.2.0"
|
||||||
rust_util = "0.2.1"
|
rust_util = "0.6.41"
|
||||||
|
sha256 = "1.1.1"
|
||||||
|
|||||||
49
src/main.rs
49
src/main.rs
@@ -1,10 +1,14 @@
|
|||||||
|
use std::fmt::format;
|
||||||
|
use std::fs;
|
||||||
use rust_util::*;
|
use rust_util::*;
|
||||||
use m3u8_rs::*;
|
use m3u8_rs::*;
|
||||||
use m3u8_rs::playlist::Playlist;
|
use m3u8_rs::playlist::{MediaPlaylist, Playlist};
|
||||||
|
|
||||||
|
const CACHE_DIR: &'static str = "";
|
||||||
|
|
||||||
// https://github.com/rutgersc/m3u8-rs/blob/master/examples/simple.rs
|
// https://github.com/rutgersc/m3u8-rs/blob/master/examples/simple.rs
|
||||||
fn main() -> XResult<()> {
|
fn main() -> XResult<()> {
|
||||||
let test_fn = "/Users/hatterjiang/m/vod";
|
let test_fn = "test.m3u8";
|
||||||
let test_f_content = std::fs::read_to_string(test_fn)?;
|
let test_f_content = std::fs::read_to_string(test_fn)?;
|
||||||
|
|
||||||
let parsed = parse_playlist_res(test_f_content.as_bytes());
|
let parsed = parse_playlist_res(test_f_content.as_bytes());
|
||||||
@@ -13,21 +17,10 @@ fn main() -> XResult<()> {
|
|||||||
Ok(Playlist::MasterPlaylist(_pl)) => { //println!("Master playlist:\n{:?}", pl),
|
Ok(Playlist::MasterPlaylist(_pl)) => { //println!("Master playlist:\n{:?}", pl),
|
||||||
println!("Master play list not supported!");
|
println!("Master play list not supported!");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
|
||||||
Ok(Playlist::MediaPlaylist(pl)) => { //println!("Media playlist:\n{:?}", pl),
|
|
||||||
println!("Version: {}", pl.version);
|
|
||||||
println!("Duration: {}", pl.target_duration);
|
|
||||||
println!("Media sequence: {}", pl.media_sequence);
|
|
||||||
println!("Discontinueity sequence: {}", pl.discontinuity_sequence);
|
|
||||||
println!("Play list type: {:?}", pl.playlist_type);
|
|
||||||
println!("I frames only: {}", pl.i_frames_only);
|
|
||||||
println!("Start: {:?}", pl.start);
|
|
||||||
println!("Independent segments: {}", pl.independent_segments);
|
|
||||||
println!("End list: {}", pl.end_list);
|
|
||||||
for _s in pl.segments {
|
|
||||||
// println!("{:?}", s);
|
|
||||||
}
|
}
|
||||||
},
|
Ok(Playlist::MediaPlaylist(pl)) => { //println!("Media playlist:\n{:?}", pl),
|
||||||
|
print_media_play_list(&pl);
|
||||||
|
}
|
||||||
Err(e) => println!("Error: {:?}", e)
|
Err(e) => println!("Error: {:?}", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,3 +28,27 @@ fn main() -> XResult<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cache_and_read_file(url: &str) -> XResult<String> {
|
||||||
|
if fs::metadata(CACHE_DIR).is_err() {
|
||||||
|
opt_result!(fs::create_dir_all(url), "Create dir failed: {}, error: {}", CACHE_DIR);
|
||||||
|
}
|
||||||
|
let url_in_sha256 = sha256::digest(url);
|
||||||
|
let file_dir = format!("{}/{}", CACHE_DIR, url_in_sha256);
|
||||||
|
let file_url = format!("{}.url", &file_dir);
|
||||||
|
let file_content = format!("{}.content", &file_dir);
|
||||||
|
if fs::metadata(&file_url).is_err() {
|
||||||
|
opt_result!(fs::write(&file_url, url), "Write file: {}, failed: {}", file_url);
|
||||||
|
}
|
||||||
|
let get_response = opt_result!(reqwest::blocking::get(&url), "Get URL: {}, failed: {}", url);
|
||||||
|
// if fs::metadata(&file_content).is_err() {
|
||||||
|
// opt_result!(fs::write(&file_content, ))
|
||||||
|
// }
|
||||||
|
Ok("".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_media_play_list(pl: &MediaPlaylist) {
|
||||||
|
let mut cloned_pl = pl.clone();
|
||||||
|
cloned_pl.segments = vec![];
|
||||||
|
println!("Media play list details:\n{:#?}", cloned_pl);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user