Skip to content

Commit

Permalink
Merge pull request #20 from DineshSolanki/feature/FindById
Browse files Browse the repository at this point in the history
Feature/find by id
  • Loading branch information
DineshSolanki authored Aug 6, 2021
2 parents 1422d24 + 5d55ce8 commit a2b3c19
Show file tree
Hide file tree
Showing 20 changed files with 467 additions and 86 deletions.
2 changes: 2 additions & 0 deletions FoliCon/Models/GlobalVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ internal static class GlobalVariables
"Alternate" => IconOverlay.Alternate,
_ => IconOverlay.Alternate
};

public static string MediaInfoFile = "info.folicon";
}
}
6 changes: 4 additions & 2 deletions FoliCon/Models/ListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ public class ListItem : BindableBase
private string _folder;
private string _overview;
private string _poster;
private int _id;
public string Title { get => _title; set => SetProperty(ref _title, value); }
public string Year { get => _year; set => SetProperty(ref _year, value); }
public string Rating { get => _rating; set => SetProperty(ref _rating, value); }
public string Folder { get => _folder; set => SetProperty(ref _folder, value); }
public string Overview { get => _overview; set => SetProperty(ref _overview, value); }
public string Poster { get => _poster; set => SetProperty(ref _poster, value); }

public ListItem(string title, string year, string rating, string overview = null, string poster = null, string folder = "")
public int Id { get => _id; set => SetProperty(ref _id, value); }
public ListItem(string title, string year, string rating, string overview = null, string poster = null, string folder = "", int id = 0)
{
Title = title;
Year = year;
Rating = rating;
Overview = overview;
Poster = poster;
Folder = folder;
Id = id;
}

public ListItem()
Expand Down
10 changes: 6 additions & 4 deletions FoliCon/Modules/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ public static void ShowMessageBox(this IDialogService dialogService, string mess
}

public static void ShowSearchResult(this IDialogService dialogService, string searchMode, string query,
string folderPath, ResultResponse result, Tmdb tmdbObject, IgdbClass igdbObject,
string folderPath, ResultResponse result, Tmdb tmdbObject, IgdbClass igdbObject, bool isPickedById,
Action<IDialogResult> callBack)
{
var p = new DialogParameters
{
{"query", query}, {"result", result}, {"searchmode", searchMode}, {"tmdbObject", tmdbObject},
{"igdbObject", igdbObject},
{"folderpath", folderPath}
{"folderpath", folderPath},
{"isPickedById" , isPickedById}
};
dialogService.ShowDialog("SearchResult", p, callBack);
}
Expand Down Expand Up @@ -57,11 +58,12 @@ public static void ShowAboutBox(this IDialogService dialogService, Action<IDialo
{
dialogService.ShowDialog("AboutBox", new DialogParameters(), callBack);
}
public static void ShowPosterPicker(this IDialogService dialogService, Tmdb tmdbObject, ResultResponse result,int pickedIndex, System.Collections.ObjectModel.ObservableCollection<ListItem> resultData, Action<IDialogResult> callBack)
public static void ShowPosterPicker(this IDialogService dialogService, Tmdb tmdbObject, ResultResponse result,int pickedIndex, System.Collections.ObjectModel.ObservableCollection<ListItem> resultData, bool isPickedById, Action<IDialogResult> callBack)
{
var p = new DialogParameters
{
{"pickedIndex", pickedIndex}, {"result", result}, {"tmdbObject",tmdbObject} , {"resultList", resultData}
{"pickedIndex", pickedIndex}, {"result", result}, {"tmdbObject",tmdbObject} , {"resultList", resultData},
{"isPickedById" , isPickedById}
};
dialogService.ShowDialog("PosterPicker", p, callBack);
}
Expand Down
15 changes: 14 additions & 1 deletion FoliCon/Modules/IGDBClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public async Task<ResultResponse> SearchGameAsync(string query)
};
return response;
}
public async Task<ResultResponse> SearchGameByIdAsync(string id)
{
Contract.Assert(_serviceClient != null);
var r = await _serviceClient.QueryAsync<Game>(IGDBClient.Endpoints.Games,
$"fields name,first_release_date,total_rating,summary,cover.*; where id = {id};");
var response = new ResultResponse
{
MediaType = MediaTypes.Game,
Result = r
};
return response;
}

public static ObservableCollection<ListItem> ExtractGameDetailsIntoListItem(Game[] result)
{
Expand Down Expand Up @@ -81,7 +93,8 @@ public void ResultPicked(Game result, string fullFolderPath, string rating = "")
var year = result.FirstReleaseDate != null ? result.FirstReleaseDate.Value.Year.ToString(CultureInfo.InvariantCulture) : "";
var posterUrl = ImageHelper.GetImageUrl(result.Cover.Value.ImageId, ImageSize.HD720);
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, result.Name, rating, fullFolderPath, folderName,
year);
year, (int)(result.Id ?? 0));
if (result.Id != null) Util.SaveMediaInfo((int)result.Id, "Game", fullFolderPath);
var tempImage = new ImageToDownload
{
LocalPath = localPosterPath,
Expand Down
14 changes: 12 additions & 2 deletions FoliCon/Modules/LangProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ private void UpdateLangs()
OnPropertyChanged(nameof(UsePosterOverlay));
OnPropertyChanged(nameof(Version));
OnPropertyChanged(nameof(Year));
OnPropertyChanged(nameof(ExceptionOccurred));
OnPropertyChanged(nameof(DeleteMediaInfo));
OnPropertyChanged(nameof(DeleteMediaInfoTooltip));
OnPropertyChanged(nameof(DeleteMediaInfoConfirmation));
OnPropertyChanged(nameof(ConfirmMediaInfoDeletion));
}

public string About => Lang.About;
Expand Down Expand Up @@ -412,6 +415,10 @@ private void UpdateLangs()

public string Year => Lang.Year;
public string ExceptionOccurred => Lang.ExceptionOccurred;
public string ConfirmMediaInfoDeletion => Lang.ConfirmMediaInfoDeletion;
public string DeleteMediaInfoConfirmation => Lang.DeleteMediaInfoConfirmation;
public string DeleteMediaInfoTooltip => Lang.DeleteMediaInfoTooltip;
public string DeleteMediaInfo => Lang.DeleteMediaInfo;


public event PropertyChangedEventHandler PropertyChanged;
Expand Down Expand Up @@ -671,6 +678,9 @@ public class LangKeys
public static string Year = nameof(Year);

public static string ExceptionOccurred = nameof(ExceptionOccurred);

public static string ConfirmMediaInfoDeletion = nameof(ConfirmMediaInfoDeletion);
public static string DeleteMediaInfoConfirmation = nameof(DeleteMediaInfoConfirmation);
public static string DeleteMediaInfoTooltip = nameof(DeleteMediaInfoTooltip);
public static string DeleteMediaInfo = nameof(DeleteMediaInfo);
}
}
121 changes: 103 additions & 18 deletions FoliCon/Modules/TMDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
using System.IO;
using System.Threading.Tasks;
using TMDbLib.Client;
using TMDbLib.Objects.Collections;
using TMDbLib.Objects.General;
using TMDbLib.Objects.Movies;
using TMDbLib.Objects.Search;
using TMDbLib.Objects.TvShows;

namespace FoliCon.Modules
{
Expand Down Expand Up @@ -128,6 +131,47 @@ public static ObservableCollection<ListItem> ExtractResourceDetailsIntoListItem(
return items;
}

public static ObservableCollection<ListItem> ExtractTvDetailsIntoListItem(TvShow result)
{
var items = new ObservableCollection<ListItem>();
var mediaName = result.Name;
var year = result.FirstAirDate != null ? result.FirstAirDate.Value.Year.ToString(CultureInfo.InvariantCulture) : "";
var rating = result.VoteAverage.ToString(CultureInfo.CurrentCulture);
var overview = result.Overview;
var poster = result.PosterPath != null ? SmallPosterBase + result.PosterPath : null;
items.Add(new ListItem(mediaName, year, rating, overview, poster));

return items;
}

public static ObservableCollection<ListItem> ExtractCollectionDetailsIntoListItem(
Collection result)
{
var items = new ObservableCollection<ListItem>();
var mediaName = result.Name;
const string year = "";
const string rating = "";
const string overview = "";
var poster = Convert.ToString(result.PosterPath != null ? SmallPosterBase + result.PosterPath : null, CultureInfo.InvariantCulture);
items.Add(new ListItem(mediaName, year, rating, overview, poster));

return items;
}

public static ObservableCollection<ListItem> ExtractMoviesDetailsIntoListItem(
Movie result)
{
var items = new ObservableCollection<ListItem>();
var mediaName = result.Title;
var year = result.ReleaseDate != null ? result.ReleaseDate.Value.Year.ToString(CultureInfo.InvariantCulture) : "";
var rating = result.VoteAverage.ToString(CultureInfo.CurrentCulture);
var overview = result.Overview;
var poster = result.PosterPath != null ? SmallPosterBase + result.PosterPath : null;
items.Add(new ListItem(mediaName, year, rating, overview, poster));

return items;
}

public static ObservableCollection<ListItem> ExtractTvDetailsIntoListItem(SearchContainer<SearchTv> result)
{
var items = new ObservableCollection<ListItem>();
Expand All @@ -143,7 +187,6 @@ public static ObservableCollection<ListItem> ExtractTvDetailsIntoListItem(Search

return items;
}

/// <summary>
/// Prepares the Selected Result for Download And final List View
/// </summary>
Expand All @@ -152,39 +195,45 @@ public static ObservableCollection<ListItem> ExtractTvDetailsIntoListItem(Search
/// <param name="fullFolderPath">Full Path to the current Media Folder</param>
/// <param name="rating">Rating for media</param>
/// TODO: Merge parameter response and resultType.
public void ResultPicked(dynamic result, string resultType, string fullFolderPath, string rating = "")
public void ResultPicked(dynamic result, string resultType, string fullFolderPath, string rating = "",bool isPickedById = false)
{
if (result.PosterPath == null)
{
throw new InvalidDataException("NoPoster");
}

var id = 0;
var type = resultType;
if (string.IsNullOrWhiteSpace(rating) && resultType != MediaTypes.Collection)
{ rating = result.VoteAverage.ToString(CultureInfo.CurrentCulture); }
{ rating = result.VoteAverage.ToString(CultureInfo.InvariantCulture); }

var folderName = Path.GetFileName(fullFolderPath);
var localPosterPath = fullFolderPath + @"\" + folderName + ".png";
string posterUrl = string.Concat(PosterBase, result.PosterPath);

if (resultType == MediaTypes.Tv)
{
var pickedResult = (SearchTv)result;
var year = pickedResult.FirstAirDate != null ? pickedResult.FirstAirDate.Value.Year.ToString(CultureInfo.InvariantCulture) : "";
dynamic pickedResult = isPickedById ? (TvShow)result : (SearchTv)result;
var year = pickedResult.FirstAirDate != null ? pickedResult.FirstAirDate.Year.ToString(CultureInfo.InvariantCulture) : "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Name,
rating, fullFolderPath, folderName,
year);
year, pickedResult.Id);
id = pickedResult.Id;
}
else if (resultType == MediaTypes.Movie)
{
var pickedResult = (SearchMovie)result;
var year = pickedResult.ReleaseDate != null ? pickedResult.ReleaseDate.Value.Year.ToString(CultureInfo.InvariantCulture) : "";
dynamic pickedResult = isPickedById ? (Movie)result : (SearchMovie)result;
var year = pickedResult.ReleaseDate != null ? pickedResult.ReleaseDate.Year.ToString(CultureInfo.InvariantCulture) : "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Title,
rating, fullFolderPath, folderName, year);
rating, fullFolderPath, folderName, year, pickedResult.Id);
id = pickedResult.Id;
}
else if (resultType == MediaTypes.Collection)
{
var searchResult = (SearchCollection)result;
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, searchResult.Name, rating, fullFolderPath,
folderName);
dynamic pickedResult = isPickedById ? (Collection)result : (SearchCollection)result;
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Name, rating, fullFolderPath,
folderName, "", pickedResult.Id);
id = pickedResult.Id;
}
else if (resultType == MediaTypes.Mtv)
{
Expand All @@ -193,29 +242,37 @@ public void ResultPicked(dynamic result, string resultType, string fullFolderPat
{
case MediaType.Tv:
{
SearchTv pickedResult = result;
type = "TV";
dynamic pickedResult = isPickedById ? (TvShow)result : (SearchTv)result;
var year = pickedResult.FirstAirDate != null
? pickedResult.FirstAirDate.Value.Year.ToString(CultureInfo.InvariantCulture)
? pickedResult.FirstAirDate.Year.ToString(CultureInfo.InvariantCulture)
: "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Name,
rating, fullFolderPath, folderName,
year);
year, pickedResult.Id);
id = pickedResult.Id;
break;
}
case MediaType.Movie:
{
SearchMovie pickedResult = result;
type = "Movie";
dynamic pickedResult = isPickedById ? (Movie)result : (SearchMovie)result;
var year = pickedResult.ReleaseDate != null
? pickedResult.ReleaseDate.Value.Year.ToString(CultureInfo.InvariantCulture)
? pickedResult.ReleaseDate.Year.ToString(CultureInfo.InvariantCulture)
: "";
Util.AddToPickedListDataTable(_listDataTable, localPosterPath, pickedResult.Title,
rating, fullFolderPath, folderName,
year);
year, pickedResult.Id);
id = pickedResult.Id;
break;
}
}
}

if (!isPickedById && id != 0)
{
Util.SaveMediaInfo(id, type, fullFolderPath);
}
var tempImage = new ImageToDownload
{
LocalPath = localPosterPath,
Expand Down Expand Up @@ -265,5 +322,33 @@ public async Task<ResultResponse> SearchAsync(string query, string searchMode)
};
return response;
}
/// <summary>
/// Searches TMDB for a query in Specified search mode
/// </summary>
/// <param name="query">Title to search</param>
/// <param name="mediaTypee">Search Mode such as Movie,TV</param>
/// <returns>Returns Search result with its Media Type</returns>
public ResultResponse SearchByIdAsync(int id, string mediaType)
{
object r = null;
if (mediaType == MediaTypes.Movie)
{
r = _serviceClient.GetMovieAsync(id).Result;
}
else if (mediaType == MediaTypes.Collection)
{
r = _serviceClient.GetCollectionAsync(id).Result;
}
else if (mediaType == MediaTypes.Tv)
{
r = _serviceClient.GetTvShowAsync(id).Result;
}
var response = new ResultResponse
{
Result = r,
MediaType = mediaType
};
return response;
}
}
}
Loading

0 comments on commit a2b3c19

Please sign in to comment.