Struct BmsTableParser

Source
pub struct BmsTableParser { /* private fields */ }
Expand description

BMS表格解析器

提供从BMS表格网站获取和解析数据的功能。 使用HTTP客户端来获取HTML和JSON数据,并提供完整的解析流程。

Implementations§

Source§

impl BmsTableParser

Source

pub fn new() -> Self

创建新的BMS表格解析器实例

§返回值

返回一个配置好的解析器实例,包含HTTP客户端。

§示例
use bms_table::fetch::BmsTableParser;

let parser = BmsTableParser::new();
Source

pub async fn extract_bmstable_url(&self, html_url: &str) -> Result<String>

从HTML页面中提取bmstable字段

解析HTML页面的head标签,查找包含bmstable字段的meta标签, 提取指向JSON配置文件的URL。

§参数
  • html_url - HTML页面的URL
§返回值

返回提取到的bmstable URL字符串,如果未找到则返回错误。

§错误

如果无法获取HTML页面、解析失败或未找到bmstable字段,将返回错误。

§示例
use bms_table::fetch::BmsTableParser;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let parser = BmsTableParser::new();
    let url = parser.extract_bmstable_url("https://example.com/table.html").await?;
    println!("bmstable URL: {}", url);
    Ok(())
}
Source

pub async fn get_table_header(&self, header_url: &str) -> Result<BmsTableHeader>

获取并解析BMS表格头信息

从指定的URL获取JSON格式的BMS表格头信息,并解析为结构体。

§参数
  • header_url - 表格头信息JSON文件的URL
§返回值

返回解析后的BmsTableHeader结构体,包含表格名称、符号、课程信息等。

§错误

如果无法获取JSON文件或解析失败,将返回错误。

§示例
use bms_table::fetch::BmsTableParser;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let parser = BmsTableParser::new();
    let header = parser.get_table_header("https://example.com/header.json").await?;
    println!("表格名称: {}", header.name);
    Ok(())
}
Source

pub async fn get_score_data(&self, score_url: &str) -> Result<Vec<ScoreItem>>

获取并解析分数数据

从指定的URL获取JSON格式的分数数据,并解析为结构体数组。

§参数
  • score_url - 分数数据JSON文件的URL
§返回值

返回解析后的ScoreItem数组,包含所有BMS文件的分数数据。

§错误

如果无法获取JSON文件或解析失败,将返回错误。

§示例
use bms_table::fetch::BmsTableParser;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let parser = BmsTableParser::new();
    let scores = parser.get_score_data("https://example.com/score.json").await?;
    println!("分数数据数量: {}", scores.len());
    Ok(())
}
Source

pub async fn fetch_complete_table( &self, base_url: &str, ) -> Result<(BmsTableHeader, Vec<ScoreItem>)>

完整的BMS表格数据获取流程

执行完整的BMS表格数据获取流程:

  1. 从HTML页面提取bmstable字段
  2. 获取并解析表格头信息
  3. 获取并解析分数数据
§参数
  • base_url - BMS表格HTML页面的URL
§返回值

返回一个元组,包含表格头信息和分数数据数组。

§错误

如果在任何步骤中发生错误(网络错误、解析错误等),将返回错误。

§示例
use bms_table::fetch::BmsTableParser;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let parser = BmsTableParser::new();
    let (header, scores) = parser.fetch_complete_table("https://example.com/table.html").await?;
     
    println!("表格名称: {}", header.name);
    println!("分数数据数量: {}", scores.len());
     
    // 显示第一个分数数据
    if let Some(first_score) = scores.first() {
        if let Some(title) = &first_score.title {
            println!("第一个歌曲: {}", title);
        }
    }
     
    Ok(())
}

Trait Implementations§

Source§

impl Default for BmsTableParser

Source§

fn default() -> Self

创建默认的BMS表格解析器实例

等同于调用 BmsTableParser::new()

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,