* Rename Selected Source Media

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
PyreneesPirate
Famous
Posts: 157
Joined: 06 Feb 2009 20:30
Family Historian: V7
Location: Montamat, SW France

Rename Selected Source Media

Post by PyreneesPirate »

I have searched and found this little gem.


Screenshot 2022-12-07 160731.jpg
Screenshot 2022-12-07 160731.jpg (90.13 KiB) Viewed 1021 times


I have used the following to see what it does and yes it does convert the Media Name to the actual File Name. My question is, I have the following Baptism below:


Screenshot 2022-12-07 161059.jpg
Screenshot 2022-12-07 161059.jpg (12.99 KiB) Viewed 1021 times

How do I edit the Plugin to produce a file name of - Baptism Addlestone, Surrey 1864 (Arthur Charles MOORE)

Any help would be much appreciated as usual.

Thanks
PP
User avatar
tatewise
Megastar
Posts: 28516
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Rename Selected Source Media

Post by tatewise »

Firstly, how familiar are you with editing and testing Plugins?
i.e.
Do we just need to give some tips and you can work out the rest for yourself, or do we need to go step by step?

Secondly, one example of a Source Title and required Filename may not be enough to determine the general algorithm.
i.e.
How is the fragment of the Title to be excluded determined? What are the rules?
Will there always be an opening parenthesis ( to terminate the Place name?
Will there always be a 4-digit year to terminate the excluded text?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
PyreneesPirate
Famous
Posts: 157
Joined: 06 Feb 2009 20:30
Family Historian: V7
Location: Montamat, SW France

Re: Rename Selected Source Media

Post by PyreneesPirate »

Thanks Mike for your reply.

My main issue is Baptisms, Burials and Marriages. At the moment I have no identifier in the filenames for the Baptism and Burial categories. Nearly all of these have been produced through AS so there is some standardization already. But I don't wish to have the whole string as a filename.

Screenshot 2022-12-07 183458.jpg
Screenshot 2022-12-07 183458.jpg (12.77 KiB) Viewed 985 times
This is the current filename Mary Anne Hicks 1857 Aldsworth, Gloucestershire Church Records, I would like to achieve - Burial Aldsworth, Gloucestershire 1857 (Mary Anne Hicks).

Screenshot 2022-12-07 183536.jpg
Screenshot 2022-12-07 183536.jpg (18.04 KiB) Viewed 985 times
This is the current filename MR Matthew Charles Moore and Maria Sanders (Jun 1863 Addlestone), I would like to achieve - Marriage Addlestone, Surrey 1863 (Matthew Charles Moore and Maria Sanders)

Here is what I have for a Census file name, each Census entry has the year in the filename already, so I don't need to address Census items. I understand this is different and I am going through my entries one by one, reloading new Census versions, highlighting the rows, adjusting the contrast, sharpening the characters, reducing the file size and putting the Census references i.e. HO107/1187/2 Schedule 10 Page 11 in the Publication slot and at the same time renaming the files in the Media/Census 1891 folder so that they are uniform. Bit long winded but, I have only the 1901 and 1881 Census still to finish.....

Screenshot 2022-12-07 184300.jpg
Screenshot 2022-12-07 184300.jpg (12.73 KiB) Viewed 985 times
With regards to editing the code, I am not an expert or programmer, but as I said before, I have sold software since 1985. Selling and Programming big difference, but logical all the same... Uh, forget that, Line by line would be preferable! :lol: :lol:

Thanks again,
PP
User avatar
tatewise
Megastar
Posts: 28516
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Rename Selected Source Media

Post by tatewise »

PP, you did not answer my last two questions which are crucial in getting the plugin to work the way you want.
However, assuming both answers were YES then I have a tentative proposal for just your BMD Sources.

Use Tools > Plugins... and click the More >> button to reveal the side panel of buttons.
Select the Rename Selected Source Media plugin and click the Edit... button to open the script editor.
Scroll down to line 42 local sTitle, n = cleanTitle(fhGetDisplayText(p)) and replace it with the following lines:

Code: Select all

		local sSource = fhGetDisplayText(p)
		local sSource, s = sSource:gsub( "^(.+) %(.+ (%d%d%d%d) (.+)$", "%1 %2 (%3)" )
		sSource = sSource:gsub( " & ", " and " )
		if s == 0 then
			tTitleStatus[i] = 'unsuitable Source Title'
			break
		end
		local sTitle, n = cleanTitle(sSource)
Use the File > Save command in the script editor window to save the changes.
Click the Go icon in the toolbar to run the plugin in debug mode, which allows you to click in the left margin to set red bullet break points to monitor progress.
However, it might be best to do all that on a temporary copy of your Project because any renaming of Media files cannot be reversed by FH. i.e. The Edit > Undo Plugin Updates command does NOT undo filename changes.

The main magic above is in the sSource:gsub( "^(.+) %(.+ (%d%d%d%d) (.+)$", "%1 %2 (%3)" ) transformation.

"^(.+) %(.+ (%d%d%d%d) (.+)$" matches your style of Source Titles.
^(.+) %( captures the leading text up to the first space and (
.+ matches but disregards the subsequent text
(%d%d%d%d) captures the year digits
(.+)$ captures the trailing text

"%1 %2 (%3)" defines the format of the transformed Title.
%1 substitutes the 1st capture of leading text
%2 substitutes the 2nd capture of year digits
(%3) substitutes the 3rd capture of trailing text enclosed in ( )

If that transformation fails to recognise the crucial ( and year digits then it sets the status to 'unsuitable Source Title' and breaks out of the plugin.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
PyreneesPirate
Famous
Posts: 157
Joined: 06 Feb 2009 20:30
Family Historian: V7
Location: Montamat, SW France

Re: Rename Selected Source Media

Post by PyreneesPirate »

Thanks for the Plugin update Mike, it worked a treat.

I certainly wouldn't have been able to do the mod to the Plugin without your help. All updated little by little and checked accordingly. It also flushed out a few idiosyncrasies which I have dealt with. How you remember/know how to set up the lua language is beyond me, but thanks again anyway.

All this effort is to bring my data / file names / media names / source names into a better format for using your GEDCOM create facility. As an old software trainer said to me in the 80's - Put Rubbish in, you get Rubbish out!!

PP
User avatar
tatewise
Megastar
Posts: 28516
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Rename Selected Source Media

Post by tatewise »

PyreneesPirate wrote: 12 Dec 2022 18:47 All this effort is to bring my data / file names / media names / source names into a better format for using your GEDCOM create facility.
Which 'GEDCOM create facility' is that? Why does it need a better format?

Since you say most of your Citations and Media are created by AS, it should be possible to use its Tools > Options settings to define all ... Image Title Templates so they define the format you require. Then when adding images the Use Image Template and Rename file to match title options will work henceforth.
Have you done that or do you need help with it?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
PyreneesPirate
Famous
Posts: 157
Joined: 06 Feb 2009 20:30
Family Historian: V7
Location: Montamat, SW France

Re: Rename Selected Source Media

Post by PyreneesPirate »

I have been guilty in the past of loading new media images and not standardising the titles, the same with the media files jpg names. It is that I was referring to when I meant preparing the data better before I run the Gedcom process (nothing to do with the Gedcom process in particular). When I looked through my TNG website, it highlighted the inconsistencies of how I named some similar sources, media and filenames. Obviously, quite a lot of my media / sources are non standard, like Military, Probate, New Items, Obituaries and of course Photographs. All of which I have now standardised to a certain extent.

I may need to look at the output from AS and how it displays the source title, but in general I am happy with that at the moment.

Thanks again Mike.
Post Reply