Fix the remaining part of bug #607228, which completes the set of video file extensio...
[gn-sub.git] / src / GnomeSubtitles / Ui / VideoPreview / VideoFiles.cs
blob7c765fc58e01b064c5892c8f9af5679950062cd6
1 /*
2 * This file is part of Gnome Subtitles.
3 * Copyright (C) 2007-2011 Pedro Castro
5 * Gnome Subtitles is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * Gnome Subtitles is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 using System;
21 using System.Collections;
22 using System.IO;
23 using System.Text.RegularExpressions;
25 namespace GnomeSubtitles.Ui.VideoPreview {
27 public class VideoFiles {
28 private static Regex videoFilesRegex = new Regex(@"^.*\.((3g2)|(3gp)|(asf)|(avi)|(bdm)|(cpi)|(divx)|(flv)|(m4v)|(mkv)|(mod)|(mov)|(mp3)|(mp4)|(mpeg)|(mpg)|(mts)|(ogg)|(ogm)|(rm)|(rmvb)|(spx)|(vob)|(wav)|(wma)|(wmv)|(xvid))$");
30 /* Public methods */
32 public static ArrayList GetVideoFilesAtPath (string path) {
33 ArrayList videoFiles = new ArrayList();
35 if ((path == null) || (path == String.Empty))
36 return videoFiles;
38 string[] allFiles = Directory.GetFiles(path, "*.*");
39 foreach (string file in allFiles) {
40 if (videoFilesRegex.IsMatch(file))
41 videoFiles.Add(file);
43 return videoFiles;
46 public static Uri FindMatchingVideo (string file) {
47 ArrayList videoFiles = GetVideoFilesAtPath(Path.GetDirectoryName(file));
48 string filename = Path.GetFileNameWithoutExtension(file);
50 foreach (string videoFile in videoFiles) {
51 string video = Path.GetFileNameWithoutExtension(videoFile);
52 if (video == filename)
53 return new Uri(videoFile);
56 return null;