diff --git a/RPS 4/Monitor.cs b/RPS 4/Monitor.cs index 62bf5dd..1a34a97 100644 --- a/RPS 4/Monitor.cs +++ b/RPS 4/Monitor.cs @@ -97,6 +97,7 @@ public Monitor(IntPtr previewHwnd, int id, Screensaver screensaver): this(id, sc public void defaultShowHide() { this.InvokeScript("setBackgroundColour", new string[] { Convert.ToString(this.screensaver.config.getPersistant("backgroundColour")) }); this.InvokeScript("toggle", new string[] { "#quickMetadata", Convert.ToString(this.screensaver.config.getPersistantBool("showQuickMetadataM" + (this.id + 1))) }); + this.InvokeScript("toggle", new string[] { "#location", Convert.ToString(this.screensaver.config.getPersistantBool("showLocationM" + (this.id + 1))) }); this.InvokeScript("toggle", new string[] { "#filename", Convert.ToString(this.screensaver.config.getPersistantBool("showFilenameM" + (this.id + 1))) }); this.InvokeScript("toggle", new string[] { "#filename .root", Convert.ToString(this.screensaver.config.getPersistantBool("showPathRoot")) }); this.InvokeScript("toggle", new string[] { "#filename .subfolders", Convert.ToString(this.screensaver.config.getPersistantBool("showPathSubfolders")) }); @@ -440,6 +441,12 @@ public void readMetadataImage() { } if (rawMetadata != null && rawMetadata != "") { this.quickMetadata = new MetadataTemplate(rawMetadata, Utils.HtmlDecode(this.screensaver.config.getPersistantString("quickMetadata"))); + if (this.quickMetadata.metadata.ContainsKey("gpslatitude") && this.quickMetadata.metadata.ContainsKey("gpslongitude")) { + string location = Utils.GetLocationFromGps(this.quickMetadata.metadata["gpslatitude"], this.quickMetadata.metadata["gpslongitude"]); + if (location != null) { + this.imageSettings["location"] = location; + } + } this.imageSettings["metadata"] = this.quickMetadata.fillTemplate(); } this.imageSettings["mediatype"] = "image"; diff --git a/RPS 4/RPS 4.csproj b/RPS 4/RPS 4.csproj index 5a39e93..100b4a3 100644 --- a/RPS 4/RPS 4.csproj +++ b/RPS 4/RPS 4.csproj @@ -222,7 +222,7 @@ - call "$(DevEnvDir)..\Tools\vsvars32.bat" + call "$(DevEnvDir)..\Tools\VsDevCmd.bat" IF NOT EXIST "$(TargetDir)vendor" MKDIR "$(TargetDir)vendor" xcopy /d /s "$(ProjectDir)vendor\*.*" "$(TargetDir)vendor" rem IF NOT EXIST "$(TargetDir)data" MKDIR "$(TargetDir)data" diff --git a/RPS 4/Utils.cs b/RPS 4/Utils.cs index dc57dbb..7045568 100644 --- a/RPS 4/Utils.cs +++ b/RPS 4/Utils.cs @@ -11,9 +11,57 @@ using System.Globalization; using System.Collections; using System.Collections.Concurrent; +using System.Net; +using Newtonsoft.Json.Linq; +using System.Text.RegularExpressions; namespace RPS { class Utils { + private static double ConvertDmsToDd(string dms) { + var matches = System.Text.RegularExpressions.Regex.Matches(dms, @"[0-9\.]+"); + var parts = matches.Cast().Select(m => m.Value).ToList(); + + if (parts.Count >= 3) { + double deg = double.Parse(parts[0], CultureInfo.InvariantCulture); + double min = double.Parse(parts[1], CultureInfo.InvariantCulture); + double sec = double.Parse(parts[2], CultureInfo.InvariantCulture); + return deg + (min / 60.0) + (sec / 3600.0); + } else if (parts.Count == 1) { + return double.Parse(parts[0], CultureInfo.InvariantCulture); + } + return 0; + } + + public static string GetLocationFromGps(string latitudeStr, string longitudeStr) { + if (latitudeStr == null || longitudeStr == null) return null; + try { + double latitude = ConvertDmsToDd(latitudeStr); + double longitude = ConvertDmsToDd(longitudeStr); + + if (latitudeStr.ToUpper().Contains("S")) latitude = -latitude; + if (longitudeStr.ToUpper().Contains("W")) longitude = -longitude; + + string url = $"https://nominatim.openstreetmap.org/reverse?format=json&lat={latitude.ToString(CultureInfo.InvariantCulture)}&lon={longitude.ToString(CultureInfo.InvariantCulture)}&accept-language=en"; + Debug.WriteLine("GetLocationFromGps url:" + url); + using (WebClient wc = new WebClient()) { + wc.Headers.Add("User-Agent", "RPS/4.0 (a screensaver)"); // Per Nominatim requirements + string json = wc.DownloadString(url); + JObject data = JObject.Parse(json); + if (data["error"] == null && data["address"] != null) { + string townish = new[] { "town", "city", "municipality", "village" } + .Select(key => (string)data["address"][key]) + .FirstOrDefault(val => !string.IsNullOrEmpty(val)) ?? ""; + string country = (string)data["address"]["country"] ?? ""; + string prettyName = !string.IsNullOrEmpty(townish) ? $"{townish}, {country}" : country; + Debug.WriteLine("GetLocationFromGps:" + prettyName); + return prettyName; + } + } + } catch (Exception ex) { + Debug.WriteLine("Error in GetLocationFromGps: " + ex.Message); + } + return null; + } public struct MSG { IntPtr hwnd; uint message; diff --git a/RPS 4/data/config.html b/RPS 4/data/config.html index 54fe275..4947d12 100644 --- a/RPS 4/data/config.html +++ b/RPS 4/data/config.html @@ -473,6 +473,7 @@

Monitor 1

Information



+
diff --git a/RPS 4/data/css/monitor.css b/RPS 4/data/css/monitor.css index c5bdbc2..8067cb8 100644 --- a/RPS 4/data/css/monitor.css +++ b/RPS 4/data/css/monitor.css @@ -128,6 +128,13 @@ html, body { text-align: right; } +#location { + z-index: 100; + right: 0.5em; + bottom: 2.5em; + text-align: right; +} + #debug { z-index: 100; right: 0.5em; diff --git a/RPS 4/data/js/monitor.js b/RPS 4/data/js/monitor.js index ea2d5f5..6ffaa79 100644 --- a/RPS 4/data/js/monitor.js +++ b/RPS 4/data/js/monitor.js @@ -536,6 +536,11 @@ function showImage(source, displayPath, settings) { $("#filename .filename")[0].innerHTML = settings["path.filename"]; $("#filename .extension")[0].innerHTML = settings["path.extension"]; document.getElementById("quickMetadata").innerHTML = settings["metadata"]; + if (settings["location"] != undefined) { + document.getElementById("location").innerHTML = settings["location"]; + } else { + document.getElementById("location").innerHTML = ""; + } if (settings["pano"] != undefined && settings["pano"] == true) { // window.prompt("Copy to clipboard: Ctrl+C, Enter", html); diff --git a/RPS 4/data/monitor.html b/RPS 4/data/monitor.html index 1c79487..0a27226 100644 --- a/RPS 4/data/monitor.html +++ b/RPS 4/data/monitor.html @@ -23,6 +23,7 @@
#indexprogress#
#debug#
#metadata#
+
#location#
hh:mm:ss
diff --git a/readme.md b/readme.md index 70ca0a8..567d25d 100644 --- a/readme.md +++ b/readme.md @@ -3,6 +3,8 @@ Random Photo Screensaver(tm) 4 Random Photo Screensaver 4 (RPS4) is a photo slideshow screensaver written in Visual Studio C#. +* This fork adds support for displaying photo location using EXIF GPS data. Most of the work was done by Jules, I just added some finishing touches and tweaks. + Download / preview ------------------ You can download the latest executable for Windows 7 & 8/8.1 from [abScreensavers.com](http://www.abscreensavers.com/random-photo-screensaver). This also showcases some of its many features.