From 13314b9dfacc63883f54b0820e51bd09dcc81d53 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 31 Oct 2020 02:25:56 +0100 Subject: [PATCH] Cleaning support of undefined language for subtitles --- src/extractor.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/extractor.c b/src/extractor.c index 4bd1cec..0c7c6b3 100644 --- a/src/extractor.c +++ b/src/extractor.c @@ -12,12 +12,12 @@ #include // @return -2 on error, -1 if track has alreaady been extracted, 0 on success. -int create_out_path(stream *track, const char *out_path) +int create_out_path(stream *track, const char *out_path, int track_id) { char *folder_path; char *tmp; - asprintf(&folder_path, "%s/Subtitles/%s", out_path, track->language); + asprintf(&folder_path, "%s/Subtitles/%s", out_path, track->language ? track->language : "und"); if (!folder_path) return -2; tmp = strrchr(folder_path, '/'); @@ -37,9 +37,14 @@ int create_out_path(stream *track, const char *out_path) return -2; } free(track->path); - asprintf(&track->path, "%s/%s.%s%s%s%s", folder_path, + + char identifier[8]; + if (!track->language) + snprintf(identifier, 8, "%d", track_id); + asprintf(&track->path, "%s/%s.%s%s%s%s", + folder_path, file_name, - track->language, + track->language ? track->language : identifier, track->is_default ? ".default" : "", track->is_forced ? ".forced" : "", extension); @@ -77,7 +82,7 @@ void extract_track(stream *track, AVFormatContext *in_ctx, AVFormatContext **out_ctx) { - if (create_out_path(track, out_path) != 0) + if (create_out_path(track, out_path, stream->id) != 0) return; extract_stream(out_ctx, track, in_ctx, stream); } @@ -101,7 +106,7 @@ void extract_font(stream *font, const char *out_path, AVStream *stream) if (count > 0) font->title = strndup(filename->value, count); - int fd = open(font->path, O_WRONLY | O_CREAT, 0744); + int fd = open(font->path, O_WRONLY | O_CREAT, 0644); if (fd == -1) return perror("Kyoo couldn't extract a subtitle's font"); write(fd, stream->codecpar->extradata, stream->codecpar->extradata_size); @@ -129,7 +134,7 @@ void extract_chapters(AVFormatContext *ctx, const char *out_path) *tmp = '\0'; strcat(path, ".txt"); - int fd = open(path, O_WRONLY | O_CREAT, 0744); + int fd = open(path, O_WRONLY | O_CREAT, 0644); for (unsigned i = 0; i < ctx->nb_chapters; i++) { AVDictionaryEntry *name = av_dict_get(ctx->chapters[i]->metadata, "title", NULL, 0);