Esempio n. 1
0
        private AudioItem checkSourcesForItemOnce(AudioReference reference, AudioLoadResultHandler resultHandler, bool[] reported)
        {
            foreach (AudioSourceManager sourceManager in sourceManagers)
            {
                AudioItem item = sourceManager.loadItem(this, reference);

                if (item != null)
                {
                    if (item is AudioTrack)
                    {
                        log.debug("Loaded a track with identifier {} using {}.", reference.identifier, sourceManager.GetType().Name);
                        reported[0] = true;
                        resultHandler.trackLoaded((AudioTrack)item);
                    }
                    else if (item is AudioPlaylist)
                    {
                        log.debug("Loaded a playlist with identifier {} using {}.", reference.identifier, sourceManager.GetType().Name);
                        reported[0] = true;
                        resultHandler.playlistLoaded((AudioPlaylist)item);
                    }
                    return(item);
                }
            }

            return(null);
        }
Esempio n. 2
0
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        //ORIGINAL LINE: private Callable<Void> createItemLoader(final String identifier, final AudioLoadResultHandler resultHandler)
        private Callable <Void> createItemLoader(string identifier, AudioLoadResultHandler resultHandler)
        {
            return(() =>
            {
                bool[] reported = new bool[1];

                try
                {
                    if (!checkSourcesForItem(new AudioReference(identifier, null), resultHandler, reported))
                    {
                        log.debug("No matches for track with identifier {}.", identifier);
                        resultHandler.noMatches();
                    }
                }
                catch (Exception throwable)
                {
                    if (reported[0])
                    {
                        log.warn("Load result handler for {} threw an exception", identifier, throwable);
                    }
                    else
                    {
                        dispatchItemLoadFailure(identifier, resultHandler, throwable);
                    }

                    ExceptionTools.rethrowErrors(throwable);
                }

                return null;
            });
        }
Esempio n. 3
0
        private void dispatchItemLoadFailure(string identifier, AudioLoadResultHandler resultHandler, Exception throwable)
        {
            FriendlyException exception = ExceptionTools.wrapUnfriendlyExceptions("Something went wrong when looking up the track", FAULT, throwable);

            ExceptionTools.log(log, exception, "loading item " + identifier);

            resultHandler.loadFailed(exception);
        }
Esempio n. 4
0
        private Future <Void> handleLoadRejected(string identifier, AudioLoadResultHandler resultHandler, RejectedExecutionException e)
        {
            FriendlyException exception = new FriendlyException("Cannot queue loading a track, queue is full.", SUSPICIOUS, e);

            ExceptionTools.log(log, exception, "queueing item " + identifier);

            resultHandler.loadFailed(exception);

            return(ExecutorTools.COMPLETED_VOID);
        }
Esempio n. 5
0
 //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
 //ORIGINAL LINE: @Override public Future<Void> loadItem(final String identifier, final AudioLoadResultHandler resultHandler)
 public override Future <Void> loadItem(string identifier, AudioLoadResultHandler resultHandler)
 {
     try
     {
         return(trackInfoExecutorService.submit(createItemLoader(identifier, resultHandler)));
     }
     catch (RejectedExecutionException e)
     {
         return(handleLoadRejected(identifier, resultHandler, e));
     }
 }
Esempio n. 6
0
        public static async Task LoadAudioTrack(string query, AudioLoadResultHandler handler, bool fromUrl = true)
        {
            JObject ytdlResponseJson = await YoutubeDLInfoProvider.ExtractInfo(query, fromUrl);

            List <AudioTrack> songs = new List <AudioTrack>();

            // Check if playlist
            if (ytdlResponseJson.ContainsKey("entries"))
            {
                if (fromUrl)
                {
                    foreach (JObject ytdlVideoJson in ytdlResponseJson["entries"].Value <JArray>())
                    {
                        SongInfo songInfo = SongInfo.ParseYtdlResponse(ytdlVideoJson);
                        songs.Add(new AudioTrack(LoadFFmpegProcess(songInfo.Url))
                        {
                            Url       = songInfo.Url,
                            TrackInfo = songInfo
                        });
                    }
                    handler.OnLoadPlaylist(songs);
                }
                else
                {
                    JObject  ytdlVideoJson  = ytdlResponseJson["entries"].Value <JArray>()[0].Value <JObject>();
                    SongInfo firstEntrySong = SongInfo.ParseYtdlResponse(ytdlVideoJson);
                    handler.OnLoadTrack(new AudioTrack(LoadFFmpegProcess(firstEntrySong.Url))
                    {
                        Url       = firstEntrySong.Url,
                        TrackInfo = firstEntrySong
                    });
                }
            }
            else
            {
                SongInfo songInfo = SongInfo.ParseYtdlResponse(ytdlResponseJson);
                handler.OnLoadTrack(new AudioTrack(LoadFFmpegProcess(songInfo.Url))
                {
                    Url       = songInfo.Url,
                    TrackInfo = songInfo
                });
            }
        }
Esempio n. 7
0
        private bool checkSourcesForItem(AudioReference reference, AudioLoadResultHandler resultHandler, bool[] reported)
        {
            AudioReference currentReference = reference;

            for (int redirects = 0; redirects < MAXIMUM_LOAD_REDIRECTS && currentReference.identifier != null; redirects++)
            {
                AudioItem item = checkSourcesForItemOnce(currentReference, resultHandler, reported);
                if (item == null)
                {
                    return(false);
                }
                else if (!(item is AudioReference))
                {
                    return(true);
                }
                currentReference = (AudioReference)item;
            }

            return(false);
        }
Esempio n. 8
0
 //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
 //ORIGINAL LINE: @Override public Future<Void> loadItemOrdered(Object orderingKey, final String identifier, final AudioLoadResultHandler resultHandler)
 public override Future <Void> loadItemOrdered(object orderingKey, string identifier, AudioLoadResultHandler resultHandler)
 {
     try
     {
         return(orderedInfoExecutor.submit(orderingKey, createItemLoader(identifier, resultHandler)));
     }
     catch (RejectedExecutionException e)
     {
         return(handleLoadRejected(identifier, resultHandler, e));
     }
 }