[WS] iTunes source script with multiple search criteria

Greetings to the web sources community.

I'm copying my original post from [General Discussion] to [Development>Web Sources scripts] to faciitate the sharing of my script, and to make it easier to discuss improvements / modifications.

Please note this is NOT a finished product. It's still in development, due to a large oversight on my part.
Details are in this post.

After using pone's WS Itunes script(s) for years, I've finally decided to take up scipting and give a shot
at creating a tool with the functions I wanted. And the main one was create a script that could be
used internationally, i.e. I could somehow define what country the script would query.

This made sense to me, since if there was an artist from a certain country, or if an album had a localized
special edition, I would want to get metadata info from Itunes from that country. There are already WS scripts for several countries, but personally I find them cumbersome. I don't need scripts for 20+ countries if I mainly use just 2 or 3 and seldom use the rest. So that was my starting point.


"Search by:" / [clear]
The "Search by:" box has the following fields:

"Country:" Simply state which country you would like the script to query. Please use correct country codes
or a bad request error will be generated. List of available country codes is available at https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

"Language:" / [clear] / en_us / ja_jp
On the Itunes API page is mentioned the possibility of displaying results from a non-English alphabet (e.g japanese) in English, or displaying search results in japanese charaters from the english alphabet, if provided by the database. For always displaying results in English, the 'language' field must have the value 'en_us'; for always displaying results in japanese, the value must be 'ja_jp'. Leaving the field blank will display the results as is. Other/incorrect values will return a bad request error message

NB: Though the ja_jp option exists and is available, I have never had a query whose results were ported to japanese characters if they were not already the original writing system. Please take note of this if/when using the 'ja_jp' option.

"Query:" / [clear]
Standard query field; script will load artist and album info onto the filed, if said info is already present in the files. Query also loads the itunes' unique album identification code (if available), which dramatically increases search times and displays always correct results, if provided with correct info. Manual input is also available.

This script is intended to be used in tandem with localized versions; as a tool to perform one-off searches of seldom searched countries, instead of having 20+ WS scripts cluttering the Tag Sources menu.

So, please enjoy using this script, as much as I enjoyed making it (and leave a like if you think the script is worth it).

Thank you.

Current release:
- beta version 200191130_0

Known issues:
- [Query field] only supports UTF-8-compatible characters (A-Z, a-z, 0-9). Foreign writing systems (eg. japanese kanji/kana) or special characters (eg. ç, é, ö) will return an invalid url error. Queries in English should be safe, as well as [CollectionId] number queries

iTunes_INTERNATIONAL_beta20191130_0.src (7.0 KB)

Here's some addicional info regarding my script:

- first, this is not a copy of pone's WS scripts. I have used them for many years, and when I decided to try to crete my own script, I used pone scripts to learn the proper commands, and how a search is conducted, as well as a template. But it is my own creation, and I've added some feature I could not find previously (like multiple search fields).

- This is a work in progress, in beta stage. Since I'm trying to create an international iTunes script, the inability to query in foreign writing systems, to call this a finished product would be incorrect.

For any fellow script enthusiast, here is my current problem, with an example:
- Conduct a search in Itunes store- japan, for an album, using the term "らき☆すた", and list the first 20 results, in english.

The query link would be:

Since the API can't recognize japanese characters, I have to use url-utf-8 encoding, which encodes
"term=らき☆すた" into "term=%E3%82%89%E3%81%8D%E2%98%86%E3%81%99%E3%81%9F"

In WS script, this would be:
[SearchBy]=らき☆すた, or rather

Which works fine. However, in order to have the search parameters as variables, I need:

which outputs

And this doesn't work. Because not only "らき☆すた" value gets converted into URL-UTF-8, but also the "&" and "=" symbols in "&lang=", &country=" and "&term=" which the API can't recognize

I can change the encoding to 'utf-8', but then I'd be back at square one, because "らき☆すた" isn't recognized.

Any help would be greatly appreciated. Thank you.