Beispiel #1
0
        public AaxFileItem(string path)
        {
            FileName = path;
            string ext = Path.GetExtension(path).ToLowerInvariant();

            AA       = ext == ".aa";
            FileSize = new FileInfo(path).Length;

            TagAndFileNamingHelper.ReadMetaData(this);
        }
Beispiel #2
0
        void writeTextFile(Func <Book, string> nameFunc, string dir)
        {
            if (AaxFileItem is null)
            {
                return;
            }
            var    afi      = AaxFileItem;
            string filename = $"{nameFunc (Book)}.txt";
            string path     = Path.Combine(dir, filename);

            Log(3, this, () => $"\"{path.SubstitUser ()}\"");
            try {
                using (var osm = new StreamWriter(path, false)) {
                    osm.WriteLine($"{R.HdrAuthor}: {Book.AuthorTag}");
                    osm.WriteLine($"{R.HdrTitle}: {Book.TitleTag}");
                    osm.WriteLine($"{R.HdrDuration}: {Duration.ToStringHMS ()}");
                    osm.WriteLine($"{R.HdrNarrator}: {afi.Narrator}");
                    osm.WriteLine($"{R.HdrGenre}: {Book.CustomNames?.GenreTag ?? TagAndFileNamingHelper.GetGenre (Settings, afi)}");
                    osm.WriteLine($"{R.HdrYear}: {Book.CustomNames?.YearTag?.Year ?? afi.PublishingDate?.Year}");
                    osm.WriteLine($"{R.HdrPublisher}: {afi.Publisher}");
                    osm.WriteLine($"{R.HdrCopyright}: {afi.Copyright}");
                    osm.WriteLine($"{R.HdrSampleRate}: {afi.SampleRate} Hz");
                    osm.WriteLine($"{R.HdrBitRate}: {afi.AvgBitRate} kb/s");
                    osm.WriteLine();

                    string[] words = afi.Abstract?.Split();
                    if (words is null)
                    {
                        return;
                    }

                    int n = 0;
                    for (int i = 0; i < words.Length; i++)
                    {
                        string word = words[i];
                        if (n + 1 + word.Length > 80)
                        {
                            osm.WriteLine();
                            n = 0;
                        }

                        if (n > 0)
                        {
                            osm.Write(' ');
                            n++;
                        }
                        osm.Write(word);
                        n += word.Length;
                    }
                    osm.WriteLine();
                }
            } catch (Exception exc) {
                Log(1, this, exc.ToShortString());
            }
        }
        public AaxFileItem(string path)
        {
            FileName = path;
            string ext = Path.GetExtension(path).ToLowerInvariant();

            HasExtAA = ext == EXT_AA;
            FileSize = new FileInfo(path).Length;

            bool succ = TagAndFileNamingHelper.ReadMetaData(this);

            if (!succ)
            {
                Log(1, this, $"{path.SubstitUser ()}, error reading meta data");
                throw new IOException(path.SubstitUser());
            }
        }
 public void WriteFiles (Func<Book, string> nameFunc) {
   if (Book is null || nameFunc is null)
     return;
   Log (3, this, () => nameFunc(Book).SubstitUser());
   if (Book.PartsType != Book.EParts.some) {
     setContext ();
     writeImageFile (nameFunc, Book.OutDirectoryLong);
     writeTextFile (nameFunc, Book.OutDirectoryLong);
   } else {
     foreach (var part in Book.Parts) {
       setContext (part);
       string dir = TagAndFileNamingHelper.GetPartDirectoryName (R, Settings, part);
       writeImageFile (nameFunc, dir);
       writeTextFile (nameFunc, dir);
     }
   }
 }
        void writeTextFile(Func <Book, string> nameFunc)
        {
            var    afi      = AaxFileItem;
            string filename = $"{nameFunc(Book)}.txt";
            string path     = Path.Combine(Book.OutDirectoryLong, filename);

            using (var osm = new StreamWriter(path, false)) {
                osm.WriteLine($"{R.HdrAuthor}: {Book.AuthorTag}");
                osm.WriteLine($"{R.HdrTitle}: {Book.TitleTag}");
                osm.WriteLine($"{R.HdrDuration}: {Duration.ToString (@"hh\:mm\:ss")}");
                osm.WriteLine($"{R.HdrNarrator}: {afi.Narrator}");
                osm.WriteLine($"{R.HdrGenre}: {Book.CustomNames?.GenreTag ?? TagAndFileNamingHelper.GetGenre(Settings, afi)}");
                osm.WriteLine($"{R.HdrYear}: {Book.CustomNames?.YearTag?.Year ?? afi.PublishingDate?.Year}");
                osm.WriteLine($"{R.HdrPublisher}: {afi.Publisher}");
                osm.WriteLine($"{R.HdrCopyright}: {afi.Copyright}");
                osm.WriteLine($"{R.HdrSampleRate}: {afi.SampleRate} Hz");
                osm.WriteLine($"{R.HdrBitRate}: {afi.AvgBitRate} kb/s");
                osm.WriteLine();

                string[] words = afi.Abstract?.Split();
                if (words is null)
                {
                    return;
                }

                int n = 0;
                for (int i = 0; i < words.Length; i++)
                {
                    string word = words[i];
                    if (n + 1 + word.Length > 80)
                    {
                        osm.WriteLine();
                        n = 0;
                    }

                    if (n > 0)
                    {
                        osm.Write(' ');
                        n++;
                    }
                    osm.Write(word);
                    n += word.Length;
                }
                osm.WriteLine();
            }
        }