# if %variable% or $function ?

**URL:** <https://community.mp3tag.de/t/if-variable-or-function/14715>\
**Category:** Web Sources Discussion\
**Created:** [May 12, 2013, 2:53am UTC](https://community.mp3tag.de/t/if-variable-or-function/14715 "2013-05-12T02:53:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LMahesa](https://community.mp3tag.de/user_avatar/community.mp3tag.de/lmahesa/32/5598_2.png) [@LMahesa](https://community.mp3tag.de/u/LMahesa)\
**Post date:** [May 12, 2013, 2:53am UTC](https://community.mp3tag.de/t/if-variable-or-function/14715/1 "2013-05-12T02:53:46Z")

</div>

I'm writing a source script for TheTVDB. Unfortunately, their API does not allow a search for a specific season. You can search for a show, a specific episode, or all of it.

The docs are a bit unclear on how to use If statements - there is a $if, but not closing $endif for a code block. 'If' is a bit annoying to search for, so I'm sorry if this has been answered already.

Anyway. As with most people, my shows are organized thusly:

```
W:\_TV\Show
+--Season 1
| +--Show S01E01 - Pilot.m4v
| +--Show S01E02 - Title2.m4v
\--Season 2
   +--Show S02E01 - Title1.m4v
   +--Show S02E02 - Title2.m4v

```

As it stands, my source script works fine, but it shows all the episodes ever - as a result, I a) have to manually nudge the files into the appropriate location, and 🕶 cannot set the appropriate COVERURL for the season.

My index SearchBy field looks like this:

```
[SearchBy]=$replace(%_parent_directory%, ,+)+$replace(%_directory%,Season ,)

```

In the album area, I would like to do this :

```
FindLine "<Episode>"
Do
    JoinUntil "</Episode>"
    FindLine "<SeasonNumber>"
    FindInLine "<SeasonNumber>"
    If $replace(%_directory%,Season ,)
        Only do this if the season matches
    endif
While blah

```

Instead of a direct string, that If statement compares the current position with the return value of $Replace. Is that possible at all?

---

<div class="post-metadata">

**Author:** ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)\
**Post date:** [May 12, 2013, 4:47pm UTC](https://community.mp3tag.de/t/if-variable-or-function/14715/2 "2013-05-12T16:47:39Z")

</div>

> [@](#):
>
> Instead of a direct string, that If statement compares the current position with the return value of $Replace. Is that possible at all?

No.

---

<div class="post-metadata">

**Author:** ![LMahesa](https://community.mp3tag.de/user_avatar/community.mp3tag.de/lmahesa/32/5598_2.png) [@LMahesa](https://community.mp3tag.de/u/LMahesa)\
**Post date:** [May 13, 2013, 8:22am UTC](https://community.mp3tag.de/t/if-variable-or-function/14715/3 "2013-05-13T08:22:20Z")

</div>

> [@dano](#):
>
> No.

Okay, thanks. I'd concluded as much after downloading multiple scripts and seeing no such code. Oh well.

---

<div class="post-metadata">

**Author:** ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)\
**Post date:** [May 13, 2013, 6:22pm UTC](https://community.mp3tag.de/t/if-variable-or-function/14715/4 "2013-05-13T18:22:43Z")

</div>

QUOTE (Laga Mahesa @ May 12 2013, 06:53) \<{POST\_SNAPBACK}\>

 FindLine ""

```
 Do
     JoinUntil "</Episode>"
     FindLine "<SeasonNumber>"
     FindInLine "<SeasonNumber>"
     If $replace(%_directory%,Season ,)
         Only do this if the season matches
     endif
 While blah<!--QuoteEnd--></div><!--QuoteEEnd-->

```

A workaround:  
Since $replace(%\_directory%,Season ,) has a limited ouput (numbers from 1 to 30 (i guess), 1 to 10 will do in most cases), you could copy your scirpt when it is finished and do different versions for each season number, like:

TheTVDB#Season &1.src  
TheTVDB#Season &2.src  
TheTVDB#Season &3.src  
...

---

<div class="post-metadata">

**Author:** ![LMahesa](https://community.mp3tag.de/user_avatar/community.mp3tag.de/lmahesa/32/5598_2.png) [@LMahesa](https://community.mp3tag.de/u/LMahesa)\
**Post date:** [May 13, 2013, 8:08pm UTC](https://community.mp3tag.de/t/if-variable-or-function/14715/5 "2013-05-13T20:08:31Z")

</div>

> [@pone](#):
>
> A workaround:  
> Since $replace(%\_directory%,Season ,) has a limited ouput (numbers from 1 to 30 (i guess), 1 to 10 will do in most cases), you could copy your scirpt when it is finished and do different versions for each season number, like:
> 
> TheTVDB#Season &1.src  
> TheTVDB#Season &2.src  
> TheTVDB#Season &3.src  
> ...

Yeah, I'll probably do that, thanks. Right now I'm just leaving it as a single file and fiddling with the delightful 'shift up/down buttons' (delightful because using them with multiple tracks moves them multiple rows) as TheTVDB is a fallback in case iTunes doesn't have the series.
