Help - Search - Members - Calendar
Full Version: Remove all linebreaks, carriage returns and such
Mp3tag Forums > Mp3tag - International > Support
DetlevD
Via private email the user "ra7h35m20s" has asked me this question ...
QUOTE
Hey there... since I have noticed you as the regex god on this forum I was hoping you could help me out a bit. i have these scripts that run itunes json (iTunes_Artist & iTunes_Album). problem i have is when a line break happens in the returned response the script breaks ... i have attached the scripts for your review. is there a way to place some regex in there to remove all linebreaks, carriage returns and such. i have scoured the threads and found a place where you reference the ascii codes for each but have not been able to get it to function in the script ....
thanx a bunch!!

unfortunately the file uploader is not working so i have pasted the index portion of the script here... sorry
CODE
[Name]=iTunes - Artist
[BasedOn]=http://itunes.apple.com
[IndexUrl]=http://itunes.apple.com/search?term=%s&media=music&entity=album&attribute=albumTerm&limit=15
[AlbumUrl]=
[WordSeperator]=-
[IndexFormat]=%_url%|%Artist%|%Album%|%Price%|%Tracks%
[SearchBy]=%album%
[Encoding]=utf-8

[ParserScriptIndex]=...
############################
#         SEARCH RESULTS DIALOG             #
############################

findline "wrapperType\""

do
  
   replace "\\\"" """

   # URL
findline "wrapperType\""
replace "?uo=4" ""
findinline "\"collectionViewUrl\":\""
sayuntil "\""            
   say "|"

# ARTIST
findline "wrapperType\""
findinline "\"artistName\":\""
  sayuntil "\""
   say "|"

# ALBUM
  findline "wrapperType\""
findinline "\"collectionName\":\""
sayuntil "\""
   say "|"

# PRICE
  findline "wrapperType\""
say "$"
  findinline "\"collectionPrice\":"
   sayuntil ","  
   say "|"

# TRACKS
findline "wrapperType\""
findinline "\"trackCount\":"
  sayuntil ","

  saynewline

  findline "wrapperType\"" 2 1

while "{\"wrapperType" 99

... and I think it is a question of general interest and can be answered by other users, who have more affinity to Mp3tag web source scripts than me.

The Mp3tag built in regex machine knows the character class \s, for example ..
$regexp($char(9)$char(10)$char(11)$char(12)$char(13)$char(32)$char(160),'\s',%DUMMY%)
... will give an empty string.

QUOTE
... to remove all linebreaks, carriage returns and such. ...

... there are character classes ...
tab \t
newline \n
vertical-tab \v
form-feed \f
carriage-return \r

DD.20120305.0725.CET
dano
You can bring the text to one line with the joinuntil command.
pone
@ra7h35m20s:

How do the linebreaks look like in the json source? \r\n or \u000d\u000a ?
Do you want to write linebreaks into your output or should they be replaced by something else?
but both types should not break the script.

Or are you talking about linebreaks in the actual json document? Looks like the itunes json has more than one line.
If so:
findinline "..." 1 1 stops at the end of the line if the searched string can not be found.
findline "..." 1 1 stops at the end of the document if the searched string can not be found.


btw, at the start of the script:

replace "\\\"" """

sould be:

replace "\\\"" "\""
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.