87 lines
No EOL
3.6 KiB
C#
87 lines
No EOL
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using JD.Shotgun.Service;
|
|
using JD.Shotgun.Service.ShotgunEntities;
|
|
using Orbit.AfterEffects.DTOs;
|
|
|
|
namespace Orbit.AfterEffects.Helpers
|
|
{
|
|
public static class NasToShotgunToAfterEffects
|
|
{
|
|
/* Filename examples
|
|
* KCPCarmen_Coach_001_COVER.aep
|
|
KCPCarmen_Coach_001.aep
|
|
FXCarmen_FX_001.aep
|
|
FXAnimals_FX_001.aep
|
|
KCPChiwawa_Coach_001.aep
|
|
KCP_TESTmapforkeyingSHA_Coach_001_WF_DODO.aep
|
|
FX365_FX_001_WII.aep
|
|
*/
|
|
private static readonly Regex ProjectFilenameRegex = new Regex(@"(?<projectType>KCP|FX)(?<mapName>_?[A-Za-z0-9]+)_(?<assetShortName>(Coach|FX)_\d+)(_(?<hint>\w+))?.aep"); // see examples above
|
|
|
|
|
|
public static AfterEffectsAsset GetAfterEffectsAsset(this IShotgunService shotgunService, string projectFilePath)
|
|
{
|
|
if (projectFilePath == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(projectFilePath));
|
|
}
|
|
|
|
if (projectFilePath == string.Empty)
|
|
{
|
|
return AfterEffectsAsset.Empty;
|
|
}
|
|
|
|
ShotgunMapAsset shotgunMapAsset = GetShotgunMapAsset(shotgunService, projectFilePath);
|
|
|
|
string normalizedPath = projectFilePath.Replace('/', '\\');
|
|
|
|
var afterEffectsAsset = new AfterEffectsAsset(shotgunMapAsset.Name, shotgunMapAsset.MapName, shotgunMapAsset.MapOpusName, shotgunMapAsset.NasProjectCodeName, shotgunMapAsset.MapProductionStudio, shotgunMapAsset.AssetType, shotgunMapAsset.ThumbnailUrl, normalizedPath);
|
|
return afterEffectsAsset;
|
|
}
|
|
|
|
public static ShotgunMapAsset GetShotgunMapAsset(this IShotgunService shotgunService, string projectFilePath)
|
|
{
|
|
if (projectFilePath == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(projectFilePath));
|
|
}
|
|
|
|
if (projectFilePath == string.Empty)
|
|
{
|
|
return null; // TODO: would be better to have an empty object
|
|
}
|
|
|
|
string filename = Path.GetFileName(projectFilePath);
|
|
|
|
var match = ProjectFilenameRegex.Match(filename);
|
|
|
|
if (!match.Success)
|
|
{
|
|
throw new ArgumentException($"Project filename '{filename}' doesn't match the expected format. Here are some examples of a valid filename: 'FXAnimals_FX_001.aep', 'FX365_FX_001_WII.aep', 'KCP_TESTmapforkeyingSHA_Coach_001_WF_DODO.aep'.");
|
|
}
|
|
|
|
string mapName = match.Groups["mapName"]?.ToString() ?? string.Empty;
|
|
|
|
ShotgunMap shotgunMap = shotgunService.GetMap(mapName);
|
|
ICollection<ShotgunMapAsset> shotgunMapAssets = shotgunService.GetMapAssets(shotgunMap);
|
|
|
|
string assetShortName = match.Groups["assetShortName"]?.ToString() ?? string.Empty;
|
|
string hint = match.Groups["hint"]?.ToString() ?? string.Empty;
|
|
if (!string.IsNullOrEmpty(hint))
|
|
assetShortName += "_" + hint;
|
|
|
|
ShotgunMapAsset shotgunMapAsset = shotgunMapAssets.FirstOrDefault(jdAsset => jdAsset.ShortName == assetShortName);
|
|
if (shotgunMapAsset == null)
|
|
{
|
|
throw new ArgumentException($"Unable to find a corresponding Shotgun asset from '{assetShortName}' (inferred from '{filename}'). " +
|
|
$"Available asset names are {string.Join(", ", shotgunMapAssets.Select(a => a?.ShortName ?? string.Empty))}.", nameof(projectFilePath));
|
|
}
|
|
|
|
return shotgunMapAsset;
|
|
}
|
|
}
|
|
} |