I've done a lot of puzzling with provided ATF functions over the past day, and I've encountered and solved a bunch of issues. I will walk through my process and provide my entire format at the end.
What I wanted to achieve after seeing the twitter plugin, was an account that basically automatically recommends the music I enjoy when I listen to it. I wanted WACUP to post a tweet of the song I'm currently listening to, if two criteria were met:
- the song has a
%rating%
- the song has a
%comment%
and the%comment%
contains a url
It's quite simple to achieve the filters to prevent tweeting when there's 1 or more of the metadata fields missing.
By using an $if(%blah%,%blah%,noblah)
in the formatting, and adding noblah
to the phrase
filter (replacing "blah" with any existing field of course), WACUP will not post any tweets if the
metadata fields are empty, I implemented this as follows:
Filter by phrase: unrated;nocomment
$if(%comment%,%comment%,nocomment)
$if(%rating%,%rating%,unrated)
This was quite the challenge, I won't lie. I'm used to having loops & advanced string manipulation at my disposal so this definitely had me looking at string manipulation in a different light.
I wanted to credit artists and provide followers with a quick way to purchase or stream the songs
I'm recommending. All purchases made through bandcamp automatically get a %comment%
field added,
with the link to the page the release was purchased from. This is why I chose to use the %comment%
field for track links.
The issue that I encountered, was that some songs have comments that either contain no links, or are
so long they won't fit in 280 characters. This meant I had to extract just the link (I chose to go
for the first link) in the %comment%
.
After plenty of time lost to dead ends, a friend of mine gave me a new perspective, which resulted in the following format.
$if(%comment%,$split($substr(%comment% nolink,$if2($ifgreater($strstr(%comment%,https://),0,$strstr(%comment%,https://),)$ifgreater($strstr(%comment%,http://),0,$strstr(%comment%,http://),),$add($len(%comment%),2)),), ,0),nolink)
I've "formatted" it to be more human-readable, but keep in mind this doesn't actually work in ATF.
$if(
%comment%,
$split(
$substr(%comment% nolink,
$if2(
$ifgreater($strstr(%comment%,https://),0,$strstr(%comment%,https://),)
$ifgreater($strstr(%comment%,http://),0,$strstr(%comment%,http://),),
%add($len(%comment%),2)
),
)
, ,0
),
nolink
)
- if
%comment%
, is non-empty, returnvalue
, else returnnolink
. - return the first value before a whitespace
' '
- return a substring of
%comment% nolink
from a certainindex
-
- if there is an occurrence of either
https://
orhttp://
in%comment%
, theindex
for$substr
is the character index of that occurrence. - else, the
index
for$substr()
is the length of%comment%
(+2 to adjust for the non-0-indexing of$substr()
, and the whitespace).
- if there is an occurrence of either
- if there is a url somewhere in
%comment%
, the first one will be at the beginning of the$substr()
.$split()
will return everything before the first whitespace' '
(just the url). - if there is no url in
%comment%
, the$substr()
and%split()
will returnnolink
- if there is no
%comment%
, returnnolink
Et voilà, we have extracted the first url from the %comment%
! And we've also made sure that if
there are no links in a non-empty %comment%
, it will still return nolink
, so that a tweet
doesn't get sent out.
Since using this stuff inline can be quite hard to read in-practice, I like to first process the
values I need, store them in variables, and just $get()
them at a later point. See below:
$puts(_link,$if(%comment%,$split($substr(%comment% nolink,$if2($ifgreater($strstr(%comment%,https://),0,$strstr(%comment%,https://),)$ifgreater($strstr(%comment%,http://),0,$strstr(%comment%,http://),),$add($len(%comment%),2)),), ,0),nolink))
$puts(
_link,
$if(
%comment%,
$split(
$substr(%comment% nolink,
$if2(
$ifgreater($strstr(%comment%,https://),0,$strstr(%comment%,https://),)
$ifgreater($strstr(%comment%,http://),0,$strstr(%comment%,http://),),
%add($len(%comment%),2)
),
)
, ,0
),
nolink
)
)
I thought it was important to make sure my tweets look somewhat presentable, especially because I'm reviewing other people's hard work.
Of course we need to include the artist, track title, and, preferrably, which album the song is from.
$puts(_title,$iflonger($put(_title,[%artist% - ]$if2(%title%,$filepart(%filename%))),81,$cut($get(_title),78)...,$get(_title)))
$puts(
_title,
$iflonger(
$put(
_title,
[%artist% - ]$if2(%title%,$filepart(%filename%))
),
81,
$cut($get(_title),78)...,
$get(_title)
)
)
If non-empty, this stores %title%
to _title
, else the %filename%
. Includes %artist%
, if
non-empty.
$puts(_album,[from: %album%][ '('%year%')'])
$puts(
_album,
[from: %album%][ '('%year%')']
)
simply having a number represent the rating is a little boring, so I chose to format my rating with unicode stars!
$puts(_rating,$if(%rating%,$repeat(★,%rating%)$repeat(☆,$sub(5,%rating%)),unrated))
$puts(
_rating,
$if(
%rating%,
$repeat(★,%rating%)$repeat(☆,$sub(5,%rating%)),
unrated
)
)
- if
%rating%
is non-empty, return a formatted rating, elseunrated
$repeat()
repeats%rating%
amount of filled stars, and5 - %rating%
amount of hollow stars- store the return value in
_rating
Simply slapping in the one-liners we made before, we can make a nice looking tweet format, quite quickly and simply! At the top, I've pasted all the one-liners, which store the formatted values in the variables.
Below these, we can start composing the tweet. It will look like there's some whitespace at the top, in the preview window, we don't need to worry about this, Twitter trims this off, automatically.
MAKE SURE YOU ADD TO "Filter by phrase": unrated;nolink
$puts(_title,$iflonger($put(_title,[%artist% - ]$if2(%title%,$filepart(%filename%))),81,$cut($get(_title),78)...,$get(_title)))
$puts(_album,[from: %album%][ '('%year%')'])
$puts(_link,$if(%comment%,$split($substr(%comment% nolink,$if2($ifgreater($strstr(%comment%,https://),0,$strstr(%comment%,https://),)$ifgreater($strstr(%comment%,http://),0,$strstr(%comment%,http://),),$add($len(%comment%),2)),), ,0),nolink))
$puts(_rating,$if(%rating%,$repeat(★,%rating%)$repeat(☆,$sub(5,%rating%)),unrated))
'♬♫♪ ◖( ˘ ɜ˘ )◗ ♪♫♬'
$get(_title)
$get(_album)
purchase: $get(_link)
my rating: $get(_rating)
A functional, running example: https://twitter.com/patchstep_plays/status/1479237837316923397