diff options
| author | dyknon dyknonr5fjp | 2026-01-16 03:10:12 +0900 |
|---|---|---|
| committer | dyknon dyknonr5fjp | 2026-01-16 03:10:12 +0900 |
| commit | 23c3482d4822d3ab56751ae81219f3df70aeac45 (patch) | |
| tree | 6cfd496950e46597209dfc35e5d1949e44ed0abd | |
| parent | a9551606fc20412f9db41a814072945b12712872 (diff) | |
Add magic number test.
| -rw-r--r-- | ytdlsb-main.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/ytdlsb-main.c b/ytdlsb-main.c index cf2a9aa..391748a 100644 --- a/ytdlsb-main.c +++ b/ytdlsb-main.c @@ -164,6 +164,7 @@ int ytdlsb_process_preload(struct ytdlsb_task *t){ size_t pp; struct ytdlsb_sb *sb; FRAG(p, sb, pp); + struct ytdlsb_sb_fragment *f = &sb->fragments[pp]; CURLMsg *m = curl_multi_info_read(p->preload_multi, &mq); assert(m != NULL); @@ -179,22 +180,37 @@ int ytdlsb_process_preload(struct ytdlsb_task *t){ CKZ(err, curl_easy_getinfo(p->preload_easy, CURLINFO_CONTENT_TYPE, &mtype)); if(respc == 200){ - if(strcmp(mtype, "image/jpeg") == 0){ - sb->fragments[pp].state = YTDLSB_SB_JPEG; + f->state = YTDLSB_SB_FAILED; + if(!mtype + || strcmp(mtype, "application/octet-stream") == 0 + ){ + // twitch returns jpeg images in octet-stream + if(f->data && f->data_len >= 12){ + if(memcmp(f->data, "\xff\xd8", 2) == 0){ + f->state = YTDLSB_SB_JPEG; + }else if( + memcmp(f->data, "RIFF", 4) == 0 + && memcmp(f->data+8, "WEBP", 4) == 0 + ){ + f->state = YTDLSB_SB_WEBP; + } + } + }else if(strcmp(mtype, "image/jpeg") == 0){ + f->state = YTDLSB_SB_JPEG; }else if(strcmp(mtype, "image/webp") == 0){ - sb->fragments[pp].state = YTDLSB_SB_WEBP; - }else{ + f->state = YTDLSB_SB_WEBP; + } + if(f->state == YTDLSB_SB_FAILED){ eprintf("invalid storyboard type: %s\n", mtype); - sb->fragments[pp].state = YTDLSB_SB_FAILED; } }else{ eprintf("invalid storyboard response: %03ld\n", respc); - sb->fragments[pp].state = YTDLSB_SB_FAILED; + f->state = YTDLSB_SB_FAILED; } }else{ double time; eprintf("storyboard download error: %d\n", (int)m->data.result); - sb->fragments[pp].state = YTDLSB_SB_FAILED; + f->state = YTDLSB_SB_FAILED; #define TIME(t) \ if(!curl_easy_getinfo(p->preload_easy, t, &time)){ \ eprintf(#t ": %f\n", time); \ |
