changeset 11309:fa738ed513f9

Improved searching for VobSubs inside RAR archives even if the names do not match the movie name. Do not display VobSubs whose timecodes are < 0 which would make all VobSubs appear from the start on upon seeking. Patches by "Reder, Uwe" <Uwe.Reder@3SOFT.de>.
author mosu
date Tue, 28 Oct 2003 22:36:56 +0000
parents 0c8d12a58a29
children 4e0e3ba55199
files vobsub.c
diffstat 1 files changed, 31 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/vobsub.c	Tue Oct 28 20:49:33 2003 +0000
+++ b/vobsub.c	Tue Oct 28 22:36:56 2003 +0000
@@ -88,11 +88,38 @@
 		p++;
 	}
 	rc = urarlib_get(&stream->data, &stream->size, (char*) p, rar_filename, "");
+	if (!rc) {
+	    /* There is no matching filename in the archive. However, sometimes
+	     * the files we are looking for have been given arbitrary names in the archive.
+	     * Let's look for a file with an exact match in the extension only. */
+	    int i, num_files, name_len;
+	    ArchiveList_struct *list, *lp;
+	    /* the cast in the next line is a hack to overcome a design flaw (IMHO) in unrarlib */
+	    num_files = urarlib_list (rar_filename, (ArchiveList_struct *)&list);
+	    if (num_files > 0) {
+		char *demanded_ext;
+		demanded_ext = strrchr (p, '.');
+		if (demanded_ext) {
+		    int demanded_ext_len = strlen (demanded_ext);
+	    	    for (i=0, lp=list; i<num_files; i++, lp=lp->next) {
+			name_len = strlen (lp->item.Name);
+			if (name_len >= demanded_ext_len && !strcasecmp (lp->item.Name + name_len - demanded_ext_len, demanded_ext)) {
+		            if ((rc = urarlib_get(&stream->data, &stream->size, lp->item.Name, rar_filename, ""))) {
+				break;
+		   	    }
+			}
+		    }
+		}
+	    	urarlib_freelist (list);
+	    }
+	    if (!rc) {
+		free(rar_filename);
+		free(stream);
+		return NULL;
+	    }
+	}
+
 	free(rar_filename);
-	if (!rc) {
-	    free(stream);
-	    return NULL;
-	}
 	stream->pos = 0;
     }
     return stream;