2003-09-22 05:40:06 +02:00
|
|
|
/*****************************************************************************
|
2009-10-18 00:24:07 +02:00
|
|
|
* subtitles.c : subtitles detection
|
2003-09-22 05:40:06 +02:00
|
|
|
*****************************************************************************
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* Copyright (C) 2003-2009 VLC authors and VideoLAN
|
2003-09-22 05:40:06 +02:00
|
|
|
*
|
|
|
|
* Authors: Derk-Jan Hartman <hartman at videolan.org>
|
|
|
|
* This is adapted code from the GPL'ed MPlayer (http://mplayerhq.hu)
|
|
|
|
*
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
2003-09-22 05:40:06 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
2003-09-22 05:40:06 +02:00
|
|
|
*
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
2003-09-22 05:40:06 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2003-10-02 00:44:58 +02:00
|
|
|
/**
|
|
|
|
* \file
|
2016-04-02 16:50:37 +02:00
|
|
|
* This file contains functions to detect subtitle files.
|
2003-10-02 00:44:58 +02:00
|
|
|
*/
|
|
|
|
|
2008-01-23 22:50:58 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-01-27 21:45:34 +01:00
|
|
|
#include <ctype.h> /* isalnum() */
|
2013-12-29 15:15:46 +01:00
|
|
|
#include <unistd.h>
|
2006-11-12 12:50:06 +01:00
|
|
|
#include <sys/stat.h>
|
2006-02-01 21:51:18 +01:00
|
|
|
|
2012-01-27 21:45:34 +01:00
|
|
|
#include <vlc_common.h>
|
2023-05-02 15:22:18 +02:00
|
|
|
#include <vlc_arrays.h>
|
2012-01-27 21:45:34 +01:00
|
|
|
#include <vlc_fs.h>
|
|
|
|
#include <vlc_url.h>
|
2009-10-18 00:24:07 +02:00
|
|
|
|
2006-11-11 12:48:20 +01:00
|
|
|
#include "input_internal.h"
|
2003-09-22 05:40:06 +02:00
|
|
|
|
2003-10-02 00:44:58 +02:00
|
|
|
/**
|
2006-04-06 19:54:21 +02:00
|
|
|
* The possible extensions for subtitle files we support
|
2003-10-02 00:44:58 +02:00
|
|
|
*/
|
2016-03-24 10:21:32 +01:00
|
|
|
static const char *const sub_exts[] = { SLAVE_SPU_EXTENSIONS, "" };
|
2007-09-12 21:44:06 +02:00
|
|
|
|
2021-07-07 02:23:46 +02:00
|
|
|
/**
|
|
|
|
* Remove file extension in-place
|
|
|
|
*/
|
|
|
|
static void filename_strip_ext_inplace(char *str)
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2021-07-07 02:23:46 +02:00
|
|
|
char *tmp = strrchr(str, '.');
|
|
|
|
if (tmp)
|
|
|
|
*tmp = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trim special characters from a filename
|
2022-08-01 17:08:02 +02:00
|
|
|
*
|
2021-07-07 02:23:46 +02:00
|
|
|
* Trims whitespaces and other non-alphanumeric
|
|
|
|
* characters from filenames.
|
2022-08-01 17:08:02 +02:00
|
|
|
*
|
2021-07-07 02:23:46 +02:00
|
|
|
* \warning This function operates on the passed string
|
|
|
|
* without copying. It might return a pointer different to
|
|
|
|
* the passed one, in case it trims characters at the beginning.
|
|
|
|
* Therefore it is essential that the return value is used where
|
|
|
|
* the trimmed version of the string is needed and the returned
|
|
|
|
* pointer must not be free()d but rather the original pointer!
|
|
|
|
*/
|
|
|
|
VLC_USED static char *filename_trim_inplace(char *str)
|
|
|
|
{
|
|
|
|
char *ret = str;
|
2011-08-29 18:10:00 +02:00
|
|
|
unsigned char c;
|
|
|
|
|
2021-07-07 02:23:46 +02:00
|
|
|
// Trim leading non-alnum
|
|
|
|
while( (c = *str) != '\0' && !isalnum(c) )
|
|
|
|
str++;
|
|
|
|
ret = str;
|
|
|
|
|
|
|
|
// Trim inline nonalnum groups
|
|
|
|
char *writehead = str;
|
|
|
|
bool consecutive = false;
|
|
|
|
while( (c = *str) != '\0' )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2021-07-07 02:23:46 +02:00
|
|
|
if ( !isalnum(c) )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2021-07-07 02:23:46 +02:00
|
|
|
if ( consecutive )
|
|
|
|
{
|
|
|
|
str++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = ' ';
|
|
|
|
consecutive = true;
|
|
|
|
} else {
|
|
|
|
consecutive = false;
|
2003-12-22 15:32:57 +01:00
|
|
|
}
|
2021-07-07 02:23:46 +02:00
|
|
|
|
|
|
|
*writehead++ = tolower(c);
|
|
|
|
str++;
|
2003-09-22 05:40:06 +02:00
|
|
|
}
|
2021-07-07 02:23:46 +02:00
|
|
|
*writehead = '\0';
|
2003-12-22 15:32:57 +01:00
|
|
|
|
2021-07-07 02:23:46 +02:00
|
|
|
// Remove trailing space, if any
|
|
|
|
if ( consecutive )
|
|
|
|
*(writehead - 1) = '\0';
|
2011-08-29 18:10:00 +02:00
|
|
|
|
2021-07-07 02:23:46 +02:00
|
|
|
return ret;
|
2003-09-22 05:40:06 +02:00
|
|
|
}
|
2003-12-22 15:32:57 +01:00
|
|
|
|
2007-09-29 17:51:34 +02:00
|
|
|
static int whiteonly( const char *s )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2011-08-29 18:10:00 +02:00
|
|
|
unsigned char c;
|
|
|
|
|
|
|
|
while( (c = *s) != '\0' )
|
2007-09-29 17:51:34 +02:00
|
|
|
{
|
2011-08-29 18:10:00 +02:00
|
|
|
if( isalnum( c ) )
|
2007-09-29 17:51:34 +02:00
|
|
|
return 0;
|
2003-12-22 15:32:57 +01:00
|
|
|
s++;
|
2007-09-29 17:51:34 +02:00
|
|
|
}
|
|
|
|
return 1;
|
2003-09-22 05:40:06 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:08 +02:00
|
|
|
static int slave_strcmp( const void *a, const void *b )
|
|
|
|
{
|
|
|
|
const input_item_slave_t *p_slave0 = *((const input_item_slave_t **) a);
|
|
|
|
const input_item_slave_t *p_slave1 = *((const input_item_slave_t **) b);
|
|
|
|
|
|
|
|
if( p_slave0 == NULL || p_slave1 == NULL )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* We can compare these uris since they come from the file system */
|
|
|
|
#ifdef HAVE_STRCOLL
|
|
|
|
return strcoll( p_slave0->psz_uri, p_slave1->psz_uri );
|
|
|
|
#else
|
|
|
|
return strcmp( p_slave0->psz_uri, p_slave1->psz_uri );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-06-09 06:38:16 +02:00
|
|
|
/*
|
|
|
|
* Check if a file ends with a subtitle extension
|
|
|
|
*/
|
2006-11-11 12:48:20 +01:00
|
|
|
int subtitles_Filter( const char *psz_dir_content )
|
2005-10-16 02:30:30 +02:00
|
|
|
{
|
2006-03-27 17:35:55 +02:00
|
|
|
const char *tmp = strrchr( psz_dir_content, '.');
|
2007-09-29 17:51:34 +02:00
|
|
|
|
|
|
|
if( !tmp )
|
2006-03-27 17:35:55 +02:00
|
|
|
return 0;
|
2007-09-29 17:51:34 +02:00
|
|
|
tmp++;
|
2006-03-27 17:35:55 +02:00
|
|
|
|
2009-10-18 00:24:07 +02:00
|
|
|
for( int i = 0; sub_exts[i][0]; i++ )
|
2007-09-29 17:51:34 +02:00
|
|
|
if( strcasecmp( sub_exts[i], tmp ) == 0 )
|
|
|
|
return 1;
|
2006-03-27 17:35:55 +02:00
|
|
|
return 0;
|
2005-10-16 02:30:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-02 00:44:58 +02:00
|
|
|
/**
|
2004-04-23 13:56:21 +02:00
|
|
|
* Convert a list of paths separated by ',' to a char**
|
2003-10-02 00:44:58 +02:00
|
|
|
*/
|
2006-11-12 12:54:28 +01:00
|
|
|
static char **paths_to_list( const char *psz_dir, char *psz_path )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2004-04-23 13:56:21 +02:00
|
|
|
unsigned int i, k, i_nb_subdirs;
|
2004-04-20 17:54:54 +02:00
|
|
|
char **subdirs; /* list of subdirectories to look in */
|
2007-09-29 17:51:34 +02:00
|
|
|
char *psz_parser = psz_path;
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2007-09-29 17:51:34 +02:00
|
|
|
if( !psz_dir || !psz_path )
|
|
|
|
return NULL;
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2007-09-29 17:51:34 +02:00
|
|
|
for( k = 0, i_nb_subdirs = 1; psz_path[k] != '\0'; k++ )
|
2004-04-20 17:54:54 +02:00
|
|
|
{
|
2004-04-23 13:56:21 +02:00
|
|
|
if( psz_path[k] == ',' )
|
2004-04-20 17:54:54 +02:00
|
|
|
i_nb_subdirs++;
|
|
|
|
}
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2007-09-29 17:51:34 +02:00
|
|
|
subdirs = calloc( i_nb_subdirs + 1, sizeof(char*) );
|
|
|
|
if( !subdirs )
|
|
|
|
return NULL;
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2007-09-29 18:02:15 +02:00
|
|
|
for( i = 0; psz_parser && *psz_parser != '\0' ; )
|
2007-09-29 17:51:34 +02:00
|
|
|
{
|
|
|
|
char *psz_subdir = psz_parser;
|
|
|
|
psz_parser = strchr( psz_subdir, ',' );
|
|
|
|
if( psz_parser )
|
2004-04-20 17:54:54 +02:00
|
|
|
{
|
2007-09-29 17:51:34 +02:00
|
|
|
*psz_parser++ = '\0';
|
|
|
|
while( *psz_parser == ' ' )
|
2004-04-20 17:54:54 +02:00
|
|
|
psz_parser++;
|
|
|
|
}
|
2007-09-29 17:51:34 +02:00
|
|
|
|
2021-12-24 00:11:42 +01:00
|
|
|
if( asprintf( &subdirs[i], "%s%s",
|
2007-09-29 17:51:34 +02:00
|
|
|
psz_subdir[0] == '.' ? psz_dir : "",
|
2010-05-31 15:25:27 +02:00
|
|
|
psz_subdir ) == -1 )
|
2008-08-13 02:16:43 +02:00
|
|
|
break;
|
2021-12-24 00:11:42 +01:00
|
|
|
i++;
|
2004-04-20 17:54:54 +02:00
|
|
|
}
|
2007-09-29 17:51:34 +02:00
|
|
|
subdirs[i] = NULL;
|
|
|
|
|
2004-04-23 13:56:21 +02:00
|
|
|
return subdirs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detect subtitle files.
|
|
|
|
*
|
2005-10-16 02:30:30 +02:00
|
|
|
* When called this function will split up the psz_name string into a
|
2004-04-23 13:56:21 +02:00
|
|
|
* directory, filename and extension. It then opens the directory
|
|
|
|
* in which the file resides and tries to find possible matches of
|
|
|
|
* subtitles files.
|
|
|
|
*
|
|
|
|
* \ingroup Demux
|
|
|
|
* \param p_this the calling \ref input_thread_t
|
|
|
|
* \param psz_path a list of subdirectories (separated by a ',') to look in.
|
2016-03-24 10:21:32 +01:00
|
|
|
* \param psz_name_org the complete filename to base the search on.
|
2023-07-06 18:43:41 +02:00
|
|
|
* \param ppp_slaves an initialized input item slave list to append detected subtitles to
|
2016-03-24 10:21:32 +01:00
|
|
|
* \param p_slaves pointer to the size of the slave list
|
|
|
|
* \return VLC_SUCCESS if ok
|
2004-04-23 13:56:21 +02:00
|
|
|
*/
|
2016-03-24 10:21:32 +01:00
|
|
|
int subtitles_Detect( input_thread_t *p_this, char *psz_path, const char *psz_name_org,
|
|
|
|
input_item_slave_t ***ppp_slaves, int *p_slaves )
|
2004-04-23 13:56:21 +02:00
|
|
|
{
|
2012-04-10 16:43:16 +02:00
|
|
|
int i_fuzzy = var_GetInteger( p_this, "sub-autodetect-fuzzy" );
|
|
|
|
if ( i_fuzzy == 0 )
|
2016-03-24 10:21:32 +01:00
|
|
|
return VLC_EGENERIC;
|
|
|
|
input_item_slave_t **pp_slaves = *ppp_slaves;
|
|
|
|
int i_slaves = *p_slaves;
|
2007-09-29 17:51:34 +02:00
|
|
|
char **subdirs; /* list of subdirectories to look in */
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2009-10-20 19:28:28 +02:00
|
|
|
if( !psz_name_org )
|
2016-03-24 10:21:32 +01:00
|
|
|
return VLC_EGENERIC;
|
2005-10-18 23:53:42 +02:00
|
|
|
|
2024-01-24 20:25:37 +01:00
|
|
|
char *psz_fname_ext = vlc_uri2path( psz_name_org );
|
|
|
|
if( !psz_fname_ext )
|
2016-03-24 10:21:32 +01:00
|
|
|
return VLC_EGENERIC;
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2024-01-24 20:25:37 +01:00
|
|
|
char *psz_fname = strdup( psz_fname_ext );
|
|
|
|
char *f_dir = strdup( psz_fname_ext );
|
|
|
|
if( psz_fname == NULL || f_dir == NULL )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2024-01-24 20:25:37 +01:00
|
|
|
free( psz_fname_ext );
|
2010-05-31 15:25:27 +02:00
|
|
|
free( psz_fname );
|
2024-01-24 20:25:37 +01:00
|
|
|
free( f_dir );
|
2016-03-24 10:21:32 +01:00
|
|
|
return VLC_ENOMEM;
|
2003-09-22 05:40:06 +02:00
|
|
|
}
|
2007-09-29 17:51:34 +02:00
|
|
|
|
2024-01-24 20:25:37 +01:00
|
|
|
/* extract filename & dirname from psz_fname */
|
2021-07-07 02:23:46 +02:00
|
|
|
char *f_fname_trim = strrchr( psz_fname, DIR_SEP_CHAR );
|
|
|
|
if( !f_fname_trim )
|
2007-09-29 17:51:34 +02:00
|
|
|
{
|
2007-09-30 18:31:02 +02:00
|
|
|
free( f_dir );
|
2024-01-24 20:25:37 +01:00
|
|
|
free( psz_fname_ext );
|
2009-10-20 19:28:28 +02:00
|
|
|
free( psz_fname );
|
2016-03-24 10:21:32 +01:00
|
|
|
return VLC_EGENERIC;
|
2003-09-22 05:40:06 +02:00
|
|
|
}
|
2021-07-07 02:23:46 +02:00
|
|
|
f_fname_trim++; /* Skip the '/' */
|
|
|
|
f_dir[f_fname_trim - psz_fname] = 0; /* keep dir separator in f_dir */
|
2003-09-22 05:40:06 +02:00
|
|
|
|
2021-07-07 02:23:46 +02:00
|
|
|
filename_strip_ext_inplace(f_fname_trim);
|
|
|
|
f_fname_trim = filename_trim_inplace(f_fname_trim);
|
2003-12-22 15:32:57 +01:00
|
|
|
|
2007-09-29 17:51:34 +02:00
|
|
|
subdirs = paths_to_list( f_dir, psz_path );
|
2017-07-23 13:25:19 +02:00
|
|
|
for( int j = -1; (j == -1) || ( j >= 0 && subdirs != NULL && subdirs[j] != NULL ); j++ )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2010-08-02 19:32:14 +02:00
|
|
|
const char *psz_dir = (j < 0) ? f_dir : subdirs[j];
|
2007-09-29 18:02:15 +02:00
|
|
|
if( psz_dir == NULL || ( j >= 0 && !strcmp( psz_dir, f_dir ) ) )
|
2005-10-18 23:53:42 +02:00
|
|
|
continue;
|
|
|
|
|
2006-02-05 21:52:29 +01:00
|
|
|
/* parse psz_src dir */
|
2022-08-02 06:37:37 +02:00
|
|
|
vlc_DIR *dir = vlc_opendir( psz_dir );
|
2010-08-02 19:32:14 +02:00
|
|
|
if( dir == NULL )
|
2007-09-29 17:51:34 +02:00
|
|
|
continue;
|
2006-02-05 21:52:29 +01:00
|
|
|
|
2007-09-29 17:51:34 +02:00
|
|
|
msg_Dbg( p_this, "looking for a subtitle file in %s", psz_dir );
|
2010-08-02 19:32:14 +02:00
|
|
|
|
2014-01-27 17:46:51 +01:00
|
|
|
const char *psz_name;
|
2016-03-24 10:21:32 +01:00
|
|
|
while( (psz_name = vlc_readdir( dir )) )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2010-08-02 19:32:14 +02:00
|
|
|
if( psz_name[0] == '.' || !subtitles_Filter( psz_name ) )
|
|
|
|
continue;
|
|
|
|
|
2021-07-07 02:23:46 +02:00
|
|
|
char *tmp_fname = strdup(psz_name);
|
|
|
|
if (!tmp_fname)
|
|
|
|
break;
|
|
|
|
|
2012-04-10 17:00:11 +02:00
|
|
|
const char *tmp;
|
2016-03-24 10:21:32 +01:00
|
|
|
int i_prio = 0;
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2007-09-29 17:51:34 +02:00
|
|
|
/* retrieve various parts of the filename */
|
2021-07-07 02:23:46 +02:00
|
|
|
filename_strip_ext_inplace(tmp_fname);
|
|
|
|
char *tmp_fname_trim = filename_trim_inplace(tmp_fname);
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2012-04-10 15:39:09 +02:00
|
|
|
if( !strcmp( tmp_fname_trim, f_fname_trim ) )
|
2007-09-29 17:51:34 +02:00
|
|
|
{
|
|
|
|
/* matches the movie name exactly */
|
2016-03-24 10:21:32 +01:00
|
|
|
i_prio = SLAVE_PRIORITY_MATCH_ALL;
|
2007-09-29 17:51:34 +02:00
|
|
|
}
|
2012-04-10 15:39:09 +02:00
|
|
|
else if( (tmp = strstr( tmp_fname_trim, f_fname_trim )) )
|
2007-09-29 17:51:34 +02:00
|
|
|
{
|
|
|
|
/* contains the movie name */
|
|
|
|
tmp += strlen( f_fname_trim );
|
|
|
|
if( whiteonly( tmp ) )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2007-09-29 17:51:34 +02:00
|
|
|
/* chars in front of the movie name */
|
2016-03-24 10:21:32 +01:00
|
|
|
i_prio = SLAVE_PRIORITY_MATCH_RIGHT;
|
2005-10-16 02:30:30 +02:00
|
|
|
}
|
2007-09-29 17:51:34 +02:00
|
|
|
else
|
2005-10-16 02:30:30 +02:00
|
|
|
{
|
2007-09-29 17:51:34 +02:00
|
|
|
/* chars after (and possibly in front of)
|
|
|
|
* the movie name */
|
2016-03-24 10:21:32 +01:00
|
|
|
i_prio = SLAVE_PRIORITY_MATCH_LEFT;
|
2005-10-16 02:30:30 +02:00
|
|
|
}
|
2007-09-29 17:51:34 +02:00
|
|
|
}
|
2012-04-10 16:24:59 +02:00
|
|
|
else if( j == -1 )
|
2007-09-29 17:51:34 +02:00
|
|
|
{
|
|
|
|
/* doesn't contain the movie name, prefer files in f_dir over subdirs */
|
2016-03-24 10:21:32 +01:00
|
|
|
i_prio = SLAVE_PRIORITY_MATCH_NONE;
|
2007-09-29 17:51:34 +02:00
|
|
|
}
|
2021-07-07 02:23:46 +02:00
|
|
|
free(tmp_fname);
|
|
|
|
tmp_fname_trim = NULL;
|
|
|
|
|
2009-03-09 23:37:49 +01:00
|
|
|
if( i_prio >= i_fuzzy )
|
2007-09-29 17:51:34 +02:00
|
|
|
{
|
|
|
|
struct stat st;
|
2014-08-13 19:38:30 +02:00
|
|
|
char *path;
|
2005-10-16 23:20:05 +02:00
|
|
|
|
2016-03-24 10:21:32 +01:00
|
|
|
size_t i_len = strlen( psz_dir );
|
|
|
|
const char *psz_format;
|
2016-05-20 18:12:01 +02:00
|
|
|
if ( i_len == 0 )
|
|
|
|
continue;
|
2016-03-24 10:21:32 +01:00
|
|
|
if( psz_dir[i_len - 1] == DIR_SEP_CHAR )
|
|
|
|
psz_format = "%s%s";
|
|
|
|
else
|
|
|
|
psz_format = "%s"DIR_SEP"%s";
|
|
|
|
|
|
|
|
if( asprintf( &path, psz_format, psz_dir, psz_name ) < 0 )
|
2007-09-29 17:51:34 +02:00
|
|
|
continue;
|
2007-09-28 23:58:26 +02:00
|
|
|
|
2024-01-24 20:25:37 +01:00
|
|
|
if( strcmp( path, psz_fname_ext )
|
2014-08-13 19:38:30 +02:00
|
|
|
&& vlc_stat( path, &st ) == 0
|
2016-03-24 10:21:32 +01:00
|
|
|
&& S_ISREG( st.st_mode ) )
|
2007-09-29 17:51:34 +02:00
|
|
|
{
|
2006-03-28 22:29:28 +02:00
|
|
|
msg_Dbg( p_this,
|
2007-09-29 17:51:34 +02:00
|
|
|
"autodetected subtitle: %s with priority %d",
|
2014-08-13 19:38:30 +02:00
|
|
|
path, i_prio );
|
2016-03-24 10:21:32 +01:00
|
|
|
char *psz_uri = vlc_path2uri( path, NULL );
|
|
|
|
input_item_slave_t *p_sub = psz_uri != NULL ?
|
|
|
|
input_item_slave_New( psz_uri, SLAVE_TYPE_SPU, i_prio )
|
|
|
|
: NULL;
|
|
|
|
if( p_sub )
|
2016-06-05 17:01:15 +02:00
|
|
|
{
|
|
|
|
p_sub->b_forced = true;
|
2017-05-18 19:47:15 +02:00
|
|
|
TAB_APPEND(i_slaves, pp_slaves, p_sub);
|
2016-06-05 17:01:15 +02:00
|
|
|
}
|
2016-03-24 10:21:32 +01:00
|
|
|
free( psz_uri );
|
2007-09-29 17:51:34 +02:00
|
|
|
}
|
2014-08-13 19:38:30 +02:00
|
|
|
free( path );
|
2003-12-22 15:32:57 +01:00
|
|
|
}
|
2007-09-29 17:51:34 +02:00
|
|
|
}
|
2022-08-01 17:08:02 +02:00
|
|
|
vlc_closedir( dir );
|
2003-09-22 05:40:06 +02:00
|
|
|
}
|
2007-09-29 17:51:34 +02:00
|
|
|
if( subdirs )
|
|
|
|
{
|
2017-07-23 13:25:19 +02:00
|
|
|
for( size_t j = 0; subdirs[j] != NULL; j++ )
|
2007-09-30 18:31:02 +02:00
|
|
|
free( subdirs[j] );
|
2007-09-29 17:51:34 +02:00
|
|
|
free( subdirs );
|
|
|
|
}
|
|
|
|
free( f_dir );
|
2009-10-20 19:28:28 +02:00
|
|
|
free( psz_fname );
|
2024-01-24 20:25:37 +01:00
|
|
|
free( psz_fname_ext );
|
2003-12-22 15:32:57 +01:00
|
|
|
|
2016-03-24 10:21:32 +01:00
|
|
|
for( int i = 0; i < i_slaves; i++ )
|
2003-09-22 05:40:06 +02:00
|
|
|
{
|
2016-03-24 10:21:32 +01:00
|
|
|
input_item_slave_t *p_sub = pp_slaves[i];
|
2007-09-29 17:51:34 +02:00
|
|
|
|
2016-03-24 10:21:32 +01:00
|
|
|
bool b_reject = false;
|
|
|
|
char *psz_ext = strrchr( p_sub->psz_uri, '.' );
|
|
|
|
if( !psz_ext )
|
|
|
|
continue;
|
|
|
|
psz_ext++;
|
2007-09-29 17:51:34 +02:00
|
|
|
|
2016-03-24 10:21:32 +01:00
|
|
|
if( !strcasecmp( psz_ext, "sub" ) )
|
2004-10-06 17:35:54 +02:00
|
|
|
{
|
2016-03-24 10:21:32 +01:00
|
|
|
for( int j = 0; j < i_slaves; j++ )
|
2004-10-06 17:35:54 +02:00
|
|
|
{
|
2016-03-24 10:21:32 +01:00
|
|
|
input_item_slave_t *p_sub_inner = pp_slaves[j];
|
|
|
|
|
2016-06-21 11:11:32 +02:00
|
|
|
/* A slave can be null if it's already rejected */
|
|
|
|
if( p_sub_inner == NULL )
|
|
|
|
continue;
|
|
|
|
|
2016-03-24 10:21:32 +01:00
|
|
|
/* check that the filenames without extension match */
|
|
|
|
if( strncasecmp( p_sub->psz_uri, p_sub_inner->psz_uri,
|
|
|
|
strlen( p_sub->psz_uri ) - 3 ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
char *psz_ext_inner = strrchr( p_sub_inner->psz_uri, '.' );
|
|
|
|
if( !psz_ext_inner )
|
|
|
|
continue;
|
|
|
|
psz_ext_inner++;
|
|
|
|
|
|
|
|
/* check that we have an idx file */
|
|
|
|
if( !strcasecmp( psz_ext_inner, "idx" ) )
|
|
|
|
{
|
|
|
|
b_reject = true;
|
2004-10-06 17:35:54 +02:00
|
|
|
break;
|
2016-03-24 10:21:32 +01:00
|
|
|
}
|
2004-10-06 17:35:54 +02:00
|
|
|
}
|
2007-09-28 23:58:26 +02:00
|
|
|
}
|
2016-03-24 10:21:32 +01:00
|
|
|
else if( !strcasecmp( psz_ext, "cdg" ) )
|
2004-10-06 17:35:54 +02:00
|
|
|
{
|
2016-03-24 10:21:32 +01:00
|
|
|
if( p_sub->i_priority < SLAVE_PRIORITY_MATCH_ALL )
|
2008-04-14 00:08:29 +02:00
|
|
|
b_reject = true;
|
2004-10-06 17:35:54 +02:00
|
|
|
}
|
2016-03-24 10:21:32 +01:00
|
|
|
if( b_reject )
|
|
|
|
{
|
|
|
|
pp_slaves[i] = NULL;
|
|
|
|
input_item_slave_Delete( p_sub );
|
|
|
|
}
|
2007-09-29 17:51:34 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:08 +02:00
|
|
|
/* Sort alphabetically */
|
|
|
|
if( i_slaves > 0 )
|
|
|
|
qsort( pp_slaves, i_slaves, sizeof (input_item_slave_t*), slave_strcmp );
|
|
|
|
|
2016-03-24 10:21:32 +01:00
|
|
|
*ppp_slaves = pp_slaves; /* in case of realloc */
|
|
|
|
*p_slaves = i_slaves;
|
|
|
|
return VLC_SUCCESS;
|
2003-09-22 05:40:06 +02:00
|
|
|
}
|