public Share RegisterShare(ResourcePath baseResourcePath, string shareName, bool useShareWatcher, IEnumerable <string> mediaCategories)
        {
            Share sd = Share.CreateNewLocalShare(baseResourcePath, shareName, useShareWatcher, mediaCategories);

            _shares.Add(sd.ShareId, sd);
            SaveSharesToSettings();
            SharesMessaging.SendShareMessage(SharesMessaging.MessageType.ShareAdded, sd);
            return(sd);
        }
Пример #2
0
        public ICollection <Share> CreateDefaultShares()
        {
            List <Share> result = new List <Share>();
            Guid         localFsResourceProviderId = LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID;

            if (LocalResourceProviders.ContainsKey(localFsResourceProviderId))
            {
                string folderPath;
                if (WindowsAPI.GetSpecialFolder(WindowsAPI.SpecialFolder.MyMusic, out folderPath))
                {
                    folderPath = LocalFsResourceProviderBase.ToProviderPath(folderPath);
                    string[] mediaCategories = new[] { DefaultMediaCategories.Audio.ToString() };
                    Share    sd = Share.CreateNewLocalShare(ResourcePath.BuildBaseProviderPath(localFsResourceProviderId, folderPath),
                                                            MY_MUSIC_SHARE_NAME_RESOURE, mediaCategories);
                    result.Add(sd);
                }

                if (WindowsAPI.GetSpecialFolder(WindowsAPI.SpecialFolder.MyVideos, out folderPath))
                {
                    folderPath = LocalFsResourceProviderBase.ToProviderPath(folderPath);
                    string[] mediaCategories = new[] { DefaultMediaCategories.Video.ToString() };
                    Share    sd = Share.CreateNewLocalShare(ResourcePath.BuildBaseProviderPath(localFsResourceProviderId, folderPath),
                                                            MY_VIDEOS_SHARE_NAME_RESOURCE, mediaCategories);
                    result.Add(sd);
                }

                if (WindowsAPI.GetSpecialFolder(WindowsAPI.SpecialFolder.MyPictures, out folderPath))
                {
                    folderPath = LocalFsResourceProviderBase.ToProviderPath(folderPath);
                    string[] mediaCategories = new[] { DefaultMediaCategories.Image.ToString() };
                    Share    sd = Share.CreateNewLocalShare(ResourcePath.BuildBaseProviderPath(localFsResourceProviderId, folderPath),
                                                            MY_PICTURES_SHARE_NAME_RESOURCE, mediaCategories);
                    result.Add(sd);
                }
            }
            if (result.Count > 0)
            {
                return(result);
            }
            // Fallback: If no share was added for the defaults above, use the provider's root folders
            result.AddRange(LocalBaseResourceProviders.Select(resourceProvider => resourceProvider.Metadata).Select(
                                metadata => Share.CreateNewLocalShare(ResourcePath.BuildBaseProviderPath(metadata.ResourceProviderId, "/"), metadata.Name, null)));
            return(result);
        }
Пример #3
0
        public ICollection <Share> CreateDefaultShares()
        {
            List <Share> result = new List <Share>();
            Guid         localFsResourceProviderId = LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID;

            if (LocalResourceProviders.ContainsKey(localFsResourceProviderId))
            {
                string folderPath;
                if (WindowsAPI.GetSpecialFolder(Environment.SpecialFolder.MyMusic, out folderPath))
                {
                    folderPath = LocalFsResourceProviderBase.ToProviderPath(folderPath);
                    string[] mediaCategories = new[] { DefaultMediaCategories.Audio.ToString() };
                    Share    sd = Share.CreateNewLocalShare(ResourcePath.BuildBaseProviderPath(localFsResourceProviderId, folderPath),
                                                            MY_MUSIC_SHARE_NAME_RESOURE, true, mediaCategories);
                    result.Add(sd);
                }

                if (WindowsAPI.GetSpecialFolder(Environment.SpecialFolder.MyVideos, out folderPath))
                {
                    folderPath = LocalFsResourceProviderBase.ToProviderPath(folderPath);
                    string[] mediaCategories = new[] { DefaultMediaCategories.Video.ToString() };
                    Share    sd = Share.CreateNewLocalShare(ResourcePath.BuildBaseProviderPath(localFsResourceProviderId, folderPath),
                                                            MY_VIDEOS_SHARE_NAME_RESOURCE, true, mediaCategories);
                    result.Add(sd);
                }

                if (WindowsAPI.GetSpecialFolder(Environment.SpecialFolder.MyPictures, out folderPath))
                {
                    folderPath = LocalFsResourceProviderBase.ToProviderPath(folderPath);
                    string[] mediaCategories = new[] { DefaultMediaCategories.Image.ToString() };
                    Share    sd = Share.CreateNewLocalShare(ResourcePath.BuildBaseProviderPath(localFsResourceProviderId, folderPath),
                                                            MY_PICTURES_SHARE_NAME_RESOURCE, true, mediaCategories);
                    result.Add(sd);
                }
            }
            return(result);
        }
        protected void PrepareMediaSources()
        {
            Dictionary <string, ICollection <MediaCategory> > checkFolders = new Dictionary <string, ICollection <MediaCategory> >();
            List <string> recordingFolders;
            string        singlePattern;
            string        seriesPattern;

            if (!GetRecordingConfiguration(out recordingFolders, out singlePattern, out seriesPattern))
            {
                ServiceRegistration.Get <ILogger>().Warn("SlimTvService: Unable to configure MediaSource for recordings, probably TV configuration wasn't run yet.");
                return;
            }

            string movieSubfolder  = GetFixedFolderPart(singlePattern);
            string seriesSubfolder = GetFixedFolderPart(seriesPattern);

            foreach (var recordingFolder in recordingFolders)
            {
                if (!string.IsNullOrEmpty(movieSubfolder) && !string.IsNullOrEmpty(seriesSubfolder))
                {
                    // If there are different target folders defined, register the media sources with specialized Series/Movie types
                    checkFolders.Add(FileUtils.CheckTrailingPathDelimiter(Path.Combine(recordingFolder, movieSubfolder)), new HashSet <MediaCategory> {
                        DefaultMediaCategories.Video, Movie
                    });
                    checkFolders.Add(FileUtils.CheckTrailingPathDelimiter(Path.Combine(recordingFolder, seriesSubfolder)), new HashSet <MediaCategory> {
                        DefaultMediaCategories.Video, Series
                    });
                }
                else
                {
                    checkFolders.Add(FileUtils.CheckTrailingPathDelimiter(recordingFolder), new HashSet <MediaCategory> {
                        DefaultMediaCategories.Video
                    });
                }
            }

            IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>();
            int           cnt          = 1;

            foreach (var folderTypes in checkFolders)
            {
                try
                {
                    List <Share> shares;
                    // Check if there are already share(s) for the folder
                    var path         = folderTypes.Key;
                    var resourcePath = BuildResourcePath(path);

                    if (GetSharesForPath(resourcePath, out shares))
                    {
                        continue;
                    }

                    var mediaCategories = folderTypes.Value.Select(mc => mc.CategoryName);

                    Share sd = Share.CreateNewLocalShare(resourcePath, string.Format("Recordings ({0})", cnt),
                                                         // Important: don't monitor recording sources by ShareWatcher, we manage them during recording start / end events!
                                                         false,
                                                         mediaCategories);

                    mediaLibrary.RegisterShare(sd);
                    cnt++;
                }
                catch (Exception ex)
                {
                    ServiceRegistration.Get <ILogger>().Error("SlimTvService: Error registering new MediaSource.", ex);
                }
            }
        }