pixivrs 0.1.0

Pixiv client writen in Rust
Documentation
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
use serde::Deserialize;
use std::collections::HashMap;

/// Follow restriction type
#[derive(Debug, Clone, Copy)]
pub enum FollowRestrict {
    /// Public
    Public,
    /// Private
    Private,
}

impl ToString for FollowRestrict {
    fn to_string(&self) -> String {
        match self {
            FollowRestrict::Public => "public".to_string(),
            FollowRestrict::Private => "private".to_string(),
        }
    }
}

/// Comment access control
#[derive(Deserialize, Debug, Clone)]
pub struct CommentAccessControl {
    /// Whether comments are allowed
    pub allow: bool,
}

/// Restriction attributes
#[derive(Deserialize, Debug, Clone)]
pub struct RestrictionAttributes {
    /// Restriction type
    #[serde(rename = "type")]
    pub restriction_type: String,
    /// Restriction value
    pub value: String,
}

/// Comment
#[derive(Deserialize, Debug, Clone)]
pub struct Comment {
    /// Comment ID
    pub id: u64,
    /// Comment content
    pub comment: String,
    /// Comment date
    pub date: String,
    /// Comment user
    pub user: Option<User>,
    /// Parent comment
    pub parent_comment: Option<Box<Comment>>,
}

/// Comment response
#[derive(Deserialize, Debug, Clone)]
pub struct CommentsResponse {
    /// Comment list
    pub comments: Vec<Comment>,
    /// Next page URL
    pub next_url: Option<String>,
    /// Total comment count
    pub total_comments: Option<u32>,
}

/// Illustration follow response
#[derive(Deserialize, Debug, Clone)]
pub struct IllustFollowResponse {
    /// Illustration list
    pub illusts: Vec<Illust>,
    /// Next page URL
    pub next_url: Option<String>,
}

/// Illustration bookmark response
#[derive(Deserialize, Debug, Clone)]
pub struct IllustBookmarkResponse {
    /// Success status
    pub success: bool,
    /// Error message
    pub error: Option<String>,
}

/// Trending tags response
#[derive(Deserialize, Debug, Clone)]
pub struct TrendingTagsResponse {
    /// Trending tags list
    pub trend_tags: Vec<TrendingTag>,
    /// Next page URL
    pub next_url: Option<String>,
}

/// Trending tag
#[derive(Deserialize, Debug, Clone)]
pub struct TrendingTag {
    /// Tag name
    pub tag: String,
    /// Translated tag name
    pub translated_name: Option<String>,
    /// Illustration list
    pub illust: Option<Vec<Illust>>,
}

/// Ugoira metadata response
#[derive(Deserialize, Debug, Clone)]
pub struct UgoiraMetadataResponse {
    /// Ugoira metadata
    pub ugoira_metadata: UgoiraMetadata,
}

/// Ugoira metadata
#[derive(Deserialize, Debug, Clone)]
pub struct UgoiraMetadata {
    /// Illustration ID
    pub illust_id: u64,
    /// Frame delay list
    pub frames: Vec<UgoiraFrame>,
    /// MIME type
    pub mime_type: String,
    /// Original file URL
    pub original_src: String,
    /// File size
    pub zip_urls: ZipUrls,
}

/// Ugoira frame
#[derive(Deserialize, Debug, Clone)]
pub struct UgoiraFrame {
    /// File name
    pub file: String,
    /// Delay time (milliseconds)
    pub delay: u32,
}

/// ZIP file URLs
#[derive(Deserialize, Debug, Clone)]
pub struct ZipUrls {
    /// Medium size ZIP file URL
    pub medium: String,
    /// Large size ZIP file URL
    pub large: String,
    /// Original size ZIP file URL
    pub original: String,
}

/// User following response
#[derive(Deserialize, Debug, Clone)]
pub struct UserFollowingResponse {
    /// User preview list
    pub user_previews: Vec<UserPreview>,
    /// Next page URL
    pub next_url: Option<String>,
}

/// User followers response
#[derive(Deserialize, Debug, Clone)]
pub struct UserFollowerResponse {
    /// User preview list
    pub user_previews: Vec<UserPreview>,
    /// Next page URL
    pub next_url: Option<String>,
}

/// User mypixiv response
#[derive(Deserialize, Debug, Clone)]
pub struct UserMypixivResponse {
    /// User preview list
    pub user_previews: Vec<UserPreview>,
    /// Next page URL
    pub next_url: Option<String>,
}

/// User preview
#[derive(Deserialize, Debug, Clone)]
pub struct UserPreview {
    /// User information
    pub user: User,
    /// Illustration list
    pub illusts: Vec<Illust>,
    /// Novel list
    pub novels: Option<Vec<Novel>>,
    /// Is muted
    pub is_muted: Option<bool>,
}

/// Novel information
#[derive(Deserialize, Debug, Clone)]
pub struct Novel {
    /// Novel ID
    pub id: u64,
    /// Novel title
    pub title: String,
    /// Novel type
    #[serde(rename = "type")]
    pub novel_type: String,
    /// Novel description
    pub caption: String,
    /// Restriction level
    pub restrict: u32,
    /// User information
    pub user: User,
    /// Tag list
    pub tags: Vec<Tag>,
    /// Creation date
    pub create_date: String,
    /// Page count
    pub page_count: u32,
    /// Text length
    pub text_length: u32,
    /// Series information
    pub series: Option<Series>,
    /// Total views
    pub total_view: u64,
    /// Total bookmarks
    pub total_bookmarks: u64,
    /// Is bookmarked
    pub is_bookmarked: bool,
    /// Is visible
    pub visible: bool,
    /// Is muted
    pub is_muted: bool,
    /// Is mypixiv only
    pub is_mypixiv_only: bool,
    /// Is X restricted
    pub is_x_restricted: bool,
    /// Novel AI type
    pub novel_ai_type: u32,
    /// Comment access control
    pub comment_access_control: Option<CommentAccessControl>,
}

/// Image URLs collection
#[derive(Deserialize, Debug, Clone)]
pub struct ImageUrls {
    /// Medium square image URL
    pub square_medium: String,
    /// Medium image URL
    pub medium: String,
    /// Large image URL
    pub large: String,
}

/// User avatar URL
#[derive(Deserialize, Debug, Clone)]
pub struct ProfileImageUrls {
    /// Medium avatar URL
    pub medium: String,
}

/// User information
#[derive(Deserialize, Debug, Clone)]
pub struct User {
    /// User ID
    pub id: u64,
    /// Username
    pub name: String,
    /// User account
    pub account: String,
    /// User avatar URL
    pub profile_image_urls: ProfileImageUrls,
    /// Comment
    pub comment: Option<String>,
    /// Is followed
    pub is_followed: Option<bool>,
}

/// Illustration tag
#[derive(Deserialize, Debug, Clone)]
pub struct Tag {
    /// Tag name
    pub name: String,
    /// Translated tag name
    pub translated_name: Option<String>,
}

/// Single page metadata
#[derive(Deserialize, Debug, Clone)]
pub struct MetaSinglePage {
    /// Original image URL
    pub original_image_url: Option<String>,
}

/// Page metadata
#[derive(Deserialize, Debug, Clone)]
pub struct MetaPage {
    /// Image URLs
    pub image_urls: ImageUrls,
}

/// Series information
#[derive(Deserialize, Debug, Clone)]
pub struct Series {
    /// Series ID
    pub id: u64,
    /// Series title
    pub title: String,
}

/// Illustration information
#[derive(Deserialize, Debug, Clone)]
pub struct Illust {
    /// Illustration ID
    pub id: u64,
    /// Illustration title
    pub title: String,
    /// Illustration type
    #[serde(rename = "type")]
    pub illust_type: String,
    /// Image URLs
    pub image_urls: ImageUrls,
    /// Illustration description
    pub caption: String,
    /// Restriction level
    pub restrict: u32,
    /// User information
    pub user: User,
    /// Tag list
    pub tags: Vec<Tag>,
    /// Tools used
    pub tools: Vec<String>,
    /// Creation date
    pub create_date: String,
    /// Page count
    pub page_count: u32,
    /// Width
    pub width: u32,
    /// Height
    pub height: u32,
    /// Sanity level
    pub sanity_level: u32,
    /// R-18 level
    pub x_restrict: u32,
    /// Series information
    pub series: Option<Series>,
    /// Single page metadata
    pub meta_single_page: MetaSinglePage,
    /// Page metadata
    pub meta_pages: Vec<MetaPage>,
    /// Total views
    #[serde(rename = "total_view_count")]
    pub total_view: u64,
    /// Total bookmarks
    #[serde(rename = "total_bookmarks_count")]
    pub total_bookmarks: u64,
    /// Is bookmarked
    pub is_bookmarked: bool,
    /// Is visible
    pub visible: bool,
    /// Is muted
    pub is_muted: bool,
    /// AI type
    pub illust_ai_type: u32,
    /// Illustration book style
    pub illust_book_style: u32,
    /// Total comments
    pub total_comments: Option<u32>,
    /// Comment access control
    #[serde(default)]
    pub comment_access_control: Option<CommentAccessControl>,
    /// Restriction attributes
    #[serde(default)]
    pub restriction_attributes: Option<Vec<RestrictionAttributes>>,
}

/// Illustration detail response
#[derive(Deserialize, Debug, Clone)]
pub struct IllustDetail {
    /// Illustration information
    pub illust: Illust,
}

/// Ranking response
#[derive(Deserialize, Debug, Clone)]
pub struct RankingResponse {
    /// Illustration list
    pub illusts: Vec<Illust>,
    /// Next page URL
    pub next_url: Option<String>,
    /// Ranking date
    pub date: Option<String>,
    /// Ranking mode
    pub mode: Option<String>,
}

/// Recommendation response
#[derive(Deserialize, Debug, Clone)]
pub struct RecommendedResponse {
    /// Illustration list
    pub illusts: Vec<Illust>,
    /// Next page URL
    pub next_url: Option<String>,
    /// Ranking label
    pub ranking_label: Option<RankingLabel>,
}

/// Ranking label
#[derive(Deserialize, Debug, Clone)]
pub struct RankingLabel {
    /// Label text
    pub text: String,
    /// Label type
    #[serde(rename = "type")]
    pub label_type: String,
}

/// Search illustration response
#[derive(Deserialize, Debug, Clone)]
pub struct SearchIllustResponse {
    /// Illustration list
    pub illusts: Vec<Illust>,
    /// Next page URL
    pub next_url: Option<String>,
    /// Search span limit
    pub search_span_limit: u32,
    /// Show AI works
    pub show_ai: bool,
}

/// Search target type
#[derive(Debug, Clone, Copy)]
pub enum SearchTarget {
    /// Partial match for tags
    PartialMatchForTags,
    /// Exact match for tags
    ExactMatchForTags,
    /// Title and caption
    TitleAndCaption,
    /// Keyword
    Keyword,
}

impl ToString for SearchTarget {
    fn to_string(&self) -> String {
        match self {
            SearchTarget::PartialMatchForTags => "partial_match_for_tags".to_string(),
            SearchTarget::ExactMatchForTags => "exact_match_for_tags".to_string(),
            SearchTarget::TitleAndCaption => "title_and_caption".to_string(),
            SearchTarget::Keyword => "keyword".to_string(),
        }
    }
}

/// Sort method
#[derive(Debug, Clone, Copy)]
pub enum Sort {
    /// Date descending
    DateDesc,
    /// Date ascending
    DateAsc,
    /// Popular descending
    PopularDesc,
}

impl ToString for Sort {
    fn to_string(&self) -> String {
        match self {
            Sort::DateDesc => "date_desc".to_string(),
            Sort::DateAsc => "date_asc".to_string(),
            Sort::PopularDesc => "popular_desc".to_string(),
        }
    }
}

/// Ranking mode
#[derive(Debug, Clone, Copy)]
pub enum RankingMode {
    /// Daily ranking
    Day,
    /// Weekly ranking
    Week,
    /// Monthly ranking
    Month,
    /// Daily male ranking
    DayMale,
    /// Daily female ranking
    DayFemale,
    /// Weekly original ranking
    WeekOriginal,
    /// Weekly rookie ranking
    WeekRookie,
    /// Daily manga ranking
    DayManga,
    /// Daily R-18 ranking
    DayR18,
    /// Daily R-18 male ranking
    DayMaleR18,
    /// Daily R-18 female ranking
    DayFemaleR18,
    /// Weekly R-18 ranking
    WeekR18,
    /// Weekly R-18G ranking
    WeekR18g,
}

impl ToString for RankingMode {
    fn to_string(&self) -> String {
        match self {
            RankingMode::Day => "day".to_string(),
            RankingMode::Week => "week".to_string(),
            RankingMode::Month => "month".to_string(),
            RankingMode::DayMale => "day_male".to_string(),
            RankingMode::DayFemale => "day_female".to_string(),
            RankingMode::WeekOriginal => "week_original".to_string(),
            RankingMode::WeekRookie => "week_rookie".to_string(),
            RankingMode::DayManga => "day_manga".to_string(),
            RankingMode::DayR18 => "day_r18".to_string(),
            RankingMode::DayMaleR18 => "day_male_r18".to_string(),
            RankingMode::DayFemaleR18 => "day_female_r18".to_string(),
            RankingMode::WeekR18 => "week_r18".to_string(),
            RankingMode::WeekR18g => "week_r18g".to_string(),
        }
    }
}

/// Content type
#[derive(Debug, Clone, Copy)]
pub enum ContentType {
    /// Illustration
    Illust,
    /// Manga
    Manga,
}

impl ToString for ContentType {
    fn to_string(&self) -> String {
        match self {
            ContentType::Illust => "illust".to_string(),
            ContentType::Manga => "manga".to_string(),
        }
    }
}

/// Filter type
#[derive(Debug, Clone, Copy)]
pub enum Filter {
    /// iOS filter
    ForIOS,
    /// No filter
    None,
}

impl ToString for Filter {
    fn to_string(&self) -> String {
        match self {
            Filter::ForIOS => "for_ios".to_string(),
            Filter::None => "".to_string(),
        }
    }
}

/// Search duration
#[derive(Debug, Clone, Copy)]
pub enum Duration {
    /// Within last day
    WithinLastDay,
    /// Within last week
    WithinLastWeek,
    /// Within last month
    WithinLastMonth,
}

impl ToString for Duration {
    fn to_string(&self) -> String {
        match self {
            Duration::WithinLastDay => "within_last_day".to_string(),
            Duration::WithinLastWeek => "within_last_week".to_string(),
            Duration::WithinLastMonth => "within_last_month".to_string(),
        }
    }
}