2021-03-26 03:26:12 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Cesar Torres <shortanemoia@protonmail.com>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-03-26 03:26:12 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
#include <AK/DeprecatedString.h>
|
2021-03-26 03:26:12 +03:00
|
|
|
#include <AK/Optional.h>
|
|
|
|
#include <AK/RefPtr.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
|
|
|
|
// Extended M3U fields (de facto standard)
|
|
|
|
struct M3UExtendedInfo {
|
|
|
|
Optional<u32> track_length_in_seconds;
|
2022-12-04 21:02:33 +03:00
|
|
|
Optional<DeprecatedString> track_display_title;
|
|
|
|
Optional<DeprecatedString> group_name;
|
|
|
|
Optional<DeprecatedString> album_title;
|
|
|
|
Optional<DeprecatedString> album_artist;
|
|
|
|
Optional<DeprecatedString> album_genre;
|
2021-03-26 03:26:12 +03:00
|
|
|
Optional<u64> file_size_in_bytes;
|
|
|
|
Optional<ReadonlyBytes> embedded_mp3;
|
2022-12-04 21:02:33 +03:00
|
|
|
Optional<DeprecatedString> cover_path;
|
2021-03-26 03:26:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct M3UEntry {
|
2022-12-04 21:02:33 +03:00
|
|
|
DeprecatedString path;
|
2021-03-26 03:26:12 +03:00
|
|
|
Optional<M3UExtendedInfo> extended_info;
|
|
|
|
};
|
|
|
|
|
|
|
|
class M3UParser {
|
|
|
|
public:
|
2022-09-12 23:06:25 +03:00
|
|
|
static NonnullOwnPtr<M3UParser> from_file(StringView path);
|
2022-12-04 21:02:33 +03:00
|
|
|
static NonnullOwnPtr<M3UParser> from_memory(DeprecatedString const& m3u_contents, bool utf8);
|
2021-03-26 03:26:12 +03:00
|
|
|
|
|
|
|
NonnullOwnPtr<Vector<M3UEntry>> parse(bool include_extended_info);
|
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
Optional<DeprecatedString>& get_playlist_title_metadata() { return m_parsed_playlist_title; }
|
2021-03-26 03:26:12 +03:00
|
|
|
|
|
|
|
M3UParser();
|
|
|
|
|
|
|
|
private:
|
2022-12-04 21:02:33 +03:00
|
|
|
DeprecatedString m_m3u_raw_data;
|
|
|
|
DeprecatedString m_playlist_path;
|
2021-03-26 03:26:12 +03:00
|
|
|
bool m_use_utf8;
|
2022-12-04 21:02:33 +03:00
|
|
|
Optional<DeprecatedString> m_parsed_playlist_title;
|
2021-03-26 03:26:12 +03:00
|
|
|
};
|