Ejemplo n.º 1
0
 public void AddComboBoxItem(AbstractAnalyser me, PlainTextComboBoxData item)
 {
     lock (operationLock)
     {
         if (me != null && !CheckPermission(me))
         {
             return;
         }
         comboBoxItems.Add(item);
     }
 }
Ejemplo n.º 2
0
        public override async Task SetURLAsync(string url)
        {
            try
            {
                id = YoutubeClient.ParseVideoId(url);
                var client = new YoutubeClient();
                Controller?.UpdateMessage(this, KEY_YOUTUBE,
                                          new PlainTextMessage(AppResources.GetString("YouTubeLinkDetectedButWaiting")));
                video = await client.GetVideoAsync(id);

                infos = await client.GetVideoMediaStreamInfosAsync(id);

                if (infos.Muxed.Count > 0)
                {
                    Controller?.SetComboBoxLayoutVisibility(this, true);
                }
                else
                {
                    throw new Exception();
                }

                Controller?.UpdateMessage(this, KEY_YOUTUBE,
                                          new PlainTextMessage(
                                              AppResources.GetString("YouTubeLinkDetectedButWaiting")
                                              + " - " +
                                              video.Title
                                              ));

                foreach (var info in infos.Muxed)
                {
                    PlainTextComboBoxData data = new PlainTextComboBoxData();
                    data.Text = info.VideoQuality.ToString() + " - " + info.VideoEncoding.ToString();
                    Controller?.AddComboBoxItem(this, data);
                }

                Controller?.SetComboBoxSelectionChangedListener(this,
                                                                async(item) => {
                    innerAnalyser?.Dispose();
                    string target = GetURLFromInfos(item.Text);
                    if (target != null)
                    {
                        innerAnalyser = Converters.UrlConverter.GetAnalyser(target);
                        if (innerAnalyser != null)
                        {
                            URL = target;
                            innerAnalyser.BindVisualController(Controller);
                            Controller?.RegistAnalyser(this, innerAnalyser);
                            await innerAnalyser.SetURLAsync(target);
                        }
                    }
                }
                                                                );
            }
            catch (Exception)
            {
                Controller?.UpdateMessage(this, KEY_YOUTUBE,
                                          new PlainTextMessage(
                                              AppResources.GetString("YouTubeLinkDetectedButFailed")
                                              ));
                Controller?.SetComboBoxLayoutVisibility(this, false);
            }
        }