SubtitleDownloader (2 Viewers)

trudslev

Portal Member
July 29, 2008
9
5
Denmark
Home Country
Denmark Denmark
Where can I download the .DLL directly? I cannot seem to find it on the project site.
 

seco

Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    I have updated the link on Downloads -page on the project site.
     

    trudslev

    Portal Member
    July 29, 2008
    9
    5
    Denmark
    Home Country
    Denmark Denmark

    I made this as a wrapper for your function from FileUtils:

    Code:
    public static List<FileInfo> ExtractFilesFromZipOrRarFile(string archiveFile)
    {
        string directory = string.Concat(new object[] { Path.GetTempPath(), Path.DirectorySeparatorChar, Path.GetRandomFileName(), Path.DirectorySeparatorChar });
        var archive = ArchiveFactory.Open(archiveFile);
        foreach (var entry in archive.Entries)
            if (!entry.IsDirectory)
                entry.WriteToDirectory(directory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
        List<FileInfo> list = new List<FileInfo>();
        foreach (string str2 in Directory.GetFiles(directory))
            list.Add(new FileInfo(str2));
        return list;
    }
     

    seco

    Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    I made this as a wrapper for your function from FileUtils:

    Thanks for you suggestion and help, I will include this in the next version.

    However I think ExtractOptions.ExtractFullPath should not be there since I believe it would extract files to ...OurTempPath/PathInArchive/foo.file instead of ...OurTempPath/foo.file. In the first case Directory.GetFiles(OurTempPath) would not return anything?

    EDIT: My tests confirm what I said above, ExtractOptions.ExtractFullPath cannot be used. After leaving it out and creating directory manually, everything should work fine.

    Code:
    public static List<FileInfo> ExtractFilesFromZipOrRarFile(string archiveFile)
            {
                string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                Directory.CreateDirectory(tempDirectory);
     
                var archive = ArchiveFactory.Open(archiveFile);
               
                foreach (var entry in archive.Entries)
                {
                    if (!entry.IsDirectory)
                        entry.WriteToDirectory(tempDirectory);
                }
     
                return Directory.GetFiles(tempDirectory).Select(fileName => new FileInfo(fileName)).ToList();
            }
     
    Last edited:

    trudslev

    Portal Member
    July 29, 2008
    9
    5
    Denmark
    Home Country
    Denmark Denmark
    EDIT: My tests confirm what I said above, ExtractOptions.ExtractFullPath cannot be used. After leaving it out and creating directory manually, everything should work fine.
    Good point. The archive I tested it on didn't have a directory structure, so I guess I didn't see the issue :)
     

    MrJul

    Member
    May 31, 2011
    4
    7
    Lyon
    Home Country
    France France
    However I think ExtractOptions.ExtractFullPath should not be there since I believe it would extract files to ...OurTempPath/PathInArchive/foo.file instead of ...OurTempPath/foo.file. In the first case Directory.GetFiles(OurTempPath) would not return anything?

    EDIT: My tests confirm what I said above, ExtractOptions.ExtractFullPath cannot be used. After leaving it out and creating directory manually, everything should work fine.

    Hello seco,

    I think there are legitimate cases where keeping the directory structure could be wanted. In fact, in the sous-titres.eu downloader I wrote, I had to perform some analysis of the structure. Some downloaded zips may contain multiple languages, one per sub directory. Thus, the files are filtered and only those needed are extracted, based on the desired subtitle language. To perform this operation, both file names and directory names are checked. Then, the resulting path is transformed into a more user-friendly file name without a directory structure, which is what is returned to SubtitleDownloader.

    This is actually why the sous-titres.eu downloader broke recently. I was using the SevenZip lib directly to have access to the structure for filtering, and as a bonus, only extract the needed files for performance. I now directly use SharpCompress instead. If I could have access to the needed structure without directly referencing the compression library, it could be great. That being said, I realize this case is very specific, and that such a change could easily break compatibility with other downloaders. Currently, I don't really mind using the SharpCompress library: I don't think you'll be changing it again soon, and even if you do, the fix should be quick and easy :)
     

    seco

    Retired Team Member
  • Premium Supporter
  • August 7, 2007
    1,575
    1,239
    Home Country
    Finland Finland
    Hello seco,

    I think there are legitimate cases where keeping the directory structure could be wanted. In fact, in the sous-titres.eu downloader I wrote, I had to perform some analysis of the structure. Some downloaded zips may contain multiple languages, one per sub directory. Thus, the files are filtered and only those needed are extracted, based on the desired subtitle language. To perform this operation, both file names and directory names are checked. Then, the resulting path is transformed into a more user-friendly file name without a directory structure, which is what is returned to SubtitleDownloader.

    This is actually why the sous-titres.eu downloader broke recently. I was using the SevenZip lib directly to have access to the structure for filtering, and as a bonus, only extract the needed files for performance. I now directly use SharpCompress instead. If I could have access to the needed structure without directly referencing the compression library, it could be great. That being said, I realize this case is very specific, and that such a change could easily break compatibility with other downloaders. Currently, I don't really mind using the SharpCompress library: I don't think you'll be changing it again soon, and even if you do, the fix should be quick and easy :)

    Yep, you're right. I guess I could introduce a new method that preserves the directory structure during extraction. Could you tell me what kind of method your implementation would require so I can take a look?

    I see you already updated your implementation in SubCentral SVN, thanks.
     

    Users who are viewing this thread

    Top Bottom