Skip to content

Commit

Permalink
Fixed downloading selected movie file version
Browse files Browse the repository at this point in the history
  • Loading branch information
fxsth committed Sep 24, 2023
1 parent 0bd2d20 commit 9a51bc6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
8 changes: 7 additions & 1 deletion Web/ClientApp/src/components/DownloadButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default class DownloadButton extends React.Component {
this.state = {
mediaKey: this.props.mediaKey,
isLoading: false,
mediatype: this.props.mediaType
mediatype: this.props.mediaType,
mediaFileKey: this.props.mediaFileKey
};
}

Expand Down Expand Up @@ -39,6 +40,11 @@ export default class DownloadButton extends React.Component {
season: this.props.season
})
}
if (typeof this.props.mediaFileKey !== 'undefined') {
input = input + '?' + new URLSearchParams({
mediaFileKey: this.props.mediaFileKey
})
}
return fetch(input, settings)
.then(response => {
if (response.status >= 200 && response.status < 300) {
Expand Down
2 changes: 1 addition & 1 deletion Web/ClientApp/src/components/Movies.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class Movies extends Component {
<td>{mediaFile.videoCodec}</td>
<td>{mediaFile.videoResolution}</td>
<td>{this.humanizeByteSize(mediaFile.totalBytes)}</td>
<td><DownloadButton mediaType='movie' mediaKey={movie.ratingKey}>Download</DownloadButton></td>
<td><DownloadButton mediaType='movie' mediaKey={movie.ratingKey} mediaFileKey={mediaFile.downloadUri}>Download</DownloadButton></td>
</tr>)

)}
Expand Down
4 changes: 2 additions & 2 deletions Web/Controllers/DownloadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public async Task<IEnumerable<DownloadElementResource>> GetPendingDownloads()
}

[HttpPost("movie/{key}")]
public async Task DownloadMovie( string key, [FromQuery] string mediaFileKey)
public async Task DownloadMovie( string key, [FromQuery] string? mediaFileKey)
{
await _downloadService.DownloadMovie(key, mediaFileKey);
}

[HttpPost("episode/{key}")]
public async Task DownloadEpisode( string key, [FromQuery] string mediaFileKey)
public async Task DownloadEpisode( string key, [FromQuery] string? mediaFileKey)
{
await _downloadService.DownloadEpisode(key, mediaFileKey);
}
Expand Down
10 changes: 7 additions & 3 deletions Web/Services/DownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public IReadOnlyCollection<DownloadElement> GetAll()
return returnList;
}

private async Task<DownloadElement> CreateDownloadElement(string key, string mediaFileKey, ElementType elementType)
private async Task<DownloadElement> CreateDownloadElement(string key, string? mediaFileKey, ElementType elementType)
{
using (var scope = _scopeFactory.CreateScope())
{
Expand All @@ -60,7 +60,11 @@ private async Task<DownloadElement> CreateDownloadElement(string key, string med
IMediaElement? mediaElement = await GetMediaElement(unitOfWork, elementType, key);
if (mediaElement == null)
throw new ArgumentException();
MediaFile? mediaFile = mediaElement.MediaFiles.FirstOrDefault(x => x.DownloadUri == mediaFileKey);
MediaFile? mediaFile;
if (mediaFileKey == null)
mediaFile = await SelectMediaFile(mediaElement.MediaFiles, settingsService);
else
mediaFile = mediaElement.MediaFiles.FirstOrDefault(x => x.DownloadUri == mediaFileKey);
if (mediaElement == null)
{
_logger.LogError("Could not prepare download of {0} due to missing media file.", mediaElement!.Title);
Expand Down Expand Up @@ -265,7 +269,7 @@ private void StartDownloaderIfNotActive()
}
}

private async Task<MediaFile> SelectMediaFile(IEnumerable<MediaFile> mediaFiles, SettingsService settingsService)
private async Task<MediaFile> SelectMediaFile(IEnumerable<MediaFile> mediaFiles, ISettingsService settingsService)
{
var preferredResolution = await settingsService.GetPreferredResolution();
var preferredVideoCodec = await settingsService.GetPreferredVideoCodec();
Expand Down

0 comments on commit 9a51bc6

Please sign in to comment.