示例#1
0
    internal TrackInfo(MkvToolJsonSchema.Track track)
    {
        if (track == null)
        {
            throw new ArgumentNullException(nameof(track));
        }

        Format  = track.Codec;
        Codec   = track.Properties.CodecId;
        Title   = track.Properties.TrackName;
        Default = track.Properties.DefaultTrack;

        // If the "language" and "tag_language" fields are set FfProbe uses the tag language instead of the track language
        // https://github.com/MediaArea/MediaAreaXml/issues/34
        if (!string.IsNullOrEmpty(track.Properties.TagLanguage) &&
            !string.IsNullOrEmpty(track.Properties.Language) &&
            !track.Properties.Language.Equals(track.Properties.TagLanguage, StringComparison.OrdinalIgnoreCase))
        {
            HasErrors = true;
            Log.Logger.Warning("Tag and Track Language Mismatch : {TagLanguage} != {Language}", track.Properties.TagLanguage, track.Properties.Language);
        }

        // Set language
        if (string.IsNullOrEmpty(track.Properties.Language))
        {
            Language = "und";
        }
        else
        {
            // MkvMerge normally sets the language to und or 3 letter ISO 639-2 code
            // Try to lookup the language to make sure it is correct
            Iso6393 lang = PlexCleaner.Language.GetIso6393(track.Properties.Language);
            if (lang != null)
            {
                Language = lang.Part2B;
            }
            else
            {
                HasErrors = true;
                Log.Logger.Warning("Invalid Language : {Language}", track.Properties.Language);
                Language = "und";
            }
        }

        // Take care to use id and number correctly in MkvMerge and MkvPropEdit
        Id     = track.Id;
        Number = track.Properties.Number;

        // Has tags
        HasTags = MediaInfo.IsTagTitle(Title);

        // Verify required info
        Debug.Assert(!string.IsNullOrEmpty(Format));
        Debug.Assert(!string.IsNullOrEmpty(Codec));
    }
示例#2
0
    internal TrackInfo(MediaInfoToolXmlSchema.Track track)
    {
        if (track == null)
        {
            throw new ArgumentNullException(nameof(track));
        }

        Format  = track.Format;
        Codec   = track.CodecId;
        Title   = track.Title;
        Default = track.Default;

        // Set language
        if (string.IsNullOrEmpty(track.Language))
        {
            Language = "und";
        }
        else
        {
            // MediaInfo uses ab or abc or ab-cd tags, we need to convert to ISO 639-2
            // https://github.com/MediaArea/MediaAreaXml/issues/33
            // Try to lookup the language to make sure it is correct
            Iso6393 lang = PlexCleaner.Language.GetIso6393(track.Language);
            if (lang != null)
            {
                Language = lang.Part2B;
            }
            else
            {
                HasErrors = true;
                Log.Logger.Warning("Invalid Language : {Language}", track.Language);
                Language = "und";
            }
        }

        // FfProbe and MkvMerge use chi not zho
        // https://github.com/mbunkus/mkvtoolnix/issues/1149
        if (Language.Equals("zho", StringComparison.OrdinalIgnoreCase))
        {
            Language = "chi";
        }

        // ID can be an integer or an integer-type, e.g. 3-CC1
        // https://github.com/MediaArea/MediaInfo/issues/201
        Id = int.Parse(track.Id.All(char.IsDigit) ? track.Id : track.Id[..track.Id.IndexOf('-', StringComparison.OrdinalIgnoreCase)], CultureInfo.InvariantCulture);
示例#3
0
 public static Iso6393 GetIso6393(string language)
 {
     // Match by string
     return(Iso6393.FromString(language, Iso6393List));
 }
示例#4
0
    internal TrackInfo(FfMpegToolJsonSchema.Stream stream)
    {
        if (stream == null)
        {
            throw new ArgumentNullException(nameof(stream));
        }

        // Fixed attributes
        Format  = stream.CodecName;
        Codec   = stream.CodecLongName;
        Default = stream.Disposition.Default;

        // Variable attributes
        Title    = stream.Tags.FirstOrDefault(item => item.Key.Equals("title", StringComparison.OrdinalIgnoreCase)).Value ?? "";
        Language = stream.Tags.FirstOrDefault(item => item.Key.Equals("language", StringComparison.OrdinalIgnoreCase)).Value ?? "";

        // TODO: FfProbe uses the tag language value instead of the track language
        // Some files show MediaInfo and MkvMerge say language is "eng", FfProbe says language is "und"
        // https://github.com/MediaArea/MediaAreaXml/issues/34

        // Set language
        if (string.IsNullOrEmpty(Language))
        {
            Language = "und";
        }
        // Some sample files are "???" or "null", set to und
        else if (Language.Equals("???", StringComparison.OrdinalIgnoreCase) ||
                 Language.Equals("null", StringComparison.OrdinalIgnoreCase))
        {
            HasErrors = true;
            Log.Logger.Warning("Invalid Language : {Language}", Language);
            Language = "und";
        }
        else
        {
            // FfProbe normally sets a 3 letter ISO 639-2 code, but some samples have 2 letter codes
            // Try to lookup the language to make sure it is correct
            Iso6393 lang = PlexCleaner.Language.GetIso6393(Language);
            if (lang != null)
            {
                Language = lang.Part2B;
            }
            else
            {
                HasErrors = true;
                Log.Logger.Warning("Invalid Language : {Language}", Language);
                Language = "und";
            }
        }

        // Use index for number
        Id     = stream.Index;
        Number = stream.Index;

        // Has tags
        HasTags = MediaInfo.IsTagTitle(Title);

        // Verify required info
        Debug.Assert(!string.IsNullOrEmpty(Format));
        Debug.Assert(!string.IsNullOrEmpty(Codec));
    }