Youtube dynamic IP address list script

Hi Guys,
i have found this article on dynamically updating an address list for all youtube IP's. However the script does not create the address list.

http://adminsline.wordpress.com/2012/08/03/mikrotik-youtube/

I'm not experienced at all with how scripting works, and I'm guessing my problem is that by just doing a copy/paste of the script in this example adds line breaks and such where they shouldn't be...

Can anyone check this script and let me know where to remove the breaks and such? Thanks

:foreach i in=[/ip dns cache find] do={
:local bNew "true";
:local cacheName [/ip dns cache all get $i name] ;

:put $cacheName;

:if ([:find $cacheName "youtube"] != 0) do={

:local tmpAddress [/ip dns cache get $i address] ;

:put $tmpAddress;

if address list is empty do not check

:if ( [/ip firewall address-list find ] = "") do={
:log info ("added entry: $[/ip dns cache get $i name] IP $tmpAddress");
/ip firewall address-list add address=$tmpAddress list=youtube_dns_ips comment=$cacheName;
} else={
:foreach j in=[/ip firewall address-list find ] do={
:if ( [/ip firewall address-list get $j address] = $tmpAddress ) do={
:set bNew "false";
}
}
:if ( $bNew = "true" ) do={
:log info ("added entry: $[/ip dns cache get $i name] IP $tmpAddress");
/ip firewall address-list add address=$tmpAddress list=youtube_dns_ips comment=$cacheName;
}
}
}
}

Perhaps your cache does not have YouTube in it? The script seems to require it. Perhaps if you add

:resolve "youtube.com";

at the start.

Also, keep in mind your script, as written, will also match any domain including “youtube” in it, that may not belong to youtube, e.g. “youtube.mysite.com”. You may want to adjust that to “youtube.com” to avoid that.

BTW, I’m not entirely sure iterating over the whole cache is the best option in general. I previously made a script that uses the API to make a request to a domain, and then add its IPs to one or more address lists. The script in question also makes itself run at regular intervals, dictated by the domain itself (which is what your DNS cache honors anyway).

Thank you, I shall check out your script now.