From f7be8f323ffa9fae3c70fb6e3faf2d7a1366e230 Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Thu, 16 Mar 2017 23:43:47 -0700 Subject: [PATCH] Use original name from EXIF instead of parsing assumed file name format. #107 (#202) --- elodie/filesystem.py | 30 +++++++++++------- .../files/with-filename-and-title-in-exif.jpg | Bin 0 -> 18323 bytes elodie/tests/files/with-filename-in-exif.jpg | Bin 0 -> 18214 bytes elodie/tests/filesystem_test.py | 14 ++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 elodie/tests/files/with-filename-and-title-in-exif.jpg create mode 100644 elodie/tests/files/with-filename-in-exif.jpg diff --git a/elodie/filesystem.py b/elodie/filesystem.py index 9577e38..fcbff06 100644 --- a/elodie/filesystem.py +++ b/elodie/filesystem.py @@ -111,18 +111,24 @@ class FileSystem(object): if(metadata is None): return None - # If the file has EXIF title we use that in the file name - # (i.e. my-favorite-photo-img_1234.jpg) - # We want to remove the date prefix we add to the name. - # This helps when re-running the program on file which were already - # processed. - base_name = re.sub( - '^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-', - '', - metadata['base_name'] - ) - if(len(base_name) == 0): - base_name = metadata['base_name'] + # First we check if we have metadata['original_name']. + # We have to do this for backwards compatibility because + # we original did not store this back into EXIF. + if(metadata['original_name'] is not None): + base_name = os.path.splitext(metadata['original_name'])[0] + else: + # If the file has EXIF title we use that in the file name + # (i.e. my-favorite-photo-img_1234.jpg) + # We want to remove the date prefix we add to the name. + # This helps when re-running the program on file which were already + # processed. + base_name = re.sub( + '^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}-', + '', + metadata['base_name'] + ) + if(len(base_name) == 0): + base_name = metadata['base_name'] if( 'title' in metadata and diff --git a/elodie/tests/files/with-filename-and-title-in-exif.jpg b/elodie/tests/files/with-filename-and-title-in-exif.jpg new file mode 100644 index 0000000000000000000000000000000000000000..75627e0d186938b75f3c50ca31b00d606dbfe221 GIT binary patch literal 18323 z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l$?qazV!%RDwxwNg9k6JB_LdUv=RqPqCbG^@ut!JWBJulq z`0`-e_8`#FJf+a}vJIi3b_ovjikj&QUJTQd1@KAcG7Ml7$R(I1L;JJk+gS#1DE!8c zwo!!TkUoI0ffgA6+h-nOj`S z(bo?GLV7ln3&2Zqb=ddEv#=k0_z}MM8}No6eNmMVv8*@K%gamn(gOVY1$~JO)6Vsy zm(3UKUK~eR4*Z%@1LdZMud)6FK9LF>-iOyB1W2D>GnxSBo`&>+(s`Qx9ZYM*0=$pP zU4`^;%}l?9>5`fL9;P*@1kk*R^fj6e;CqS(N@n^nrVV(f4DKYWHaF;lCLZ4|;LSt9 zD;v5Y)pZ^=Syip6!j3I{ug=sDxyWey>0t_e8^5p}OmS~KK<&%D=dT=?Q&1V!F;}&DTsU9q5lx^mKJ~b$9i2clY%7z-O?pr>AdlXkcJ)U|?uuh+fvs%(Q=Vy}iAA zhV~p9898)=KSFWE{t*iJ)durND6YagHypkM=f3(nAY`PSra9UH+1CLvf1H7X-=r7? t`CmNcF63=a2cfJ!_>mm0o2=0!{D=li;%{hJ&_JN)BqMN=97mzw`5#DfOalM_ literal 0 HcmV?d00001 diff --git a/elodie/tests/files/with-filename-in-exif.jpg b/elodie/tests/files/with-filename-in-exif.jpg new file mode 100644 index 0000000000000000000000000000000000000000..fe09b51f22fc92ff86edea40fd0c8986263f4b8c GIT binary patch literal 18214 zcmeG^X>23cd2dMF(rTqW;%&T0$KGAb&RXK|l0;U^U6P`XRNR#*dL0`mj3GIsW_QS; zXND_j(I1JMCPB~^wwgFd;GoWW)1X0twrQIJO_4U+Z5tRZQXg@W-geTo2;kPK?KD3E zsNeTy-W=qtw1*dVTaCn-_rB|W?|a|--Z974ceY;X`R&}gTqPu*C+{bO^pRnXkRYTu zQh^g^rJsUyfTj`m6|TpE2LQg8z?t;G?@zc9nmz#OE8ISd1_W{ktu%0R?4A?TiwAp3Dzr5LP!~b}**OCtw-0Zi~Baj}jX|8NOLFEUhV*r2BmELsH&sgo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