Skip to content

Commit

Permalink
Experiments with new favicons
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamcooled committed Sep 8, 2014
1 parent af7003e commit 024eb2a
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 36 deletions.
26 changes: 18 additions & 8 deletions SjUpdater/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
</Button>
</controls:WindowCommands>
</controls:MetroWindow.WindowCommands>
<controls:MetroWindow.Resources>
<utils:StringToFaviconConverter x:Key="StringToFaviconConverter" />
</controls:MetroWindow.Resources>
<controls:MetroWindow.Flyouts>
<controls:FlyoutsControl>
<controls:Flyout Header="Add TV Show" Position="Right" x:Name="AddShowFlyout" Theme="Adapt">
Expand Down Expand Up @@ -494,9 +497,15 @@
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Margin="4" Content="{Binding Key}"
<Button Margin="4"
Command="{Binding DownloadCommand, ElementName=Window}"
CommandParameter="{Binding Value}" />
CommandParameter="{Binding Value}" >
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Key}" />
<Image Source="{Binding Key,Converter={StaticResource StringToFaviconConverter}}"></Image>
</StackPanel>

</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Expand Down Expand Up @@ -567,12 +576,14 @@
SelectedValue="{Binding CurrentAccent, ElementName=Window}" />
</Grid>

<CheckBox Content="Sort Tv Shows Alphabetically"
<CheckBox Content="Sort Tv Shows Alphabetically" Margin="0,2"
IsChecked="{Binding SortShowsAlphabetically, Source={x:Static local:Settings.Instance}}" />
<CheckBox Content="Sort Seasons Descending"
<CheckBox Content="Sort Seasons Descending" Margin="0,2"
IsChecked="{Binding SortSeasonsDesc, Source={x:Static local:Settings.Instance}}" />
<CheckBox Content="Sort Episodes Descending"
<CheckBox Content="Sort Episodes Descending" Margin="0,2"
IsChecked="{Binding SortEpisodesDesc, Source={x:Static local:Settings.Instance}}" />
<CheckBox Content="Mark 'German Subbed' Episodes as German" Margin="0,2,0,1"
IsChecked="{Binding MarkSubbedAsGerman, Source={x:Static local:Settings.Instance}}" />

<StackPanel Orientation="Horizontal">
<CheckBox Content="Show Notifications" IsChecked="{Binding ShowNotifications, Source={x:Static local:Settings.Instance}}"/>
Expand All @@ -582,9 +593,8 @@
SelectedValue="{Binding NotificationTimeout, Source={x:Static local:Settings.Instance}}"/>
</StackPanel>

<StackPanel>
<CheckBox Content="Enable Images" IsChecked="{Binding EnableImages, Source={x:Static local:Settings.Instance}}"/>
</StackPanel>
<CheckBox Content="Enable Images" IsChecked="{Binding EnableImages, Source={x:Static local:Settings.Instance}}"/>

</StackPanel>
</GroupBox>
<GroupBox Header="Other" Grid.Row="3" Margin="10,10,10,10">
Expand Down
17 changes: 12 additions & 5 deletions SjUpdater/Model/FavShowData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,15 @@ public void ApplyFilter(bool reset=true)
ignoreCurrentUpload = true;
do
{
if ((currentUpload.Language & FilterLanguage) == 0) //Filter: Language

UploadLanguage language = currentUpload.Language;
if (!Settings.Instance.MarkSubbedAsGerman && currentUpload.Subbed) //dont mark german-subbed as german
{
language&=~UploadLanguage.German; //remove german
}

if ((language & FilterLanguage) == 0) //Filter: Language
break;


if (!String.IsNullOrWhiteSpace(FilterRuntime) && //Filter: Runtime
!(new Regex(FilterRuntime).Match(currentUpload.Runtime).Success))
Expand Down Expand Up @@ -213,10 +219,11 @@ public void ApplyFilter(bool reset=true)
int episodeNr = -1;
if (seasonNr != -1)
{
Match m1 = new Regex("S0{0,4}" + seasonNr + "E(\\d+)", RegexOptions.IgnoreCase).Match(download.Title);
if (m1.Success)
MatchCollection mts = new Regex("S0{0,4}" + seasonNr + "E(\\d+)", RegexOptions.IgnoreCase).Matches(download.Title);
MatchCollection mts_ep = new Regex("[^A-Z]E(\\d+)", RegexOptions.IgnoreCase).Matches(download.Title);
if (mts.Count==1 && mts_ep.Count==1) //if there is exactly one match for "S<xx>E<yy>" and there is no second "E<zz>" (e.g. S01E01-E12)
{
int.TryParse(m1.Groups[1].Value, out episodeNr);
int.TryParse(mts[0].Groups[1].Value, out episodeNr);
}

if (episodeNr == -1 && !FilterShowNonEpisode.GetValueOrDefault()) //Filter: NonEpisode Stuff
Expand Down
2 changes: 2 additions & 0 deletions SjUpdater/Model/UploadData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public UploadData()
Size = "";
Runtime = "";
Language = 0;
Subbed = false;
Season = null;
Favorized = false;
}
Expand All @@ -30,6 +31,7 @@ public UploadData()
public String Runtime { get; set; }
public UploadLanguage Language { get; set; }
public SeasonData Season { get; set; }
public bool Subbed { get; set; }

public bool Favorized { get; set; } //Todo: move to Fav* class, since it's user data

Expand Down
4 changes: 4 additions & 0 deletions SjUpdater/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public ObservableCollection<FavShowData> TvShows
/// <summary>
/// The Numer of Threads used to fetch updates on programm start
/// </summary>

public bool MarkSubbedAsGerman { get; set; }
public uint NumFetchThreads
{
get { return numFetchThreads; }
Expand Down Expand Up @@ -171,6 +173,7 @@ public uint NumFetchThreads
public String FilterUploader { get; set; }
public String FilterSize { get; set; }
public String FilterRuntime { get; set; }


public Settings()
{
Expand All @@ -186,6 +189,7 @@ public Settings()
FilterLanguage = UploadLanguage.Any;
FilterShowNonEpisode = true;
FilterShowNonSeason = true;
MarkSubbedAsGerman = false;
NoPersonalData = false;
EnableImages = true;
CheckForUpdates = true;
Expand Down
38 changes: 16 additions & 22 deletions SjUpdater/SjInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using RestSharp;
using SjUpdater.Model;
using SjUpdater.Utils;
Expand Down Expand Up @@ -203,11 +204,14 @@ private static List<DownloadData> ParseSite(ShowData showData, string url, out s
Match m;
SeasonData seasonData=null;
UploadData uploadData=null;
// int season = -1;

while (!reader.EndOfStream)
{
String line = reader.ReadLine();
if (line.Contains("line-height") && line.Contains("&nbsp;")) //detect: <div style="line-height:5px;height:5px;background-color:lightgrey;">&nbsp;</div>
{
continue; //I can only hope this will never occour in any other case..
}
if (inContent)
{
if (inPost)
Expand All @@ -229,15 +233,6 @@ private static List<DownloadData> ParseSite(ShowData showData, string url, out s
continue;
}
string title = WebUtility.HtmlDecode(m.Groups[1].Value);
/*int episode = -1;
if (season != -1)
{
Match m1 = new Regex("S0{0,4}" + season + "E(\\d+)", RegexOptions.IgnoreCase).Match(title);
if (m1.Success)
{
int.TryParse(m1.Groups[1].Value, out episode);
}
}*/

var downloads = new Dictionary<string, string>();
Regex r = new Regex("<a\\s+href\\s*=\"([^\"]+)\".+\\s+(.+?)\\s*<");
Expand All @@ -261,20 +256,19 @@ private static List<DownloadData> ParseSite(ShowData showData, string url, out s
key = keyOrg + "(" + ++num + ")";
}
String val = m2.Groups[1].Value;
if (val != null && !String.IsNullOrWhiteSpace(val) && val.StartsWith("http://"))
if (val != null && !String.IsNullOrWhiteSpace(val) && val.Trim().StartsWith("http://"))
{
downloads.Add(key, val);
}
else
{
Console.WriteLine("Warning: Invalid Download received while parsing " + showData.Name + ". Ignoring link");
//ignoring invalid download
}
}
if (line.Contains("</p>"))
break;
}



if (title.Contains("720p") )
{
Expand All @@ -295,10 +289,13 @@ private static List<DownloadData> ParseSite(ShowData showData, string url, out s

DownloadData dd = new DownloadData();
dd.Upload = uploadCache == null ? uploadData : uploadCache.GetUniqueUploadData(uploadData);

//ed.EpisodeN = episode;
dd.Title = title;

if (title.ToLower().Contains("subbed"))
{
dd.Upload.Subbed = true;
}

foreach (var download in downloads)
{
dd.Links.Add(download.Key,download.Value);
Expand Down Expand Up @@ -354,6 +351,10 @@ private static List<DownloadData> ParseSite(ShowData showData, string url, out s
{
uploadData.Language |= UploadLanguage.English;
}
if (value.Contains("subbed"))
{
uploadData.Subbed = true;
}
}
}
}
Expand Down Expand Up @@ -388,13 +389,6 @@ private static List<DownloadData> ParseSite(ShowData showData, string url, out s

seasonData.Url= m.Groups[1].Value;
seasonData.Title = WebUtility.HtmlDecode(m.Groups[2].Value);
/*season = -1;
Match m2 = new Regex("(?:season|staffel)\\s*(\\d+)", RegexOptions.IgnoreCase).Match(seasonData.Title);
if (m2.Success)
{
int.TryParse(m2.Groups[1].Value,out season);
}*/

}
else if (new Regex("<div\\s+class\\s*=\\s*\"post-content\"\\s*>").Match(line).Success)
{
Expand Down
3 changes: 3 additions & 0 deletions SjUpdater/SjUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="Utils\CachedBitmap.cs" />
<Compile Include="Utils\Crc64.cs" />
<Compile Include="Utils\ExtensionMethods.cs" />
<Compile Include="Utils\FavIcon.cs" />
<Compile Include="Utils\GlobalMutex.cs" />
<Compile Include="Utils\Native.cs" />
<Compile Include="Properties\Annotations.cs" />
Expand All @@ -138,6 +139,7 @@
<Compile Include="SjInfo.cs" />
<Compile Include="Utils\StaticInstance.cs" />
<Compile Include="Utils\Stats.cs" />
<Compile Include="Utils\StringToFaviconConverter.cs" />
<Compile Include="Utils\ThreadPool.cs" />
<Compile Include="Utils\timehelper.cs" />
<Compile Include="Utils\UploadCache.cs" />
Expand Down Expand Up @@ -186,6 +188,7 @@
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<AppDesigner Include="Properties\" />
<None Include="Model\ClassDiagram1.cd" />
Expand Down
2 changes: 1 addition & 1 deletion SjUpdater/Utils/CachedBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static MemoryStream DownloadData(string url)
}
}

private static BitmapImage BitmapImageFromStream(Stream stream, bool freeze = true)
public static BitmapImage BitmapImageFromStream(Stream stream, bool freeze = true)
{
try
{
Expand Down
Loading

0 comments on commit 024eb2a

Please sign in to comment.