GithubHelp home page GithubHelp logo

Comments (7)

TarheelGrad1998 avatar TarheelGrad1998 commented on August 29, 2024

Thanks for the heads up. I am still on 2022.5 but plan to upgrade in the next week or so, and I do use both components, so if they are fixable I certainly will.

from gallery-card.

0n3man avatar 0n3man commented on August 29, 2024

As the gallery card allows for pulling the date and time from the file name, and then sorting based on these dates and time, any chance for modification to allow some type of wild card character to allow processing filenames with additional data. Here are a couple examples of the file names I using: person-06-07-22-21:57:31.jpg, cat-06-04-22-21:40:26.jpg , dog-06-04-22-00:44:06.jpg. I'm using zoneminder to do image processing of my video streams and then passing snapshots with new objects are identified to HA. I tag the file that are then passed to HA with the object name, along with the date and time. If the gallery card handled pulling date and time from this type of file name then I could use the folder platform instead of the files platform.

from gallery-card.

0n3man avatar 0n3man commented on August 29, 2024

For some reason I couldn't clone your repo to my online github account so I couldn't generate a pull request. The following is patch that works for my filename formatting. If you like it please consider including it in your gallery-card.js.

diff --git a/gallery-card.js b/gallery-card.js
index 08b0435..9d8097a 100644
--- a/gallery-card.js
+++ b/gallery-card.js
@@ -571,7 +571,7 @@ class GalleryCard extends LitElement {
       if (fileNameFormat === undefined || captionFormat === undefined)
           fileCaption = fileName;
       else {
-        var tokens = ["%YYY", "%m", "%d", "%H", "%M", "%S", "%p"]
+        var tokens = ["%YYY", "%y", "%m", "%d", "%H", "%M", "%S", "%p"]
         fileCaption = captionFormat;

         var hr = 0;
@@ -581,12 +581,20 @@ class GalleryCard extends LitElement {
         var hour = 0;
         var min = 0;
         var sec = 0;
+        var skipVal = 0;
+        skipVal = fileName.search(/\d/) - 1;
+        if (skipVal < 0) {
+          skipVal = 0;
+        }
+
         for (let token of tokens) {
           var searchIndex = fileNameFormat.indexOf(token);

           if (searchIndex >= 0) {
+            searchIndex = searchIndex + skipVal;
             var val = fileName.substring(searchIndex, searchIndex + token.length);
             if (token == "%YYY" ) year = parseInt(val);
+            if (token == "%y" ) year = parseInt(val);
             if (token == "%m" ) month = parseInt(val);
             if (token == "%d" ) day = parseInt(val);
             if (token == "%H" ) hour = parseInt(val);
@@ -1131,6 +1139,7 @@ class GalleryCardEditor extends LitElement {
         Use the following placeholders to reformat the file name into the caption:
         <ul>
           <li>%YYY - A 4 digit year, e.g. 2019</li>
+          <li>%y - A 2 digit year, e.g. 22</li>
           <li>%m - The 2 digit month</li>
           <li>%d - The 2 digit day</li>
           <li>%H - The 2 digit hour</li>
@@ -1390,3 +1399,4 @@ window.customCards.push({
   preview: false, // Optional - defaults to false
   description: "The Gallery Card allows for viewing multiple images/videos.  Requires the Files sensor availble at https://github.com/TarheelGrad1998" // Optional
 });
+

from gallery-card.

0n3man avatar 0n3man commented on August 29, 2024

In the patch above I subtract one on this line

skipVal = fileName.search(/\d/) - 1;

It didn't make any sense why I need to do the -1. This was on a test system I have setup to make things work. I just moved the code to my production system and to make it work I had to remove the -1. It's strange. One is running on RPI4 the operation is running on odroid n2+, both as supervised installs.

from gallery-card.

TarheelGrad1998 avatar TarheelGrad1998 commented on August 29, 2024

I finally got around to upgrading (to 2022.6.7) and my files component still contains all the same attributes. Maybe the core team fixed something in v *.6 or *.7 that was breaking yours? Or if not maybe it was something specific to your configuration? I'm not sure if you're interested in the original fix since you have created a different solution.

As to the pull request, I do have an in progress change where I have completely redone the date parsing, but I agree your change could have use for others with "mixed" file names. I'll take a look when I get time to continue working on that update..

from gallery-card.

0n3man avatar 0n3man commented on August 29, 2024

Thanks for the feedback. I'll have a look at your update. My preference is to use your code if possible. I hate diverging code if it can be prevented.

from gallery-card.

TarheelGrad1998 avatar TarheelGrad1998 commented on August 29, 2024

This is still working as of version 3.4, though you might take a look at the Local Media in media_source to see if that's a better option.

from gallery-card.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.