1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TitleFactory.cs" company="HandBrake Project (http://handbrake.fr)">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// Defines the TitleFactory type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Services.Scan.Factories
{
using System;
using HandBrake.Interop.Interop;
using HandBrake.Interop.Interop.HbLib;
using HandBrake.Interop.Interop.Json.Scan;
using HandBrake.Interop.Interop.Model;
using HandBrakeWPF.Services.Encode.Model.Models;
using HandBrakeWPF.Services.Scan.Model;
public class TitleFactory
{
public Title CreateTitle(SourceTitle title, int mainFeature)
{
Title converted = new Title
{
TitleNumber = title.Index,
Duration = new TimeSpan(0, title.Duration.Hours, title.Duration.Minutes, title.Duration.Seconds),
Resolution = new Size(title.Geometry.Width, title.Geometry.Height),
AngleCount = title.AngleCount,
ParVal = new Size(title.Geometry.PAR.Num, title.Geometry.PAR.Den),
AutoCropDimensions = new Cropping
{
Top = title.Crop[0],
Bottom = title.Crop[1],
Left = title.Crop[2],
Right = title.Crop[3]
},
Fps = ((double)title.FrameRate.Num) / title.FrameRate.Den,
SourceName = title.Path,
MainTitle = mainFeature == title.Index,
Playlist = title.Type == 1 ? string.Format(" {0:d5}.MPLS", title.Playlist).Trim() : null,
FramerateNumerator = title.FrameRate.Num,
FramerateDenominator = title.FrameRate.Den,
Type = title.Type
};
int currentTrack = 1;
foreach (SourceChapter chapter in title.ChapterList)
{
string chapterName = !string.IsNullOrEmpty(chapter.Name) ? chapter.Name : string.Empty;
converted.Chapters.Add(new Chapter(currentTrack, chapterName, new TimeSpan(chapter.Duration.Hours, chapter.Duration.Minutes, chapter.Duration.Seconds)));
currentTrack++;
}
int currentAudioTrack = 1;
foreach (SourceAudioTrack track in title.AudioList)
{
converted.AudioTracks.Add(new Audio(currentAudioTrack, track.Language, track.LanguageCode, track.Description, track.Codec, track.SampleRate, track.BitRate, track.ChannelLayout, track.Name));
currentAudioTrack++;
}
int currentSubtitleTrack = 1;
foreach (SourceSubtitleTrack track in title.SubtitleList)
{
SubtitleType convertedType = new SubtitleType();
switch (track.Source)
{
case (int)hb_subtitle_s_subsource.VOBSUB:
convertedType = SubtitleType.VobSub;
break;
case (int)hb_subtitle_s_subsource.CC608SUB:
case (int)hb_subtitle_s_subsource.CC708SUB:
convertedType = SubtitleType.CC;
break;
case (int)hb_subtitle_s_subsource.IMPORTSRT:
convertedType = SubtitleType.SRT;
break;
case (int)hb_subtitle_s_subsource.UTF8SUB:
convertedType = SubtitleType.UTF8Sub;
break;
case (int)hb_subtitle_s_subsource.TX3GSUB:
convertedType = SubtitleType.TX3G;
break;
case (int)hb_subtitle_s_subsource.SSASUB:
convertedType = SubtitleType.SSA;
break;
case (int)hb_subtitle_s_subsource.PGSSUB:
convertedType = SubtitleType.PGS;
break;
}
bool canBurn = HandBrakeSubtitleHelpers.CheckCanBurnSubtitle(track.Source) > 0;
bool canSetForcedOnly = HandBrakeSubtitleHelpers.CheckCanForceSubtitle(track.Source) > 0;
converted.Subtitles.Add(new Subtitle(track.Source, currentSubtitleTrack, track.Language, track.LanguageCode, convertedType, canBurn, canSetForcedOnly, track.Name));
currentSubtitleTrack++;
}
SourceMetadata metadata = title.MetaData;
if (title.MetaData != null)
{
converted.Metadata = new Metadata(
metadata.AlbumArtist,
metadata.Album,
metadata.Artist,
metadata.Comment,
metadata.Composer,
metadata.Description,
metadata.Genre,
metadata.LongDescription,
metadata.Name,
metadata.ReleaseDate);
}
return converted;
}
}
}
|