Skip to content

Commit

Permalink
feat: refactor to use new search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper Christensen Mayntzhusen committed Feb 17, 2022
1 parent 8ff1105 commit 7e756bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public SkyfishController(VideoPickerService videoPickerService) {
}

[Route("umbraco/api/skyfish/GetThumbnail")]
public object GetThumbnail(string videoId) {
public object GetThumbnail(string uniqueMediaId) {

if (!_videoPickerService.Providers.TryGet(out SkyfishVideoProvider provider)) return Request.CreateResponse(HttpStatusCode.NotFound);
if (!_videoPickerService.Config.TryGetConfig(provider, out SkyfishConfig config)) return Request.CreateResponse(HttpStatusCode.NotFound);
Expand All @@ -31,8 +31,9 @@ public object GetThumbnail(string videoId) {

// Initialize a new service for the Skyfish API
SkyfishHttpService api = SkyfishHttpService.CreateFromKeys(credentials.PublicKey, credentials.SecretKey, credentials.Username, credentials.Password);
SkyfishHttpHelper skyHelper = new SkyfishHttpHelper(api);

var thumbnailUrl = api.GetThumbnailUrl(int.Parse(videoId));
var thumbnailUrl = skyHelper.GetVideoByUniqueMediaId(int.Parse(uniqueMediaId)).ThumbnailUrl;

if (!string.IsNullOrWhiteSpace(thumbnailUrl)) return Redirect(thumbnailUrl);
return Request.CreateResponse(HttpStatusCode.NotFound);
Expand Down
12 changes: 6 additions & 6 deletions src/Skybrud.VideoPicker.Skyfish/SkyfishVideoDetails.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Limbo.Integrations.Skyfish.Models;
using Limbo.Integrations.Skyfish.Models.Media;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Skybrud.Essentials.Json.Extensions;
Expand Down Expand Up @@ -29,11 +29,11 @@ public class SkyfishVideoDetails : IVideoDetails {

#region Constructors

public SkyfishVideoDetails(SkyfishVideo video, VideoThumbnail[] thumbnails) {
Id = video.VideoId.ToString();
Title = string.IsNullOrWhiteSpace(video.VideoTitle) ? video.FileName : video.VideoTitle;
Description = video.VideoDescription;
EmbedUrl = video.EmbedUrl;
public SkyfishVideoDetails(SkyfishMediaItem video, VideoThumbnail[] thumbnails, string embedUrl) {
Id = video.UniqueMediaId.ToString();
Title = string.IsNullOrWhiteSpace(video.Title) ? video.FileName : video.Title;
Description = video.Description;
EmbedUrl = embedUrl;
Thumbnails = thumbnails;
}

Expand Down
15 changes: 8 additions & 7 deletions src/Skybrud.VideoPicker.Skyfish/SkyfishVideoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Limbo.Integrations.Skyfish;
using Limbo.Integrations.Skyfish.Models;
using Limbo.Integrations.Skyfish.Models.Media;
using Newtonsoft.Json.Linq;
using Skybrud.Essentials.Json.Extensions;
using Skybrud.Essentials.Strings.Extensions;
using Skybrud.VideoPicker.Exceptions;
using Skybrud.VideoPicker.Models;
using Skybrud.VideoPicker.Models.Config;
Expand Down Expand Up @@ -57,15 +56,17 @@ public VideoPickerValue GetVideo(VideoPickerService service, IVideoOptions optio

// Initialize a new service for the Skyfish API
SkyfishHttpService api = SkyfishHttpService.CreateFromKeys(credentials.PublicKey, credentials.SecretKey, credentials.Username, credentials.Password);
SkyfishHttpHelper skyHelper = new SkyfishHttpHelper(api);

SkyfishVideo video = api.GetVideo(int.Parse(o.VideoId));
SkyfishMediaItem video = skyHelper.GetVideoByMediaId(int.Parse(o.VideoId));
string embedUrl = skyHelper.GetEmbedUrlByUniqueMediaId(video.UniqueMediaId);

// As thumbnail URLs received from the Skyfish API expire over time, we need to create our own solution to handle thumbnails URLs
VideoThumbnail[] thumbnails = GetThumbnails(video);

VideoProviderDetails provider = new VideoProviderDetails(Alias, Name);

SkyfishVideoDetails details = new SkyfishVideoDetails(video, thumbnails);
SkyfishVideoDetails details = new SkyfishVideoDetails(video, thumbnails, embedUrl);

SkyfishEmbedOptions embed = new SkyfishEmbedOptions(details);

Expand Down Expand Up @@ -98,7 +99,7 @@ internal bool IsValidName(string videoName) {
return videoName != null && Regex.IsMatch(videoName, "^([0-9_]+)$");
}

internal VideoThumbnail[] GetThumbnails(SkyfishVideo video) {
internal VideoThumbnail[] GetThumbnails(SkyfishMediaItem video) {

List<VideoThumbnail> thumbnails = new List<VideoThumbnail>();

Expand All @@ -108,8 +109,8 @@ internal VideoThumbnail[] GetThumbnails(SkyfishVideo video) {

}

private VideoThumbnail GetThumbnail(SkyfishVideo video) {
string url = $"/umbraco/api/Skyfish/GetThumbnail?videoId={video.VideoId}";
private VideoThumbnail GetThumbnail(SkyfishMediaItem video) {
string url = $"/umbraco/api/Skyfish/GetThumbnail?uniqueMediaId={video.UniqueMediaId}";

return new VideoThumbnail(0, 0, url);
}
Expand Down

0 comments on commit 7e756bf

Please sign in to comment.