Personal Video Database

English => Development => Topic started by: firefox on October 20, 2013, 05:23:53 pm

Title: Character encoding for script
Post by: firefox on October 20, 2013, 05:23:53 pm
Hello,
Many thanks for the great program.
I've started to write an import script for japanese site (EUC-JP encoding) and I've noticed a strange thing.
I cannot use japanese character in PosFrom.
Os: Windows 8, PVD 1.0.2.6, the script file saved with encoding utf-8.
Code: [Select]
  StartPos := Pos('<table border="0" cellpadding="2" cellspacing="0" class="mg-b20">', HTML);
  StartPos := PosFrom('">レーベル:</td>', HTML, StartPos);
    Cast := Trim(TextBetween(HTML, '>', '<', False, StartPos));
  if Cast <> '----' then
  begin
    CastURL := BASE_URL + Trim(TextBetween(HTML, 'href="', '"', False, StartPos));
    Cast := Trim(TextBetween(HTML, '">', '<', False, StartPos));
    LogMessage('writer: '+ Cast +', url: '+ CastURL);
    AddMoviePerson(Cast, '', '', CastURL, 2);
  end else
    LogMessage('writer not found');

Title: Re: Character encoding for script
Post by: nostra on October 20, 2013, 05:53:37 pm
Make sure to provide a correct code page in GetCodePage function
Code: [Select]
function GetCodePage : Cardinal;
begin
 Result := CODE_PAGE;
end;
Title: Re: Character encoding for script
Post by: firefox on October 21, 2013, 04:24:40 am
I provided a code page in GetCodePage function (EUC-JP 20932).
You can search with keyword 'mgod0112' with attached script file.
I use writer item for film series info. The writer item didn't show after running the script.
Thank you for your help!
Title: Re: Character encoding for script
Post by: nostra on October 22, 2013, 06:42:38 pm
There seem to be multiple problems (the program was never tested with such languages):
1. There is a problem when passing data to the script. I will fix it in next update
2. The pascal script compiler does not accept non ANSI characters. This can't be fixed, unless the pascal script compiler is updated. As a workaround you could try saving values in japanese in a file and load them in runtime. (but the first problem must be fixed for this to work)
Title: Re: Character encoding for script
Post by: firefox on November 06, 2013, 09:42:35 am
There seem to be multiple problems (the program was never tested with such languages):
1. There is a problem when passing data to the script. I will fix it in next update
2. The pascal script compiler does not accept non ANSI characters. This can't be fixed, unless the pascal script compiler is updated. As a workaround you could try saving values in japanese in a file and load them in runtime. (but the first problem must be fixed for this to work)
Please give me an example code for saving japanese values in a file and load them in runtime.
Many thanks for your help and PVD v1.0.2.7!
Title: Re: Character encoding for script
Post by: nostra on November 06, 2013, 08:14:10 pm
To find ">レーベル:</td> from your example do the following:
1. Create a file (for exmple value1.txt) in the "PVD Path\Scripts" directory
2. Put ">レーベル:</td> into the file and save it with UTF8 Encoding with BOM
3. Replace the line where you search for this text with the following line:
Code: [Select]
StartPos := PosFrom(FileToString(GetAppPath + 'Scripts\value1.txt'), HTML, StartPos);So the value is replaced with: FileToString(GetAppPath + 'Scripts\value1.txt')
Title: Re: Character encoding for script
Post by: firefox on November 08, 2013, 11:44:40 am
Thanks nostra for example code. Finally, the script works well.
Is there any possible way that saving multiple japanese values in one txt file and load them in runtime?
Title: Re: Character encoding for script
Post by: nostra on November 08, 2013, 06:48:11 pm
You can save multiple values in the same file, load the file to a string and then split it into separate values using String manipulation functions.
Title: Re: Character encoding for script
Post by: firefox on November 09, 2013, 01:57:48 pm
I finished the script and it runs well.
Many thanks for your help!