define(["exports","./../common/servicelocator.js"],function(_exports,_servicelocator){function getImageUrl(serverId,itemId,imageOptions){serverId=getImagePath(0,itemId,imageOptions.type,imageOptions.index);return _servicelocator.fileRepository.getImageUrl(serverId)}function getImagePath(serverId,itemId,imageType,index){for(var parts=[],finalParts=(parts.push("images"),parts.push(itemId+"_"+imageType+"_"+(index=index||0).toString()),[]),i=0;i<parts.length;i++)finalParts.push(parts[i]);return finalParts}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;_exports.default={getDirectoryPath:function(item){var parts=[],itemtype=item.Type.toLowerCase(),mediaType=(item.MediaType||"").toLowerCase(),albumArtist=("episode"===itemtype||"series"===itemtype||"season"===itemtype?parts.push("TV"):"trailer"===itemtype?parts.push("Trailers"):"video"===mediaType?parts.push("Videos"):"audio"===itemtype||"musicalbum"===itemtype||"musicartist"===itemtype?parts.push("Music"):"photo"===itemtype||"photoalbum"===itemtype?parts.push("Photos"):"game"!==itemtype&&"gamesystem"!==itemtype||parts.push("Games"),item.AlbumArtist);albumArtist&&parts.push(albumArtist),(albumArtist=item.SeriesName)&&parts.push(albumArtist);(albumArtist=item.SeasonName)&&parts.push(albumArtist),item.Album&&parts.push(item.Album),item.GameSystem&&parts.push(item.GameSystem),("video"===mediaType&&"episode"!==itemtype||"game"===itemtype||item.IsFolder)&&parts.push(item.Name);for(var finalParts=[],i=0;i<parts.length;i++)finalParts.push(_servicelocator.fileRepository.getValidFileName(parts[i]));return finalParts},getLocalFileName:function(item,originalFileName){return originalFileName=originalFileName||item.Name,_servicelocator.fileRepository.getValidFileName(originalFileName)},removeLocalItem:function(localItem){return _servicelocator.itemRepository.getLibraryItem(localItem.ServerId,localItem.ItemId).then(function(item){function onFileDeletedSuccessOrFail(){return _servicelocator.itemRepository.deleteLibraryItem(localItem.ServerId,localItem.ItemId)}var p=Promise.resolve();return item.LocalPath&&(p=p.then(function(){return _servicelocator.fileRepository.deleteFile(item.LocalPath)})),item&&item.Item&&item.Item.MediaSources&&item.Item.MediaSources.forEach(function(mediaSource){mediaSource.MediaStreams&&0<mediaSource.MediaStreams.length&&mediaSource.MediaStreams.forEach(function(mediaStream){mediaStream.Path&&(p=p.then(function(){return _servicelocator.fileRepository.deleteFile(mediaStream.Path)}))})}),p.then(onFileDeletedSuccessOrFail,onFileDeletedSuccessOrFail)},function(){return Promise.resolve()})},downloadFile:function(url,localItem){var imageUrl=getImageUrl(localItem.Item.ServerId,localItem.Item.Id,{type:"Primary",index:0});return _servicelocator.transferManager.downloadFile(url,localItem,imageUrl)},downloadSubtitles:function(url,fileName){return _servicelocator.transferManager.downloadSubtitles(url,fileName)},hasImage:function(serverId,itemId,imageType,index){return serverId=getImagePath(0,itemId,imageType,index),itemId=_servicelocator.fileRepository.getFullMetadataPath(serverId),_servicelocator.fileRepository.fileExists(itemId).then(function(exists){return Promise.resolve(exists)},function(){return Promise.resolve(!1)})},downloadImage:function(localItem,url,serverId,itemId,imageType,index){return serverId=getImagePath(0,itemId,imageType,index),_servicelocator.transferManager.downloadImage(url,serverId)},getImageUrl:getImageUrl,getSubtitleSaveFileName:function(localItem,mediaPath,language,isForced,isHearingImpaired,format){return mediaPath=function(path){var pos=path.lastIndexOf(".");0<pos&&(path=path.substring(0,pos));return path}(mediaPath),mediaPath=_servicelocator.fileRepository.getValidFileName(mediaPath),language&&(mediaPath+="."+language.toLowerCase()),isForced&&(mediaPath+=".forced"),isHearingImpaired&&(mediaPath+=".sdh"),mediaPath=mediaPath+"."+format.toLowerCase(),language=_servicelocator.fileRepository.getParentPath(localItem.LocalPath),_servicelocator.fileRepository.combinePath(language,mediaPath)},getItemFileSize:function(path){return _servicelocator.fileRepository.getItemFileSize(path)},isDownloadFileInQueue:function(path){return _servicelocator.transferManager.isDownloadFileInQueue(path)},getDownloadItemCount:function(){return _servicelocator.transferManager.getDownloadItemCount()},resyncTransfers:function(){return _servicelocator.transferManager.resyncTransfers()},fileExists:function(localFilePath){return _servicelocator.fileRepository.fileExists(localFilePath)},enableBackgroundCompletion:function(){return _servicelocator.transferManager.enableBackgroundCompletion}}});