Skip to content

Commit 82584c8

Browse files
committed
refactor: Refactor TMDB data handling to use SearchResultData class
Refactored TmdbDataTransformer to encapsulate result details into a new SearchResultData class. This change simplifies the method signatures and improves code readability by reducing parameter count. Added SearchResultData.cs to define the new data structure.
1 parent 95d2a19 commit 82584c8

File tree

2 files changed

+53
-39
lines changed

2 files changed

+53
-39
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace FoliCon.Models.Data;
2+
3+
public class SearchResultData
4+
{
5+
public dynamic Result { get; set; }
6+
public string ResultType { get; set; }
7+
public string FullFolderPath { get; set; }
8+
public string Rating { get; set; }
9+
public bool IsPickedById { get; set; }
10+
public string FolderName { get; set; }
11+
public string LocalPosterPath { get; set; }
12+
}

FoliCon/Modules/TMDB/TmdbDataTransformer.cs

+41-39
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,17 @@ public void ResultPicked(dynamic result, string resultType, string fullFolderPat
191191
var localPosterPath = Path.Combine(fullFolderPath, $"{IconUtils.GetImageName()}.png");
192192
var posterUrl = GetPosterUrl(result.PosterPath, PosterSize.Original, client);
193193

194-
string type = PickResult(result, resultType, fullFolderPath, rating, isPickedById,out int id, folderName, localPosterPath);
194+
var resultDetails = new SearchResultData
195+
{
196+
Result = result,
197+
ResultType = resultType,
198+
FullFolderPath = fullFolderPath,
199+
Rating = rating,
200+
IsPickedById = isPickedById,
201+
FolderName = folderName,
202+
LocalPosterPath = localPosterPath,
203+
};
204+
var type = PickResult(resultDetails, out var id);
195205

196206
if (!isPickedById && id != 0)
197207
{
@@ -219,61 +229,53 @@ private static string PrepareRating(string resultType, string rating, dynamic re
219229
return rating;
220230
}
221231

222-
private string PickResult(dynamic result,
223-
string resultType,
224-
string fullFolderPath,
225-
string rating,
226-
bool isPickedById,
227-
out int id,
228-
string folderName,
229-
string localPosterPath)
232+
private string PickResult(SearchResultData details, out int id)
230233
{
231234
id = 0;
232-
var mediaType = resultType;
233-
switch (resultType)
235+
var mediaType = details.ResultType;
236+
switch (mediaType)
234237
{
235238
case MediaTypes.Tv:
236-
{
237-
var pickedResult = CastResult(isPickedById ? typeof(TvShow) : typeof(SearchTv), result);
238-
var year = pickedResult.FirstAirDate?.Year.ToString(CultureInfo.InvariantCulture) ?? "";
239-
AddToPickedList(pickedResult.Name, year, rating, fullFolderPath, folderName, localPosterPath);
240-
id = pickedResult.Id;
241-
break;
242-
}
239+
{
240+
var pickedResult = CastResult(details.IsPickedById ? typeof(TvShow) : typeof(SearchTv), details.Result);
241+
var year = pickedResult.FirstAirDate?.Year.ToString(CultureInfo.InvariantCulture) ?? "";
242+
AddToPickedList(pickedResult.Name, year, details.Rating, details.FullFolderPath, details.FolderName, details.LocalPosterPath);
243+
id = pickedResult.Id;
244+
break;
245+
}
243246
case MediaTypes.Movie:
244-
{
245-
var pickedResult = CastResult(isPickedById ? typeof(Movie) : typeof(SearchMovie), result);
246-
var year = pickedResult.ReleaseDate?.Year.ToString(CultureInfo.InvariantCulture) ?? "";
247-
AddToPickedList(pickedResult.Title, year, rating, fullFolderPath, folderName, localPosterPath);
248-
id = pickedResult.Id;
249-
break;
250-
}
247+
{
248+
var pickedResult = CastResult(details.IsPickedById ? typeof(Movie) : typeof(SearchMovie), details.Result);
249+
var year = pickedResult.ReleaseDate?.Year.ToString(CultureInfo.InvariantCulture) ?? "";
250+
AddToPickedList(pickedResult.Title, year, details.Rating, details.FullFolderPath, details.FolderName, details.LocalPosterPath);
251+
id = pickedResult.Id;
252+
break;
253+
}
251254
case MediaTypes.Collection:
252-
{
253-
var pickedResult = CastResult(isPickedById ? typeof(Collection) : typeof(SearchCollection), result);
254-
AddToPickedList(pickedResult.Name, null, rating, fullFolderPath, folderName, localPosterPath);
255-
id = pickedResult.Id;
256-
break;
257-
}
255+
{
256+
var pickedResult = CastResult(details.IsPickedById ? typeof(Collection) : typeof(SearchCollection), details.Result);
257+
AddToPickedList(pickedResult.Name, null, details.Rating, details.FullFolderPath, details.FolderName, details.LocalPosterPath);
258+
id = pickedResult.Id;
259+
break;
260+
}
258261
case MediaTypes.Mtv:
259-
mediaType = SelectMtvType(result, fullFolderPath, rating, isPickedById, out id, folderName, localPosterPath);
262+
mediaType = SelectMtvType(details, out id);
260263
break;
261-
default: throw new InvalidDataException($"Invalid Result Type: {resultType}");
264+
default: throw new InvalidDataException($"Invalid Result Type: {mediaType}");
262265
}
263266

264267
return mediaType;
265268
}
266269

267-
private string SelectMtvType(dynamic result, string fullFolderPath, string rating, bool isPickedById, out int id, string folderName, string localPosterPath)
270+
private string SelectMtvType(SearchResultData details, out int id)
268271
{
269-
var mediaType = result.MediaType;
272+
var mediaType = details.Result.MediaType;
270273
id = 0;
274+
details.ResultType = mediaType.ToString();
271275
return mediaType switch
272276
{
273-
MediaType.Tv => PickResult(result, MediaTypes.Tv, fullFolderPath, rating, isPickedById, out id, folderName,
274-
localPosterPath),
275-
MediaType.Movie => PickResult(result, MediaTypes.Movie, fullFolderPath, rating, isPickedById, out id,
276-
folderName, localPosterPath),
277+
MediaType.Tv => PickResult(details, out id),
278+
MediaType.Movie => PickResult(details, out id),
277279
_ => mediaType
278280
};
279281
}

0 commit comments

Comments
 (0)