Page 1 of 1

Find likeliest logo to string

Posted: 15 Jun 2017, 13:55
by zcooler
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"

Re: Find likeliest logo to string

Posted: 15 Jun 2017, 14:22
by Xtra

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"
}


Re: Find likeliest logo to string

Posted: 15 Jun 2017, 14:37
by zcooler
Oh thanks, really smart way to handle it using the StrReplace() :)

Regards
zcooler

Re: Find likeliest logo to string

Posted: 15 Jun 2017, 14:39
by Xtra
I added a faster method in an edit.

It does lookup based on key.

Re: Find likeliest logo to string

Posted: 15 Jun 2017, 14:45
by zcooler
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: