How to write a magic file for libmagic to detect srt (subtitle) files

705 Views Asked by At

hhvm use libmagic to detect mime types of files. When i upload a subtitle file in srt format with the keyword "extern" as first word of a line hhvm (libmagic) detect it as text/x-c and the validation in symfony dont except the file.

That's why I need a magic file for libmagic to correctly recognize srt files. The syntax of magic files is complicated for me. Can someone help me or give a tip for a howto? I have already read the man pages file(1) and magic(5)

The srt file format is simple:

1
00:01:23,667 --> 00:01:26,333
Und?
- Das ist der einzige Alligator hier.

2
00:01:30,000 --> 00:01:32,083
extern Vier Minuten vorbei.
In einer Minute gehen wir.

3
00:01:32,208 --> 00:01:33,749
Das hat er klar gesagt.

4
00:01:34,000 --> 00:01:35,000
Er kommt schon.

5
00:01:44,708 --> 00:01:47,208
Der ist zu jung, um an
solche Sachen zu gelangen.

6
00:02:02,000 --> 00:02:03,791
Wann öffnet das Restaurant?

7
00:02:03,958 --> 00:02:05,249
Um 12 Uhr mittags.

8
00:02:05,417 --> 00:02:07,375
Nur das Essen ist etwas zu scharf.

9
00:02:08,458 --> 00:02:09,874
Kommt mit.

10
00:02:30,208 --> 00:02:31,583
Verzeihung.

This text is detected as text/x-c by linux file command.

1

There are 1 best solutions below

0
On

That works for me in /etc/magic (ubuntu 16.04):

0   string  1
>1   regex   \^[0-9:,\ ]*-->[0-9:,\ ]*   SubRip File
!:mime text/x-srt