protected void ImportRecording(string fileName) { ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>(); IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(); List <Share> possibleShares = new List <Share>(); // Shares can point to different depth, we try to find the deepest one foreach (var share in mediaLibrary.GetShares(systemResolver.LocalSystemId).Values) { var dir = LocalFsResourceProviderBase.ToDosPath(share.BaseResourcePath.LastPathSegment.Path); if (dir != null && fileName.StartsWith(dir, StringComparison.InvariantCultureIgnoreCase)) { possibleShares.Add(share); } } if (possibleShares.Count == 0) { ServiceRegistration.Get <ILogger>().Warn("SlimTvService: Received notifaction of new recording but could not find a media source. Have you added recordings folder as media source? File: {0}", fileName); return; } Share usedShare = possibleShares.OrderByDescending(s => s.BaseResourcePath.LastPathSegment.Path.Length).First(); IImporterWorker importerWorker = ServiceRegistration.Get <IImporterWorker>(); importerWorker.ScheduleImport(LocalFsResourceProviderBase.ToResourcePath(fileName), usedShare.MediaCategories, false); }
protected bool GetSharesForPath(ResourcePath resourcePath, string localSystemId, out List <Share> possibleShares) { IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(); possibleShares = new List <Share>(); foreach (var share in mediaLibrary.GetShares(localSystemId).Values) { if (resourcePath.ToString().StartsWith(share.BaseResourcePath.ToString(), StringComparison.InvariantCultureIgnoreCase)) { possibleShares.Add(share); } } return(possibleShares.Count > 0); }
protected bool GetSharesForPath(string fileName, string localSystemId, out List <Share> possibleShares) { IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(); possibleShares = new List <Share>(); foreach (var share in mediaLibrary.GetShares(localSystemId).Values) { var dir = LocalFsResourceProviderBase.ToDosPath(share.BaseResourcePath.LastPathSegment.Path); if (dir != null && fileName.StartsWith(dir, StringComparison.InvariantCultureIgnoreCase)) { possibleShares.Add(share); } } return(possibleShares.Count > 0); }
public ICollection <string> GetMediaCategories(ResourcePath path) { ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>(); IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(); ICollection <Share> shares = mediaLibrary.GetShares(systemResolver.LocalSystemId).Values; Share bestShare = SharesHelper.BestContainingPath(shares, path); List <string> categories = new List <string>(); if (bestShare != null) { categories.AddRange(bestShare.MediaCategories); } return(categories); }
protected ICollection <Share> GetAllowedShares() { IMediaLibrary library = ServiceRegistration.Get <IMediaLibrary>(); ICollection <Share> shares = library.GetShares(null)?.Values; IUserProfileDataManagement userProfileDataManagement = ServiceRegistration.Get <IUserProfileDataManagement>(); var res = userProfileDataManagement.GetProfileAsync(UserId).Result; if (!res.Success || !res.Result.RestrictShares) { return(shares); } var allowedShareIds = res.Result.GetAllowedShares(); return(shares.Where(s => allowedShareIds.Contains(s.ShareId)).ToList()); }
static UPnPError OnScheduleImports(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context) { outParams = null; ICollection <Guid> shareIds = MarshallingHelper.ParseCsvGuidCollection((string)inParams[0]); string importJobTypeStr = (string)inParams[1]; ImportJobType importJobType; UPnPError error = ParseImportJobType("ImportJobType", importJobTypeStr, out importJobType); if (error != null) { return(error); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(); IDictionary <Guid, Share> allShares = mediaLibrary.GetShares(null); IDictionary <string, ICollection <Share> > importRequests = new Dictionary <string, ICollection <Share> >(); foreach (Guid shareId in shareIds) { Share importShare; if (!allShares.TryGetValue(shareId, out importShare)) { // Share not found continue; } ICollection <Share> systemShares; if (!importRequests.TryGetValue(importShare.SystemId, out systemShares)) { importRequests[importShare.SystemId] = new List <Share> { importShare } } ; else { systemShares.Add(importShare); } } // Local imports at the server ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>(); ICollection <Share> shares; if (importRequests.TryGetValue(systemResolver.LocalSystemId, out shares)) { IImporterWorker importerWorker = ServiceRegistration.Get <IImporterWorker>(); foreach (Share share in shares) { if (importJobType == ImportJobType.Import) { importerWorker.ScheduleImport(share.BaseResourcePath, share.MediaCategories, true); } else { importerWorker.ScheduleRefresh(share.BaseResourcePath, share.MediaCategories, true); } } } ServiceRegistration.Get <IThreadPool>().Add(() => ScheduleClientImports(importRequests, importJobType)); return(null); }