Skip to content

Commit

Permalink
Don't crash if we can't download the available YouTube videos in the …
Browse files Browse the repository at this point in the history
…context menu
  • Loading branch information
flagbug committed Mar 2, 2015
1 parent e5b01e3 commit be55e2a
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions Espera.View/ViewModels/YoutubeSongViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using Espera.Core;
using Akavache;
using Espera.Core;
using ReactiveUI;
using Splat;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using System.Windows.Media;
using Akavache;
using Splat;
using YoutubeExtractor;
using ReactiveCommand = ReactiveUI.ReactiveCommand;

Expand Down Expand Up @@ -38,7 +40,8 @@ public YoutubeSongViewModel(YoutubeSong wrapped, Func<string> downloadPathFunc)
// Wait for the opening of the context menu to download the YouTube information
this.WhenAnyValue(x => x.IsContextMenuOpen)
.FirstAsync(x => x)
.Subscribe(_ => this.LoadContextMenu());
.SelectMany(_ => this.LoadContextMenu().ToObservable())
.Subscribe();

// We have to set a dummy here, so that we can connect the commands
this.isDownloading = Observable.Never<bool>().ToProperty(this, x => x.IsDownloading);
Expand Down Expand Up @@ -149,7 +152,28 @@ public async Task LoadContextMenu()
{
this.IsLoadingContextMenu = true;

IEnumerable<VideoInfo> infos = await Task.Run(() => DownloadUrlResolver.GetDownloadUrls(this.Path, false).ToList());
var infos = new List<VideoInfo>(0);

try
{
infos = await Task.Run(() => DownloadUrlResolver.GetDownloadUrls(this.Path, false).ToList());
}

catch (YoutubeParseException ex)
{
this.Log().ErrorException("Failed to load the available YouTube videos", ex);
}

catch (VideoNotAvailableException ex)
{
this.Log().ErrorException("Failed to load the available YouTube videos", ex);
}

catch (WebException ex)
{
this.Log().ErrorException("Failed to load the available YouTube videos", ex);
}

this.VideosToDownload = infos.Where(x => x.AdaptiveType == AdaptiveType.None && x.VideoType != VideoType.Unknown)
.OrderBy(x => x.VideoType)
.ThenByDescending(x => x.Resolution)
Expand Down

0 comments on commit be55e2a

Please sign in to comment.