Exemplo n.º 1
0
        public bool TryCreateResourceAccessor(string path, out IResourceAccessor result)
        {
            string       nativeSystemId;
            ResourcePath nativeResourcePath;

            if (!TryExtractSystemAndPath(path, out nativeSystemId, out nativeResourcePath))
            {
                throw new InvalidDataException("Path '{0}' is not a valid path for remote resource provider", path);
            }
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            SystemName      nativeSystem   = systemResolver.GetSystemNameForSystemId(nativeSystemId);

            if (nativeSystem == null)
            {
                throw new IllegalCallException("Cannot create resource accessor for resource location '{0}' at system '{1}': System is not available", nativeResourcePath, nativeSystemId);
            }
            // Try to access resource locally. This might work if we have the correct resource providers installed.
            if (nativeSystem.IsLocalSystem() && nativeResourcePath.IsValidLocalPath && nativeResourcePath.TryCreateLocalResourceAccessor(out result))
            {
                return(true);
            }
            IFileSystemResourceAccessor fsra;

            if (RemoteFileSystemResourceAccessor.ConnectFileSystem(nativeSystemId, nativeResourcePath, out fsra))
            {
                result = fsra;
                return(true);
            }
            result = null;
            return(false);
        }
        protected bool GetSharesForPath(ResourcePath resourcePath, out List <Share> possibleShares)
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            string          localSystemId  = systemResolver.LocalSystemId;

            return(GetSharesForPath(resourcePath, localSystemId, out possibleShares));
        }
Exemplo n.º 3
0
        public PlaylistItem(VideoViewModel videoInfo, string resolvedPlaybackUrl)
            : base(Guid.Empty, new Dictionary <Guid, IList <MediaItemAspect> >
        {
            { ProviderResourceAspect.ASPECT_ID, new MediaItemAspect[] { new MultipleMediaItemAspect(ProviderResourceAspect.Metadata) } },
            { MediaAspect.ASPECT_ID, new MediaItemAspect[] { new SingleMediaItemAspect(MediaAspect.Metadata) } },
            { VideoAspect.ASPECT_ID, new MediaItemAspect[] { new SingleMediaItemAspect(VideoAspect.Metadata) } },
            { OnlineVideosAspect.ASPECT_ID, new MediaItemAspect[] { new SingleMediaItemAspect(OnlineVideosAspect.Metadata) } },
        })
        {
            SiteName  = videoInfo.SiteName;
            VideoInfo = videoInfo.VideoInfo;

            Aspects[OnlineVideosAspect.ASPECT_ID].First().SetAttribute(OnlineVideosAspect.ATTR_SITEUTIL, SiteName);

            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();

            IList <MultipleMediaItemAspect> providerResourceAspects;

            MediaItemAspect.TryGetAspects(Aspects, ProviderResourceAspect.Metadata, out providerResourceAspects);
            MultipleMediaItemAspect providerResourceAspect = providerResourceAspects.First();

            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_PRIMARY, true);
            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SYSTEM_ID, systemResolver.LocalSystemId);

            if (videoInfo.SiteUtilName == "DownloadedVideo")
            {
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, LocalFsResourceProviderBase.ToResourcePath(resolvedPlaybackUrl).Serialize());
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, "video/unknown");
            }
            else
            {
                Uri uri;
                // Test if the resolved "url" is a real Uri (Sites can provide any content here)
                var isUriSource = Uri.TryCreate(resolvedPlaybackUrl, UriKind.Absolute, out uri);

                var value = isUriSource
                    ? RawUrlResourceProvider.ToProviderResourcePath(resolvedPlaybackUrl).Serialize()
                    : RawTokenResourceProvider.ToProviderResourcePath(resolvedPlaybackUrl).Serialize();
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, value);
                Aspects[OnlineVideosAspect.ASPECT_ID].First().SetAttribute(OnlineVideosAspect.ATTR_LONGURL, value);

                var isBrowser = videoInfo.SiteSettings.Player == PlayerType.Browser;
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE,
                                                    isBrowser
                        ? WebBrowserVideoPlayer.ONLINEVIDEOSBROWSER_MIMETYPE
                        : OnlineVideosPlayer.ONLINEVIDEOS_MIMETYPE);
            }

            MediaItemAspect.SetAttribute(Aspects, MediaAspect.ATTR_TITLE, videoInfo.Title);

            // TODO: Restore line after story plot was moved back to VideoAspect!
            // MediaItemAspect.SetAttribute(aspects, VideoAspect.ATTR_STORYPLOT, videoInfo.Description);

            DateTime parsedAirDate;

            if (DateTime.TryParse(videoInfo.VideoInfo.Airdate, out parsedAirDate))
            {
                MediaItemAspect.SetAttribute(Aspects, MediaAspect.ATTR_RECORDINGTIME, parsedAirDate);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the defaut drive letter for ResourceMounting service. Client and Server will use different defaults (<c>R</c>, <c>S</c>). If the preferred drive letter
        /// is not available, the next higher one will be returned. If none is found, a lower one is tried as last option.
        /// </summary>
        /// <returns>Available drive letter or <c>null</c> if none is available anymore</returns>
        private char?GetDefaultDriveLetter()
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            char?           driveLetter    = systemResolver.SystemType == SystemType.Server
        ? ResourceMountingSettings.DEFAULT_DRIVE_LETTER_SERVER
        : ResourceMountingSettings.DEFAULT_DRIVE_LETTER_CLIENT;

            AvailableDriveLettersSettings adls = new AvailableDriveLettersSettings();
            List <char?> availableLetters      = adls.AvailableDriveLetters.Select(d => (char?)d).ToList();

            // If the preferred drive letter is not available, first try to find a "higher", or if not possible a lower drive letter.
            if (!availableLetters.Contains(driveLetter))
            {
                driveLetter =
                    availableLetters.FirstOrDefault(d => d > driveLetter) ??
                    availableLetters.FirstOrDefault(d => d < driveLetter);
            }

            // Save the new drive letter
            if (driveLetter.HasValue)
            {
                ServiceRegistration.Get <ILogger>().Info("ResourceMountingService: Setup new drive letter {0}", driveLetter);
                ResourceMountingSettings setting = ServiceRegistration.Get <ISettingsManager>().Load <ResourceMountingSettings>();
                setting.DriveLetter = driveLetter;
                _firstRun           = true; // Set a flag so we can ignore the "SettingChanged" event
                ServiceRegistration.Get <ISettingsManager>().Save(setting);
            }
            return(driveLetter);
        }
Exemplo n.º 6
0
        public LocalShares(Share share) : base(ShareEditMode.EditShare)
        {
            ISystemResolver systemResolver  = ServiceRegistration.Get <ISystemResolver>();
            string          localSystemName = systemResolver.GetSystemNameForSystemId(systemResolver.LocalSystemId).HostName ?? systemResolver.LocalSystemId;

            InitializePropertiesWithShare(share, localSystemName);
        }
        /// <summary>
        /// Creates a MediaItem that represents a TV stream. The MediaItem also holds information about stream indices to provide PiP
        /// functions (<paramref name="slotIndex"/>).
        /// </summary>
        /// <param name="slotIndex">Index of the slot (0/1)</param>
        /// <param name="path">Path or URL of the stream</param>
        /// <param name="channel"></param>
        /// <returns></returns>
        public static LiveTvMediaItem CreateMediaItem(int slotIndex, string path, IChannel channel)
        {
            if (!String.IsNullOrEmpty(path))
            {
                ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
                IDictionary <Guid, MediaItemAspect> aspects = new Dictionary <Guid, MediaItemAspect>();
                MediaItemAspect providerResourceAspect;
                MediaItemAspect mediaAspect;

                SlimTvResourceAccessor resourceAccessor = new SlimTvResourceAccessor(slotIndex, path);
                aspects[ProviderResourceAspect.ASPECT_ID] = providerResourceAspect = new MediaItemAspect(ProviderResourceAspect.Metadata);
                aspects[MediaAspect.ASPECT_ID]            = mediaAspect = new MediaItemAspect(MediaAspect.Metadata);
                // VideoAspect needs to be included to associate VideoPlayer later!
                aspects[VideoAspect.ASPECT_ID] = new MediaItemAspect(VideoAspect.Metadata);
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SYSTEM_ID, systemResolver.LocalSystemId);

                String raPath = resourceAccessor.CanonicalLocalResourcePath.Serialize();
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, raPath);

                mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, "Live TV");
                mediaAspect.SetAttribute(MediaAspect.ATTR_MIME_TYPE, "video/livetv"); // Custom mimetype for LiveTv

                LiveTvMediaItem tvStream = new LiveTvMediaItem(new Guid(), aspects);

                tvStream.AdditionalProperties[LiveTvMediaItem.SLOT_INDEX]  = slotIndex;
                tvStream.AdditionalProperties[LiveTvMediaItem.CHANNEL]     = channel;
                tvStream.AdditionalProperties[LiveTvMediaItem.TUNING_TIME] = DateTime.Now;
                return(tvStream);
            }
            return(null);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Convenience constructor to create a resource locator for the local system.
        /// </summary>
        /// <param name="localResourcePath">Path of the desired resource in the local system.</param>
        public ResourceLocator(ResourcePath localResourcePath)
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();

            _nativeSystemId     = systemResolver.LocalSystemId;
            _nativeResourcePath = localResourcePath;
        }
Exemplo n.º 9
0
        public IResourceAccessor CreateAccessor()
        {
            ISystemResolver   systemResolver = ServiceRegistration.Get <ISystemResolver>();
            IResourceAccessor result;

            if (_nativeResourcePath.IsNetworkResource)
            {
                if (_nativeResourcePath.TryCreateLocalResourceAccessor(out result))
                {
                    return(result);
                }
            }
            SystemName nativeSystem = systemResolver.GetSystemNameForSystemId(_nativeSystemId);

            if (nativeSystem == null)
            {
                throw new IllegalCallException("Cannot create resource accessor for resource location '{0}' at system '{1}': System is not available", _nativeResourcePath, _nativeSystemId);
            }
            // Try to access resource locally. This might work if we have the correct resource providers installed.
            if (nativeSystem.IsLocalSystem() && _nativeResourcePath.IsValidLocalPath && _nativeResourcePath.TryCreateLocalResourceAccessor(out result))
            {
                return(result);
            }
            IFileSystemResourceAccessor fsra;

            if (RemoteFileSystemResourceAccessor.ConnectFileSystem(_nativeSystemId, _nativeResourcePath, out fsra))
            {
                return(fsra);
            }
            throw new IllegalCallException("Cannot create resource accessor for resource location '{0}' at system '{1}'", _nativeResourcePath, _nativeSystemId);
        }
Exemplo n.º 10
0
        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);
            }

            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);
        }
Exemplo n.º 11
0
        public FrontendServer()
        {
            UPnPConfiguration.PRODUCT_VERSION = MP2SERVER_DEVICEVERSION;
            UPnPConfiguration.LOGGER          = new UPnPLoggerDelegate();
            HttpResponse.HTTP_SERVER_NAME     = MP2_HTTP_SERVER_NAME;

            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();

            _upnpServer = new UPnPFrontendServer(systemResolver.LocalSystemId);
        }
Exemplo n.º 12
0
        public BackendServer()
        {
            ServerSettings serverSettings = ServiceRegistration.Get <ISettingsManager>().Load <ServerSettings>();

            UPnPConfiguration.PRODUCT_VERSION = MP2SERVER_DEVICEVERSION;
            UPnPConfiguration.LOGGER          = new UPnPLoggerDelegate();
            UPnPConfiguration.USE_IPV4        = serverSettings.UseIPv4;
            UPnPConfiguration.USE_IPV6        = serverSettings.UseIPv6;
            HttpResponse.HTTP_SERVER_NAME     = MP2_HTTP_SERVER_NAME;

            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();

            _upnpServer = new UPnPBackendServer(systemResolver.LocalSystemId);
        }
Exemplo n.º 13
0
        public void Activated(PluginRuntime pluginRuntime)
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            var             appKey         = systemResolver.SystemType == SystemType.Server ? KEY_SERVER : KEY_CLIENT;

            // The appkey and shared key can be found in onetrueeror.com
            OneTrue.Configuration.Credentials(appKey.Item1, appKey.Item2);
            OneTrue.Configuration.CatchWinFormsExceptions();
            OneTrue.Configuration.Advanced.UploadReportFailed += OnUploadReportFailed;

            // Exchange the logger by the error reporting wrapper
            var currentLogger = ServiceRegistration.Get <ILogger>();
            var errorLogger   = new ErrorLogWrapper(currentLogger);

            ServiceRegistration.Set <ILogger>(errorLogger);
        }
Exemplo n.º 14
0
        public MediaItem CreateLocalMediaItem(IResourceAccessor mediaItemAccessor, IEnumerable <Guid> metadataExtractorIds)
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            const bool      forceQuickMode = true;
            IDictionary <Guid, MediaItemAspect> aspects = ExtractMetadata(mediaItemAccessor, metadataExtractorIds, forceQuickMode);

            if (aspects == null)
            {
                return(null);
            }
            MediaItemAspect providerResourceAspect = MediaItemAspect.GetOrCreateAspect(aspects, ProviderResourceAspect.Metadata);

            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SYSTEM_ID, systemResolver.LocalSystemId);
            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, mediaItemAccessor.CanonicalLocalResourcePath.Serialize());
            return(new MediaItem(Guid.Empty, aspects));
        }
Exemplo n.º 15
0
        public FrontendServer()
        {
            ServerSettings serverSettings = ServiceRegistration.Get <ISettingsManager>().Load <ServerSettings>();

            UPnPConfiguration.PRODUCT_VERSION     = MP2SERVER_DEVICEVERSION;
            UPnPConfiguration.LOGGER              = new UPnPLoggerDelegate();
            UPnPConfiguration.USE_IPV4            = serverSettings.UseIPv4;
            UPnPConfiguration.USE_IPV6            = serverSettings.UseIPv6;
            UPnPConfiguration.IP_ADDRESS_BINDINGS = serverSettings.IPAddressBindingsList;
            NetworkUtils.LimitIPEndpoints         = serverSettings.LimitIPEndpoints;
            //HttpResponse.HTTP_SERVER_NAME = MP2_HTTP_SERVER_NAME;

            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();

            _upnpServer = new UPnPFrontendServer(systemResolver.LocalSystemId);
        }
Exemplo n.º 16
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);
        }
        private static LiveTvMediaItem.LiveTvMediaItem CreateCommonMediaItem(int slotIndex, string path, bool isTv, string customMimeType = null)
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            IDictionary <Guid, IList <MediaItemAspect> > aspects = new Dictionary <Guid, IList <MediaItemAspect> >();

            SlimTvResourceAccessor resourceAccessor = new SlimTvResourceAccessor(slotIndex, path);

            MultipleMediaItemAspect providerResourceAspect = MediaItemAspect.CreateAspect(aspects, ProviderResourceAspect.Metadata);

            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_TYPE, ProviderResourceAspect.TYPE_PRIMARY);
            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SYSTEM_ID, systemResolver.LocalSystemId);

            String raPath = resourceAccessor.CanonicalLocalResourcePath.Serialize();

            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, raPath);

            string title;
            string mimeType;

            if (isTv)
            {
                // VideoAspect needs to be included to associate VideoPlayer later!
                MediaItemAspect.GetOrCreateAspect(aspects, VideoAspect.Metadata);
                title    = "Live TV";
                mimeType = LiveTvMediaItem.LiveTvMediaItem.MIME_TYPE_TV;
            }
            else
            {
                // AudioAspect needs to be included to associate an AudioPlayer later!
                MediaItemAspect.GetOrCreateAspect(aspects, AudioAspect.Metadata);
                title    = "Live Radio";
                mimeType = LiveTvMediaItem.LiveTvMediaItem.MIME_TYPE_RADIO;
            }

            // Allow overriding from argument
            if (!string.IsNullOrEmpty(customMimeType))
            {
                mimeType = customMimeType;
            }

            MediaItemAspect.SetAttribute(aspects, MediaAspect.ATTR_TITLE, title);
            MediaItemAspect.SetAttribute(aspects, MediaAspect.ATTR_SORT_TITLE, BaseInfo.GetSortTitle(title));
            MediaItemAspect.SetAttribute(aspects, MediaAspect.ATTR_ISVIRTUAL, false);
            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, mimeType); // Custom mimetype for LiveTv or Radio
            LiveTvMediaItem.LiveTvMediaItem tvStream = new LiveTvMediaItem.LiveTvMediaItem(new Guid(), aspects);
            return(tvStream);
        }
        /// <summary>
        /// Detects if an audio CD/DVD/BD is contained in the given <paramref name="drive"/>.
        /// </summary>
        /// <param name="drive">The drive to be examined.</param>
        /// <param name="tracks">Returns a collection of audio tracks for the audio CD in the given <paramref name="drive"/>.</param>
        /// <param name="extractedMIATypeIDs">IDs of the media item aspect types which were extracted from the returned <paramref name="tracks"/>.</param>
        /// <returns><c>true</c>, if an audio CD was identified, else <c>false</c>.</returns>
        public static bool DetectAudioCD(string drive, out ICollection <MediaItem> tracks, out ICollection <Guid> extractedMIATypeIDs)
        {
            tracks = null;
            extractedMIATypeIDs = null;
            if (string.IsNullOrEmpty(drive) || drive.Length < 2)
            {
                return(false);
            }
            drive = drive.Substring(0, 2); // Clip potential '\\' at the end

            try
            {
                IList <BassUtils.AudioTrack> audioTracks = BassUtils.GetAudioTracks(drive);
                // BassUtils can report wrong audio tracks for some devices, we filter out "Duration = -1" here
                audioTracks = audioTracks?.Where(t => t.Duration > 0).ToList();
                if (audioTracks == null || audioTracks.Count == 0)
                {
                    return(false);
                }
                ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
                string          systemId       = systemResolver.LocalSystemId;
                tracks = new List <MediaItem>(audioTracks.Count);
                char driveChar = drive[0];
                foreach (BassUtils.AudioTrack track in audioTracks)
                {
                    tracks.Add(CreateMediaItem(track, driveChar, audioTracks.Count, systemId));
                }
                extractedMIATypeIDs = new List <Guid>
                {
                    ProviderResourceAspect.ASPECT_ID,
                    MediaAspect.ASPECT_ID,
                    AudioAspect.ASPECT_ID,
                };
            }
            catch (IOException)
            {
                ServiceRegistration.Get <ILogger>().Warn("Error enumerating tracks of audio CD in drive {0}", drive);
                tracks = null;
                return(false);
            }
            return(true);
        }
Exemplo n.º 19
0
        public ServerShares(Share share) : base(ShareEditMode.EditShare)
        {
            IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>();
            ISystemResolver          systemResolver          = ServiceRegistration.Get <ISystemResolver>();
            string nativeSystem = serverConnectionManager.LastHomeServerName;

            if (nativeSystem == null)
            {
                SystemName systemName = systemResolver.GetSystemNameForSystemId(serverConnectionManager.HomeServerSystemId);
                if (systemName != null)
                {
                    nativeSystem = systemName.HostName;
                }
            }
            if (nativeSystem == null)
            {
                nativeSystem = serverConnectionManager.HomeServerSystemId;
            }
            InitializePropertiesWithShare(share, nativeSystem);
        }
Exemplo n.º 20
0
        public MediaItem CreateLocalMediaItem(IResourceAccessor mediaItemAccessor, IEnumerable <Guid> metadataExtractorIds)
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            IDictionary <Guid, IList <MediaItemAspect> > aspects = ExtractMetadataAsync(mediaItemAccessor, metadataExtractorIds, true).Result;

            if (aspects == null)
            {
                return(null);
            }
            IList <MultipleMediaItemAspect> providerResourceAspects;

            if (MediaItemAspect.TryGetAspects(aspects, ProviderResourceAspect.Metadata, out providerResourceAspects) && providerResourceAspects.Count > 0)
            {
                MultipleMediaItemAspect providerResourceAspect = providerResourceAspects.First();
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_TYPE, ProviderResourceAspect.TYPE_PRIMARY);
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SYSTEM_ID, systemResolver.LocalSystemId);
                providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, mediaItemAccessor.CanonicalLocalResourcePath.Serialize());
                return(new MediaItem(Guid.Empty, aspects));
            }
            return(null);
        }
Exemplo n.º 21
0
        private static LiveTvMediaItem.LiveTvMediaItem CreateCommonMediaItem(int slotIndex, string path, bool isTv)
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
            IDictionary <Guid, MediaItemAspect> aspects = new Dictionary <Guid, MediaItemAspect>();
            MediaItemAspect providerResourceAspect;
            MediaItemAspect mediaAspect;

            var resourceAccessor = SlimTvResourceProvider.GetResourceAccessor(slotIndex, path);

            aspects[ProviderResourceAspect.ASPECT_ID] = providerResourceAspect = new MediaItemAspect(ProviderResourceAspect.Metadata);
            aspects[MediaAspect.ASPECT_ID]            = mediaAspect = new MediaItemAspect(MediaAspect.Metadata);
            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SYSTEM_ID, systemResolver.LocalSystemId);

            String raPath = resourceAccessor.CanonicalLocalResourcePath.Serialize();

            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, raPath);

            string title;
            string mimeType;

            if (isTv)
            {
                // VideoAspect needs to be included to associate VideoPlayer later!
                aspects[VideoAspect.ASPECT_ID] = new MediaItemAspect(VideoAspect.Metadata);
                title    = "Live TV";
                mimeType = LiveTvMediaItem.LiveTvMediaItem.MIME_TYPE_TV;
            }
            else
            {
                // AudioAspect needs to be included to associate an AudioPlayer later!
                aspects[AudioAspect.ASPECT_ID] = new MediaItemAspect(AudioAspect.Metadata);
                title    = "Live Radio";
                mimeType = LiveTvMediaItem.LiveTvMediaItem.MIME_TYPE_RADIO;
            }
            mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, title);
            mediaAspect.SetAttribute(MediaAspect.ATTR_MIME_TYPE, mimeType); // Custom mimetype for LiveTv or Radio
            LiveTvMediaItem.LiveTvMediaItem tvStream = new LiveTvMediaItem.LiveTvMediaItem(new Guid(), aspects);
            return(tvStream);
        }
Exemplo n.º 22
0
        protected bool ValidateAttachmentState(ClientDescriptor client)
        {
            string clientSystemId = client.MPFrontendServerUUID;

            ServiceRegistration.Get <ILogger>().Info("ClientManager: Validating attachment state of client '{0}' (system ID '{1}')",
                                                     client.ClientName, clientSystemId);
            ClientConnection connection = _controlPoint.GetClientConnection(clientSystemId);

            if (connection != null)
            {
                string          homeServerSystemId = connection.ClientController.GetHomeServerSystemId();
                ISystemResolver systemResolver     = ServiceRegistration.Get <ISystemResolver>();
                if (homeServerSystemId != systemResolver.LocalSystemId)
                {
                    ServiceRegistration.Get <ILogger>().Info(
                        "ClientManager: Client '{0}' is no longer attached to this server, cleaning up client data", clientSystemId);
                    DetachClientAndRemoveShares(clientSystemId);
                    return(false);
                }
            }
            return(true);
        }
        protected override void NavigateToLocalRootView(Share localShare, NavigateToViewDlgt navigateToViewDlgt)
        {
            // We need to simulate the logic from method ReLoadItemsAndSubViewSpecifications
            ICollection <Share> localServerShares;
            ICollection <Share> localClientShares;

            GetShares(out localServerShares, out localClientShares);
            if (localServerShares.Count > 0 && localClientShares.Count > 0)
            {
                IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>();
                ISystemResolver          systemResolver          = ServiceRegistration.Get <ISystemResolver>();
                if (localShare.SystemId == serverConnectionManager.HomeServerSystemId)
                {
                    navigateToViewDlgt(new LocalSharesViewSpecification(localServerShares, Consts.RES_SERVER_SHARES_VIEW_NAME, _necessaryMIATypeIds, _optionalMIATypeIds));
                }
                else if (localShare.SystemId == systemResolver.LocalSystemId)
                {
                    navigateToViewDlgt(new LocalSharesViewSpecification(localClientShares, Consts.RES_CLIENT_SHARES_VIEW_NAME, _necessaryMIATypeIds, _optionalMIATypeIds));
                }
            }
            navigateToViewDlgt(new LocalDirectoryViewSpecification(localShare.Name, localShare.BaseResourcePath, _necessaryMIATypeIds, _optionalMIATypeIds));
        }
        public void Startup()
        {
            char?driveLetter = ReadDriveLetterFromSettings();

            if (!driveLetter.HasValue)
            {
                ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
                driveLetter = systemResolver.SystemType == SystemType.Server ? ResourceMountingSettings.DEFAULT_DRIVE_LETTER_SERVER :
                              ResourceMountingSettings.DEFAULT_DRIVE_LETTER_CLIENT;
                // Save the current default setting to be able to change it in config file
                SaveDefaultDriveSettings(driveLetter.Value);
            }
            _dokanExecutor = Dokan.Dokan.Install(driveLetter.Value);
            if (_dokanExecutor == null)
            {
                ServiceRegistration.Get <ILogger>().Warn("ResourceMountingService: Due to problems in DOKAN, resources cannot be mounted into the local filesystem");
            }
            else
            {
                // We share the same synchronization object to avoid multithreading issues between the two classes
                _syncObj = _dokanExecutor.SyncObj;
            }
        }
Exemplo n.º 25
0
    public void DetachFromHomeServer()
    {
      ISettingsManager settingsManager = ServiceRegistration.Get<ISettingsManager>();
      ServerConnectionSettings settings = settingsManager.Load<ServerConnectionSettings>();
      ServiceRegistration.Get<ILogger>().Info("ServerConnectionManager: Detaching from home server '{0}'", settings.HomeServerSystemId);

      ServiceRegistration.Get<ILogger>().Debug("ServerConnectionManager: Clearing pending import jobs and suspending importer worker");
      IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>();
      importerWorker.Suspend();
      importerWorker.CancelPendingJobs();

      ServiceRegistration.Get<ILogger>().Debug("ServerConnectionManager: Notifying the MediaPortal server about the detachment");
      UPnPServerControllerServiceProxy sc = ServerControllerServiceProxy;
      ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>();
      if (sc != null)
        try
        {
          sc.DetachClient(systemResolver.LocalSystemId);
          sc.AttachedClientsChanged -= OnAttachedClientsChanged;
          sc.ConnectedClientsChanged -= OnConnectedClientsChanged;
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Error detaching from home server '{0}'", e, HomeServerSystemId);
        }
      UPnPContentDirectoryServiceProxy cd = ContentDirectoryServiceProxy;
      if (cd != null)
        try
        {
          cd.PlaylistsChanged -= OnContentDirectoryPlaylistsChanged;
          cd.MIATypeRegistrationsChanged -= OnContentDirectoryMIATypeRegistrationsChanged;
          cd.RegisteredSharesChangeCounterChanged -= OnRegisteredSharesChangeCounterChanged;
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Error unregistering from state variable change events", e);
        }

      ServiceRegistration.Get<ILogger>().Debug("ServerConnectionManager: Closing server connection");
      UPnPClientControlPoint cp;
      lock (_syncObj)
        cp = _controlPoint;
      if (cp != null)
        cp.Stop(); // Must be outside the lock - sends messages
      lock (_syncObj)
      {
        settings.HomeServerSystemId = null;
        settings.LastHomeServerName = null;
        settings.LastHomeServerSystem = null;
        settingsManager.Save(settings);
        _controlPoint = null;
      }
      UpdateCurrentlyImportingShares(null); // Mark all shares as not being imported
      ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerDetached);

      ServiceRegistration.Get<ILogger>().Debug("ServerConnectionManager: Starting to watch for MediaPortal servers");
      if (_serverWatcher == null)
      {
        lock (_syncObj)
          _serverWatcher = BuildServerWatcher();
        _serverWatcher.Start(); // Outside the lock
      }
    }
Exemplo n.º 26
0
    /// <summary>
    /// Synchronously synchronizes all local shares and media item aspect types with the MediaPortal server.
    /// </summary>
    protected async Task CompleteServerConnectionAsync()
    {
      UPnPServerControllerServiceProxy sc = ServerControllerServiceProxy;
      ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>();
      if (sc != null)
      {
        try
        {
          // Check if we're attached to the server. If the server lost its state, it might have forgotten us.
          if (!sc.GetAttachedClients().Select(clientMetadata => clientMetadata.SystemId).Contains(systemResolver.LocalSystemId))
            sc.AttachClient(systemResolver.LocalSystemId);
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Error checking attachment state at home server '{0}'", e, HomeServerSystemId);
          return; // This is a real error case, we don't need to try any other service calls
        }

        // Register state variables change events
        sc.AttachedClientsChanged += OnAttachedClientsChanged;
        sc.ConnectedClientsChanged += OnConnectedClientsChanged;
      }
      IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>();
      ICollection<Share> newShares = new List<Share>();
      UPnPContentDirectoryServiceProxy cd = ContentDirectoryServiceProxy;
      if (cd != null)
      {
        // Update shares registration
        try
        {
          ISettingsManager settingsManager = ServiceRegistration.Get<ISettingsManager>();
          ServerConnectionSettings settings = settingsManager.Load<ServerConnectionSettings>();
          ServiceRegistration.Get<ILogger>().Info("ServerConnectionManager: Synchronizing shares with home server");
          IDictionary<Guid, Share> serverShares = new Dictionary<Guid, Share>();
          foreach (Share share in await cd.GetSharesAsync(systemResolver.LocalSystemId, SharesFilter.All))
            serverShares.Add(share.ShareId, share);
          IDictionary<Guid, Share> localShares = ServiceRegistration.Get<ILocalSharesManagement>().Shares;
          // First remove shares - if the client lost its configuration and re-registers an already present share, the server's method will throw an exception
          foreach (Guid serverShareId in serverShares.Keys)
            if (!localShares.ContainsKey(serverShareId))
              await cd.RemoveShareAsync(serverShareId);
          foreach (Share localShare in localShares.Values)
          {
            RelocationMode relocationMode;
            if (!serverShares.ContainsKey(localShare.ShareId))
            {
              await cd.RegisterShareAsync(localShare);
              newShares.Add(localShare);
            }
            else if (settings.CachedSharesUpdates.TryGetValue(localShare.ShareId, out relocationMode))
            {
              await cd.UpdateShareAsync(localShare.ShareId, localShare.BaseResourcePath, localShare.Name, localShare.UseShareWatcher, localShare.MediaCategories,
                  relocationMode);
              switch (relocationMode)
              {
                case RelocationMode.ClearAndReImport:
                  importerWorker.ScheduleImport(localShare.BaseResourcePath, localShare.MediaCategories, true);
                  break;
                case RelocationMode.Relocate:
                  importerWorker.ScheduleRefresh(localShare.BaseResourcePath, localShare.MediaCategories, true);
                  break;
              }
            }
          }
          settings.CachedSharesUpdates.Clear();
          settingsManager.Save(settings);
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Could not synchronize local shares with server", e);
        }

        // Update media item aspect type registration
        try
        {
          IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get<IMediaItemAspectTypeRegistration>();
          ServiceRegistration.Get<ILogger>().Info("ServerConnectionManager: Checking for unregistered media item aspect types at home server");
          ICollection<Guid> serverMIATypes = await cd.GetAllManagedMediaItemAspectTypesAsync();
          foreach (KeyValuePair<Guid, MediaItemAspectMetadata> localMiaType in miatr.LocallyKnownMediaItemAspectTypes)
            if (!serverMIATypes.Contains(localMiaType.Key))
            {
              ServiceRegistration.Get<ILogger>().Info("ServerConnectionManager: Adding unregistered media item aspect type '{0}' (ID '{1}') at home server",
                  localMiaType.Value.Name, localMiaType.Key);
              await cd.AddMediaItemAspectStorageAsync(localMiaType.Value);
            }
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Could not synchronize local media item aspect types with server", e);
        }

        // Register state variables change events
        cd.PlaylistsChanged += OnContentDirectoryPlaylistsChanged;
        cd.MIATypeRegistrationsChanged += OnContentDirectoryMIATypeRegistrationsChanged;
        cd.RegisteredSharesChangeCounterChanged += OnRegisteredSharesChangeCounterChanged;

        // Activate importer worker
        ServiceRegistration.Get<ILogger>().Debug("ServerConnectionManager: Activating importer worker");
        ImporterCallback ic = new ImporterCallback(cd);
        importerWorker.Activate(ic, ic);
        foreach (Share share in newShares)
          importerWorker.ScheduleImport(share.BaseResourcePath, share.MediaCategories, true);
      }
    }
Exemplo n.º 27
0
        /// <summary>
        /// Detects if an audio CD/DVD/BD is contained in the given <paramref name="drive"/>.
        /// </summary>
        /// <param name="drive">The drive to be examined.</param>
        /// <param name="tracks">Returns a collection of audio tracks for the audio CD in the given <paramref name="drive"/>.</param>
        /// <param name="extractedMIATypeIDs">IDs of the media item aspect types which were extracted from the returned <paramref name="tracks"/>.</param>
        /// <returns><c>true</c>, if an audio CD was identified, else <c>false</c>.</returns>
        public static bool DetectAudioCD(DriveInfo driveInfo, out ICollection <MediaItem> tracks, out ICollection <Guid> extractedMIATypeIDs)
        {
            tracks = null;
            extractedMIATypeIDs = null;
            string drive = driveInfo.Name;

            if (string.IsNullOrEmpty(drive) || drive.Length < 2)
            {
                return(false);
            }
            drive = drive.Substring(0, 2); // Clip potential '\\' at the end

            try
            {
                IList <BassUtils.AudioTrack> audioTracks = BassUtils.GetAudioTracks(drive);
                // BassUtils can report wrong audio tracks for some devices, we filter out "Duration = -1" here
                audioTracks = audioTracks?.Where(t => t.Duration > 0).ToList();
                if (audioTracks == null || audioTracks.Count == 0)
                {
                    return(false);
                }
                ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();
                string          systemId       = systemResolver.LocalSystemId;
                tracks = new List <MediaItem>(audioTracks.Count);
                char driveChar = drive[0];
                int  driveId   = BassUtils.Drive2BassID(driveChar);
                if (driveId > -1)
                {
                    BASS_CD_INFO info = BassCd.BASS_CD_GetInfo(driveId);
                    if (info.cdtext)
                    {
                        string[] tags        = BassCd.BASS_CD_GetIDText(driveId);
                        string   album       = GetCDText(tags, "TITLE");
                        string   albumArtist = GetCDText(tags, "PERFORMER");
                        foreach (BassUtils.AudioTrack track in audioTracks)
                        {
                            tracks.Add(CreateMediaItem(track, driveChar, audioTracks.Count, systemId, album, albumArtist,
                                                       album, albumArtist, irsc: BassCd.BASS_CD_GetISRC(driveId, track.TrackNo - 1)));
                        }
                    }
                    else
                    {
                        foreach (BassUtils.AudioTrack track in audioTracks)
                        {
                            tracks.Add(CreateMediaItem(track, driveChar, audioTracks.Count, systemId,
                                                       irsc: BassCd.BASS_CD_GetISRC(driveId, track.TrackNo - 1)));
                        }
                    }
                    BassCd.BASS_CD_Release(driveId);
                }
                else
                {
                    foreach (BassUtils.AudioTrack track in audioTracks)
                    {
                        tracks.Add(CreateMediaItem(track, driveChar, audioTracks.Count, systemId));
                    }
                }
                extractedMIATypeIDs = new List <Guid>
                {
                    ProviderResourceAspect.ASPECT_ID,
                    MediaAspect.ASPECT_ID,
                    AudioAspect.ASPECT_ID,
                    ExternalIdentifierAspect.ASPECT_ID,
                };
            }
            catch (IOException)
            {
                ServiceRegistration.Get <ILogger>().Warn("Error enumerating tracks of audio CD in drive {0}", drive);
                tracks = null;
                return(false);
            }
            return(true);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates a new local share. This will create a new share ID and call the constructor with it.
        /// </summary>
        /// <param name="baseResourcePath">Description of the resource provider chain for the share's base directory.</param>
        /// <param name="name">Name of the share. This name will be shown at the GUI. The string might be
        /// localized using a "[[Section-Name].[String-Name]]" syntax, for example "[Media.MyMusic]".</param>
        /// <param name="useShareWatcher">Indicates if changes on share should be monitored by a share watcher.</param>
        /// <param name="mediaCategories">Media content categories of this share. If set, the category
        /// describes the desired contents of this share. If set to <c>null</c>, this share has no explicit
        /// media categories, i.e. it is a general share.</param>
        /// <returns>Created <see cref="Share"/> with a new share id.</returns>
        public static Share CreateNewLocalShare(ResourcePath baseResourcePath, string name, bool useShareWatcher, IEnumerable <string> mediaCategories)
        {
            ISystemResolver systemResolver = ServiceRegistration.Get <ISystemResolver>();

            return(CreateNewShare(systemResolver.LocalSystemId, baseResourcePath, name, useShareWatcher, mediaCategories));
        }