Skip to content

Commit

Permalink
Add ability to scan library and improve library navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
brian9206 committed Jan 21, 2018
1 parent 4426d71 commit 86a3993
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 29 deletions.
4 changes: 2 additions & 2 deletions PlexFlux/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
19 changes: 9 additions & 10 deletions PlexFlux/UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<component:LibrarySidebarItem Library="{Binding}" Click="LibrarySidebarItem_Click" />
<component:LibrarySidebarItem Library="{Binding}"
Click="LibrarySidebarItem_Click">
<component:LibrarySidebarItem.ContextMenu>
<ContextMenu>
<MenuItem Header="Scan Library" Click="LibrarySidebarItem_Scan_Click" />
</ContextMenu>
</component:LibrarySidebarItem.ContextMenu>
</component:LibrarySidebarItem>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Expand All @@ -226,15 +233,7 @@


<!-- Bottom Bar -->
<Grid Grid.Column="0" Grid.Row="2" Style="{StaticResource GridBar}">
<!-- Now Playing -->
<StackPanel Orientation="Horizontal">


</StackPanel>
</Grid>

<Grid Grid.Column="1" Grid.Row="2" Style="{StaticResource GridBar}">
<Grid Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Style="{StaticResource GridBar}">
<component:PlaybackControl HorizontalAlignment="Right" Margin="0,0,5,0" />
</Grid>

Expand Down
39 changes: 39 additions & 0 deletions PlexFlux/UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,45 @@ private void LibrarySidebarItem_Click(object sender, RoutedEventArgs e)
SelectSidebarItem(sender);
}

private async void LibrarySidebarItem_Scan_Click(object sender, RoutedEventArgs e)
{
var item = ((FrameworkElement)e.Source).DataContext as PlexLibrary;

try
{
IsLoading = true;

var app = (App)Application.Current;
await app.plexClient.ScanLibrary(item);

bool isComplete = false;

while (!isComplete)
{
isComplete = true;

var libraries = await app.plexClient.GetLibraries();

foreach (var library in libraries)
{
if (library.Key == item.Key && library.IsRefreshing)
isComplete = false;
}

await Task.Delay(1000);
}
}
catch (Exception exception)
{
MessageBox.Show("Could not get data from remote server.\n" + exception.Message, "PlexFlux", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
GoToPlayQueue();
IsLoading = false;
}
}

// commands
private void MediaCommands_Play_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
Expand Down
21 changes: 13 additions & 8 deletions PlexFlux/UI/Pages/BrowseAlbum.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public bool IsLoading
}
}

private bool isLoaded = false;
private CancellationTokenSource artworkResizeTokenSource;

public BrowseAlbum(PlexAlbum album, ContextMenu contextMenu)
Expand Down Expand Up @@ -118,18 +119,22 @@ private async void Page_Loaded(object sender, RoutedEventArgs e)

LoadArtwork();

try
{
var app = (App)Application.Current;
var tracks = await app.plexClient.GetTracks(Album);
TracksData.FromArray(tracks);
}
catch
if (!isLoaded)
{
MessageBox.Show("Could not fetch data from remote server.", "PlexFlux", MessageBoxButton.OK, MessageBoxImage.Exclamation);
try
{
var app = (App)Application.Current;
var tracks = await app.plexClient.GetTracks(Album);
TracksData.FromArray(tracks);
}
catch
{
MessageBox.Show("Could not fetch data from remote server.", "PlexFlux", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}

IsLoading = false;
isLoaded = true;
}

private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
Expand Down
21 changes: 13 additions & 8 deletions PlexFlux/UI/Pages/BrowseArtist.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public bool IsLoading
}
}

private bool isLoaded = false;
private CancellationTokenSource artworkResizeTokenSource;

public BrowseArtist(PlexArtist artist, ContextMenu contextMenu)
Expand Down Expand Up @@ -118,18 +119,22 @@ private async void Page_Loaded(object sender, RoutedEventArgs e)

LoadArtwork();

try
if (!isLoaded)
{
var app = (App)Application.Current;
var albums = await app.plexClient.GetAlbums(Artist);
AlbumsData.FromArray(albums);
}
catch
{
MessageBox.Show("Could not fetch data from remote server.", "PlexFlux", MessageBoxButton.OK, MessageBoxImage.Exclamation);
try
{
var app = (App)Application.Current;
var albums = await app.plexClient.GetAlbums(Artist);
AlbumsData.FromArray(albums);
}
catch
{
MessageBox.Show("Could not fetch data from remote server.", "PlexFlux", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}

IsLoading = false;
isLoaded = true;
}

private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
Expand Down
6 changes: 5 additions & 1 deletion PlexFlux/UI/Pages/BrowseLibrary.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public bool IsLoading
}
}

private bool isLoaded = false;

public BrowseLibrary(ContextMenu contextMenu, PlexLibrary library)
{
MediaObjectsData = new ObservableCollection<IPlexMediaObject>();
Expand Down Expand Up @@ -110,11 +112,13 @@ private async Task LoadMediaObjects(string category)

private async void Page_Loaded(object sender, RoutedEventArgs e)
{
if (DesignerProperties.GetIsInDesignMode(this))
if (DesignerProperties.GetIsInDesignMode(this) || isLoaded)
return;

var app = (App)Application.Current;
await LoadMediaObjects(app.config.LibraryDefaultCategory);

isLoaded = true;
}

private void Button_Click(object sender, RoutedEventArgs e)
Expand Down
5 changes: 5 additions & 0 deletions PlexLib/PlexClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ public async Task MoveTrackInPlaylist(PlexPlaylist playlist, PlexTrack track, Pl
await connection.RequestServer(playlist.MetadataUrl + "/" + track.PlaylistItemID + "/move", nvc, "PUT");
}

public async Task ScanLibrary(PlexLibrary library)
{
await connection.RequestServer("/library/sections/" + library.Key + "/refresh");
}

public Uri GetPhotoTranscodeUrl(string url, int width, int height, bool minSize = true)
{
return connection.BuildRequestUrl("/photo/:/transcode", new NameValueCollection()
Expand Down
7 changes: 7 additions & 0 deletions PlexLib/PlexLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public string Title
internal set;
}

public bool IsRefreshing
{
get;
internal set;
}

internal PlexLibrary(XmlNode node, bool isMediaContainer)
{
if (isMediaContainer)
Expand All @@ -48,6 +54,7 @@ internal PlexLibrary(XmlNode node, bool isMediaContainer)
UUID = node.Attributes["uuid"].InnerText;
Title = HttpUtility.HtmlDecode(node.Attributes["title"].InnerText);
Type = node.Attributes["type"].InnerText;
IsRefreshing = node.Attributes["refreshing"].InnerText == "1";
}
}

Expand Down

0 comments on commit 86a3993

Please sign in to comment.