Exemplo n.º 1
0
        public R <Playlist> LoadPlaylistFrom(string message, AudioType?type = null)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message));
            }

            string netlinkurl = TextUtil.ExtractUrlFromBB(message);

            if (type.HasValue)
            {
                foreach (var factory in factories)
                {
                    if (factory.FactoryFor == type.Value)
                    {
                        return(factory.GetPlaylist(netlinkurl));
                    }
                }
                return("There is not factory registered for this type");
            }
            else
            {
                foreach (var factory in factories)
                {
                    if (factory.MatchLink(netlinkurl))
                    {
                        return(factory.GetPlaylist(netlinkurl));
                    }
                }
                return("Unknown playlist type. Please use '!list from <type> <url>' to specify your playlist type.");
            }
        }
Exemplo n.º 2
0
        public string LoadAndPlay(PlayData data)
        {
            string           netlinkurl = TextUtil.ExtractUrlFromBB(data.Message);
            IResourceFactory factory    = GetFactoryFor(netlinkurl);

            return(LoadAndPlay(factory, data));
        }
Exemplo n.º 3
0
        /// <summary>Generates a new <see cref="PlayResource"/> which can be played.
        /// The message used will be cleared of bb-tags. Also lets you pick an
        /// <see cref="IResourceFactory"/> identifier to optionally select a factory.
        /// </summary>
        /// <param name="message">The link/uri to resolve for the resource.</param>
        /// <param name="audioType">The associated <see cref="AudioType"/> to a factory.
        /// Leave null to let it detect automatically.</param>
        /// <returns>The playable resource if successful, or an error message otherwise.</returns>
        public R <PlayResource> Load(string message, AudioType?audioType = null)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentNullException(nameof(message));
            }

            IResourceFactory factory;
            string           netlinkurl = TextUtil.ExtractUrlFromBB(message);

            if (audioType.HasValue)
            {
                factory = GetFactoryFor(audioType.Value);
            }
            else
            {
                factory = GetFactoryFor(netlinkurl);
            }

            var result = factory.GetResource(netlinkurl);

            if (!result)
            {
                return($"Could not load ({result.Message})");
            }
            return(result);
        }
Exemplo n.º 4
0
        private string LoadAndPlay(IResourceFactory factory, PlayData data)
        {
            if (data.Resource == null)
            {
                string netlinkurl = TextUtil.ExtractUrlFromBB(data.Message);

                AudioResource resource;
                RResultCode   result = factory.GetResource(netlinkurl, out resource);
                if (result != RResultCode.Success)
                {
                    return($"Could not play ({result})");
                }
                data.Resource = resource;
            }
            return(PostProcessStart(factory, data));
        }