Esempio n. 1
0
        private void input_FileSelected(FileBar sender, FileBarEventArgs args)
        {
            audioDelay.Value = PrettyFormatting.getDelayAndCheck(input.Filename) ?? 0;

            bool bFound = false;

            foreach (KeyValuePair <string, string> strLanguage in LanguageSelectionContainer.Languages)
            {
                if (input.Filename.ToLower(System.Globalization.CultureInfo.InvariantCulture).Contains(strLanguage.Key.ToLower(System.Globalization.CultureInfo.InvariantCulture)))
                {
                    SetLanguage(strLanguage.Key);
                    bFound = true;
                    break;
                }
            }
            if (!bFound && input.Filename.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith(".idx"))
            {
                List <SubtitleInfo> subTracks;
                idxReader.readFileProperties(input.Filename, out subTracks);
                if (subTracks.Count > 0)
                {
                    SetLanguage(LanguageSelectionContainer.Short2FullLanguageName(subTracks[0].Name));
                }
            }
            raiseEvent();
        }
Esempio n. 2
0
        /// <summary>
        /// get Audio Language from the IFO file
        /// </summary>
        /// <param name="fileName">name of the IFO file</param>
        /// <param name="count">the audio stream number</param>
        /// <returns>Language as String</returns>
        public static string getAudioLanguage(string FileName, int count)
        {
            FileStream   fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            Stream       sr = br.BaseStream;

            // go to audio stream number
            sr.Seek(0x203, SeekOrigin.Begin);
            byte a = br.ReadByte();

            sr.Seek(2, SeekOrigin.Current);
            if (count > 0)
            {
                sr.Seek(8 * count, SeekOrigin.Current);
            }
            byte[] buff = new byte[2];
            br.Read(buff, 0, 2);
            string ShortLangCode = String.Format("{0}{1}", (char)buff[0], (char)buff[1]);
            string audioLang     = LanguageSelectionContainer.Short2FullLanguageName(ShortLangCode);

            fs.Close();
            return(audioLang);
        }
Esempio n. 3
0
        /// <summary>
        /// get several Audio Informations from the IFO file
        /// </summary>
        /// <param name="fileName">name of the IFO file</param>
        /// <param name="verbose">to have complete infos or not</param>
        /// <returns>several infos as String</returns>
        public static AudioTrackInfo[] GetAudioInfos(string FileName, bool verbose)
        {
            FileStream   fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            Stream       sr = br.BaseStream;

            // go to audio stream number
            sr.Seek(0x203, SeekOrigin.Begin);

            byte a = br.ReadByte();

            if (a > 8)
            {
                a = 8; // force the max #. According to the specs 8 is the max value for audio streams.
            }
            AudioTrackInfo[] ati = new AudioTrackInfo[a];

            for (int i = 0; i < a; i++)
            {
                ati[i] = new AudioTrackInfo();
                byte[] array = new byte[2];
                fs.Read(array, 0, 2);
                string        cm      = GetAudioCodingMode(array);
                string        sp      = GetAudioSamplingRate(array);
                int           ch      = (int)((GetAudioChannels(array)) + 1);
                byte          trackID = 0xBD;
                StringBuilder ad      = new StringBuilder();

                switch (cm)
                {
                case "AC3":  trackID = (byte)(0x80 + i); break;

                case "LPCM": trackID = (byte)(0xA0 + i); break;

                case "DTS":  trackID = (byte)(0x88 + i); break;
                }

                if (verbose)
                {
                    string mce = "Not Present";
                    if (GetAudioMultichannelExt(array))
                    {
                        mce = "Present";
                    }
                    string lt = GetAudioLanguageType(array);
                    string ap = GetAudioApplicationMode(array);
                    string aq = GetAudioQuantization(array);

                    ad.AppendFormat("Track# : {0:00} - [{1:X}]", i, trackID, Environment.NewLine);
                    ad.AppendFormat("Coding Mode            : {0}", cm, Environment.NewLine);
                    ad.AppendFormat("Multichannel Extension : {0}", mce, Environment.NewLine);
                    ad.AppendFormat("Language Type          : {0}", lt, Environment.NewLine);
                    ad.AppendFormat("Application Mode       : {0}", ap, Environment.NewLine);
                    ad.AppendFormat("Quantization           : {0}", aq, Environment.NewLine);
                    ad.AppendFormat("Sampling Rate          : {0}", sp, Environment.NewLine);
                    ad.AppendFormat("Channels               : {0}", ch, Environment.NewLine);
                }

                byte[] buff = new byte[2];
                br.Read(buff, 0, 2);
                string ShortLangCode = String.Format("{0}{1}", (char)buff[0], (char)buff[1]);

                sr.Seek(1, SeekOrigin.Current);
                byte[] l = new byte[1];
                fs.Read(l, 0, 1);
                string lce = GetAudioLanguageCodeExt(l);

                ati[i].TrackID      = trackID;
                ati[i].NbChannels   = ch + " channels";
                ati[i].SamplingRate = sp;
                ati[i].Type         = cm;
                ati[i].Language     = LanguageSelectionContainer.Short2FullLanguageName(ShortLangCode);
                if (verbose)
                {
                    ad.AppendFormat("Language              : {0} - {1}", LanguageSelectionContainer.Short2FullLanguageName(ShortLangCode), ShortLangCode, Environment.NewLine);
                    ad.AppendFormat("Language Extension    : {0}", lce, Environment.NewLine);
                    ad.AppendLine();
                    ati[i].Description = ad.ToString();
                }
                else
                {
                    ati[i].Description = String.Format("[{0:X}] - {1} - {2}ch / {3} / {4}", trackID, cm, ch, sp, LanguageSelectionContainer.Short2FullLanguageName(ShortLangCode));
                }

                // go to the next audio stream
                sr.Seek(2, SeekOrigin.Current);
            }

            fs.Close();

            return(ati);
        }
Esempio n. 4
0
        /// <summary>
        /// get several Subtitles Informations from the IFO file
        /// </summary>
        /// <param name="fileName">name of the IFO file</param>
        /// <returns>several infos as String</returns>
        public static string[] GetSubtitlesStreamsInfos(string FileName)
        {
            byte[] buff = new byte[2];
            byte   s    = 0;

            string[] subdesc = new string[s];

            try
            {
                FileStream   fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                Stream       sr = br.BaseStream;

                // go to the substream #1
                sr.Seek(0x255, SeekOrigin.Begin);

                s = br.ReadByte();
                if (s > 32)
                {
                    s = 32; // force the max #. According to the specs 32 is the max value for subtitles streams.
                }
                subdesc = new string[s];

                // go to the Language Code
                sr.Seek(2, SeekOrigin.Current);

                for (int i = 0; i < s; i++)
                {
                    // Presence (1 bit), Coding Mode (1bit), Short Language Code (2bits), Language Extension (1bit), Sub Picture Caption Type (1bit)
                    br.Read(buff, 0, 2);
                    string ShortLangCode = String.Format("{0}{1}", (char)buff[0], (char)buff[1]);

                    subdesc[i] = "[" + String.Format("{0:00}", i) + "]  - " + LanguageSelectionContainer.Short2FullLanguageName(ShortLangCode);

                    // Go to Code Extension
                    sr.Seek(1, SeekOrigin.Current);
                    buff[0] = br.ReadByte();

                    switch (buff[0] & 0x0F)
                    {
                    // from http://dvd.sourceforge.net/dvdinfo/sprm.html
                    case 1: subdesc[i] += " (Caption/Normal Size Char)"; break;

                    case 2: subdesc[i] += " (Caption/Large Size Char)"; break;

                    case 3: subdesc[i] += " (Caption For Children)"; break;

                    case 5: subdesc[i] += " (Closed Caption/Normal Size Char)"; break;

                    case 6: subdesc[i] += " (Closed Caption/Large Size Char)"; break;

                    case 7: subdesc[i] += " (Closed Caption For Children)"; break;

                    case 9: subdesc[i] += " (Forced Caption)"; break;

                    case 13: subdesc[i] += " (Director Comments/Normal Size Char)"; break;

                    case 14: subdesc[i] += " (Director Comments/Large Size Char)"; break;

                    case 15: subdesc[i] += " (Director Comments for Children)"; break;
                    }

                    if (buff[0] == 0)
                    {
                        buff[0] = 1;
                    }

                    // go to the next sub stream
                    sr.Seek(2, SeekOrigin.Current);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(subdesc);
        }
Esempio n. 5
0
        /// <summary>
        /// get several Subtitles Informations from the IFO file
        /// </summary>
        /// <param name="fileName">name of the IFO file</param>
        /// <returns>several infos as String</returns>
        public static string[] GetSubtitlesStreamsInfos(string FileName, int iPGC, bool bGetAllStreams)
        {
            byte[] buff = new byte[4];
            byte   s    = 0;

            string[] subdesc    = new string[s];
            string[] substreams = new string[s];

            try
            {
                FileStream   fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                Stream       sr = br.BaseStream;

                // go to the substream #1
                sr.Seek(0x255, SeekOrigin.Begin);

                s = br.ReadByte();
                if (s > 32 || bGetAllStreams)
                {
                    s = 32; // force the max #. According to the specs 32 is the max value for subtitles streams.
                }
                subdesc = new string[s];

                // go to the Language Code
                sr.Seek(2, SeekOrigin.Current);

                for (int i = 0; i < s; i++)
                {
                    // Presence (1 bit), Coding Mode (1bit), Short Language Code (2bits), Language Extension (1bit), Sub Picture Caption Type (1bit)
                    br.Read(buff, 0, 2);

                    if (buff[0] == 0 && buff[1] == 0)
                    {
                        subdesc[i] = "unknown";
                    }
                    else
                    {
                        string ShortLangCode = String.Format("{0}{1}", (char)buff[0], (char)buff[1]);
                        subdesc[i] = LanguageSelectionContainer.Short2FullLanguageName(ShortLangCode);
                    }

                    // Go to Code Extension
                    sr.Seek(1, SeekOrigin.Current);
                    buff[0] = br.ReadByte();

                    switch (buff[0] & 0x0F)
                    {
                    // from http://dvd.sourceforge.net/dvdinfo/sprm.html
                    case 1: subdesc[i] += " - (Caption/Normal Size Char)"; break;

                    case 2: subdesc[i] += " - (Caption/Large Size Char)"; break;

                    case 3: subdesc[i] += " - (Caption For Children)"; break;

                    case 5: subdesc[i] += " - (Closed Caption/Normal Size Char)"; break;

                    case 6: subdesc[i] += " - (Closed Caption/Large Size Char)"; break;

                    case 7: subdesc[i] += " - (Closed Caption For Children)"; break;

                    case 9: subdesc[i] += " - (Forced Caption)"; break;

                    case 13: subdesc[i] += " - (Director Comments/Normal Size Char)"; break;

                    case 14: subdesc[i] += " - (Director Comments/Large Size Char)"; break;

                    case 15: subdesc[i] += " - (Director Comments for Children)"; break;
                    }

                    if (buff[0] == 0)
                    {
                        buff[0] = 1;
                    }

                    // go to the next sub stream
                    sr.Seek(2, SeekOrigin.Current);
                }

                // find the PGC starting address of the requested PGC number
                sr.Seek(0x1000 + 0x0C + (iPGC - 1) * 0x08, SeekOrigin.Begin);
                br.Read(buff, 0, 4);

                // go to the starting address of the requested PGC number
                sr.Seek(0x1000 + buff[3] + buff[2] * 256 + buff[1] * 256 ^ 2 + buff[0] * 256 ^ 3, SeekOrigin.Begin);

                // go to the subtitle starting address
                sr.Seek(0x1B, SeekOrigin.Current);

                substreams = new string[32];
                for (int i = 0; i < 32; i++)
                {
                    if (i >= subdesc.Length)
                    {
                        break;
                    }

                    br.Read(buff, 0, 4);

                    if (buff[0] == 0)
                    {
                        continue;
                    }
                    buff[0] -= 128;

                    if (buff[0] > 0)
                    {
                        if (String.IsNullOrEmpty(substreams[buff[0]]))
                        {
                            substreams[buff[0]] = "[" + String.Format("{0:00}", buff[0]) + "] - " + subdesc[i];
                        }
                    }
                    if (buff[1] > 0)
                    {
                        if (String.IsNullOrEmpty(substreams[buff[1]]))
                        {
                            substreams[buff[1]] = "[" + String.Format("{0:00}", buff[1]) + "] - " + subdesc[i];
                        }
                    }
                    if (buff[2] > 0)
                    {
                        if (String.IsNullOrEmpty(substreams[buff[2]]))
                        {
                            substreams[buff[2]] = "[" + String.Format("{0:00}", buff[2]) + "] - " + subdesc[i];
                        }
                    }
                    if (buff[3] > 0)
                    {
                        if (String.IsNullOrEmpty(substreams[buff[3]]))
                        {
                            substreams[buff[3]] = "[" + String.Format("{0:00}", buff[3]) + "] - " + subdesc[i];
                        }
                    }
                    if (buff[0] == 0 && buff[1] == 0 && buff[2] == 0 && buff[3] == 0)
                    {
                        if (String.IsNullOrEmpty(substreams[buff[0]]))
                        {
                            substreams[buff[0]] = "[" + String.Format("{0:00}", buff[0]) + "] - " + subdesc[i];
                        }
                    }
                }

                if (bGetAllStreams)
                {
                    for (int i = 0; i < 32; i++)
                    {
                        if (String.IsNullOrEmpty(substreams[i]))
                        {
                            substreams[i] = "[" + String.Format("{0:00}", i) + "] - not detected";
                        }
                    }
                }
                else
                {
                    ArrayList arrList = new ArrayList();
                    foreach (string strItem in substreams)
                    {
                        if (!String.IsNullOrEmpty(strItem))
                        {
                            arrList.Add(strItem);
                        }
                    }
                    substreams = new string[arrList.Count];
                    for (int i = 0; i < arrList.Count; i++)
                    {
                        substreams[i] = arrList[i].ToString();
                    }
                }

                fs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(substreams);
        }