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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#ifndef NET_CATALOG_H
#define NET_CATALOG_H
// NOTE: the quranicaudio.com catalog. qaris (reciters) come from /api/qaris, surah metadata from
// /api/surahs. audio for qari q, surah s is
// https://download.quranicaudio.com/quran/<q.relative_path><sss>.mp3
// both json files are cached in the data dir so the player starts offline.
#define SURAH_COUNT 114
#define CATALOG_API_QARIS "https://quranicaudio.com/api/qaris"
#define CATALOG_API_SURAHS "https://quranicaudio.com/api/surahs"
#define CATALOG_AUDIO_BASE "https://download.quranicaudio.com/quran/"
typedef struct Qari Qari;
struct Qari {
String8 name;
String8 relative_path;
u32 id;
u32 section_id;
};
typedef struct Surah Surah;
struct Surah {
String8 name; // "Al-Fatihah"
String8 english; // "The Opener"
u32 number;
u32 ayah_count;
b32 makki;
};
typedef struct Catalog Catalog;
struct Catalog {
Qari *qaris;
u32 qari_count;
Surah surahs[SURAH_COUNT];
};
// NOTE: a track is one surah by one qari. keys are dense so per track state is a flat array.
#define TrackKey(qari_index, surah_index) ((u32)(qari_index) * SURAH_COUNT + (u32)(surah_index))
#define TrackQari(key) ((key) / SURAH_COUNT)
#define TrackSurah(key) ((key) % SURAH_COUNT)
#define TRACK_NONE 0xFFFFFFFFu
//- qcat, the on disk catalog format (see net_catalog.cpp)
#define CATALOG_MAGIC 0x54414351u // "QCAT"
#define CATALOG_VERSION 2u // 2: crc32c checksum
typedef struct CatalogHeader CatalogHeader;
struct CatalogHeader {
u32 magic;
u32 version;
u32 qari_count;
u32 surah_count;
u32 strings_size;
u32 checksum; // crc32c over everything after the header
u32 reserved[2];
};
typedef struct CatalogQariRecord CatalogQariRecord;
struct CatalogQariRecord {
u32 id;
u32 section_id;
u32 name_offset;
u32 name_size;
u32 path_offset;
u32 path_size;
};
typedef struct CatalogSurahRecord CatalogSurahRecord;
struct CatalogSurahRecord {
u32 number;
u32 ayah_count;
u32 makki;
u32 name_offset;
u32 name_size;
u32 english_offset;
u32 english_size;
u32 reserved;
};
internal b32 http_get(Arena *arena, const char *url, String8 *out);
internal b32 catalog_parse_json(Arena *arena, Catalog *catalog, String8 qaris_text, String8 surahs_text);
internal String8 catalog_to_binary(Arena *arena, Catalog *catalog);
internal b32 catalog_from_binary(Arena *arena, Catalog *catalog, String8 data);
internal b32 catalog_load(Arena *arena, Catalog *catalog, String8 data_dir, b32 refresh);
internal s32 catalog_find_qari_by_id(Catalog *catalog, u32 id);
internal String8 catalog_section_name(u32 section_id);
#endif // NET_CATALOG_H
|