Find likeliest logo to string

Get help with using AutoHotkey and its commands and hotkeys
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Find likeliest logo to string

15 Jun 2017, 13:55

Hmm...this was way tricker than I anticipated, mainly cuz the needle is not known on before hand. Im trying to find which is the likeliest logo for the string. In this case its logo8. The string changes all the time, but haystack of logos doesnt.

Code: Select all

Array := {logo1: "C:\Program Files (x86)\DVBViewer\Images\Logos\STV1 HD.png"
    ,     logo2: "C:\Program Files (x86)\DVBViewer\Images\Logos\SVT2 HD.png"
	,     logo3: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV3.png"
	,     logo4: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV4.png"
	,     logo5: "C:\Program Files (x86)\DVBViewer\Images\Logos\Kanal 5.png"
	,     logo6: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV6.png"
    ,     logo7: "C:\Program Files (x86)\DVBViewer\Images\Logos\Sjuan.png"
	,     logo8: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV8.png"
	,     logo9: "C:\Program Files (x86)\DVBViewer\Images\Logos\Kanal 9.png"
	,     logo10: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV10.png"
	,     logo11: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV11.png"
	,     logo12: "C:\Program Files (x86)\DVBViewer\Images\Logos\Discovery Channel.png"}
for i, k in Array
  msgbox % i "=" k

string := "F:\TV\Recording Service\20170615_18-36-51_TV8_Lyxfällan Norge -.ts"
User avatar
Xtra
Posts: 1920
Joined: 02 Oct 2015, 12:15

Re: Find likeliest logo to string

15 Jun 2017, 14:22

Code: Select all

string := "F:\TV\Recording Service\20170615_18-36-51_TV8_Lyxfällan Norge -.ts"
MsgBox,, Likeliest logo, % LogoLookup(string)


LogoLookup(string)
{
    static Array := {logo1: "C:\Program Files (x86)\DVBViewer\Images\Logos\STV1 HD.png"
               ,     logo2: "C:\Program Files (x86)\DVBViewer\Images\Logos\SVT2 HD.png"
	           ,     logo3: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV3.png"
	           ,     logo4: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV4.png"
	           ,     logo5: "C:\Program Files (x86)\DVBViewer\Images\Logos\Kanal 5.png"
	           ,     logo6: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV6.png"
               ,     logo7: "C:\Program Files (x86)\DVBViewer\Images\Logos\Sjuan.png"
	           ,     logo8: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV8.png"
	           ,     logo9: "C:\Program Files (x86)\DVBViewer\Images\Logos\Kanal 9.png"
	           ,     logo10: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV10.png"
	           ,     logo11: "C:\Program Files (x86)\DVBViewer\Images\Logos\TV11.png"
	           ,     logo12: "C:\Program Files (x86)\DVBViewer\Images\Logos\Discovery Channel.png"}
    for logo, path in Array           
        if InStr(string, StrReplace(SubStr(path,1,-4),"C:\Program Files (x86)\DVBViewer\Images\Logos\"))
            return path
    return "Error"
}

; or the same method but faster:

string := "F:\TV\Recording Service\20170615_18-36-51_TV8_Lyxfällan Norge -.ts"
MsgBox,, Likeliest logo, % LogoLookup(string)


LogoLookup(string)
{
    static Array := {"STV1 HD": "C:\Program Files (x86)\DVBViewer\Images\Logos\STV1 HD.png"
               ,     "SVT2 HD": "C:\Program Files (x86)\DVBViewer\Images\Logos\SVT2 HD.png"
	           ,     "TV3": "C:\Program Files (x86)\DVBViewer\Images\Logos\TV3.png"
	           ,     "TV4": "C:\Program Files (x86)\DVBViewer\Images\Logos\TV4.png"
	           ,     "Kanal 5": "C:\Program Files (x86)\DVBViewer\Images\Logos\Kanal 5.png"
	           ,     "TV6": "C:\Program Files (x86)\DVBViewer\Images\Logos\TV6.png"
               ,     "Sjuan": "C:\Program Files (x86)\DVBViewer\Images\Logos\Sjuan.png"
	           ,     "TV8": "C:\Program Files (x86)\DVBViewer\Images\Logos\TV8.png"
	           ,     "Kanal 9": "C:\Program Files (x86)\DVBViewer\Images\Logos\Kanal 9.png"
	           ,     "TV10": "C:\Program Files (x86)\DVBViewer\Images\Logos\TV10.png"
	           ,     "TV11": "C:\Program Files (x86)\DVBViewer\Images\Logos\TV11.png"
	           ,     "Discovery Channel": "C:\Program Files (x86)\DVBViewer\Images\Logos\Discovery Channel.png"}
    for logo, path in Array           
        if InStr(string, logo)
            return path
    return "Error"
}

zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: Find likeliest logo to string

15 Jun 2017, 14:37

Oh thanks, really smart way to handle it using the StrReplace() :)

Regards
zcooler
User avatar
Xtra
Posts: 1920
Joined: 02 Oct 2015, 12:15

Re: Find likeliest logo to string

15 Jun 2017, 14:39

I added a faster method in an edit.

It does lookup based on key.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: Find likeliest logo to string

15 Jun 2017, 14:45

Xtra wrote:I added a faster method in an edit.

It does lookup based on key.
Yes, I did see that and contemplating it. Hmm...yeah it might be possible to do the keys that way when creating the array from a file loop and parse. Good idea, many thanks Xtra :)
Man, the faster method was very nice...

:wave:

Return to “Ask For Help”

Who is online

Users browsing this forum: Bodhi, boiler, electrone77, Ferro, TAC109, TheProdigyC2 and 67 guests