Fix for season 0

This commit is contained in:
zvon 2019-02-07 19:36:36 +01:00
parent 3ff6557f83
commit 3ee1937af5

View File

@ -117,6 +117,11 @@ string encodeUrl( const string &url ) {
bool searchSpecificSeason( const char_t *const path, size_t &ep_pos,
const string &number ) {
size_t cur_pos{};
#ifdef _WIN32
auto ncompare = wcsncmp;
#else
auto ncompare = strncmp;
#endif
// search for S[0-9]+E[0-9]+
while ( path[cur_pos] != '\0' ) {
if ( ( path[cur_pos] == 's' || path[cur_pos] == 'S' ) &&
@ -124,19 +129,18 @@ bool searchSpecificSeason( const char_t *const path, size_t &ep_pos,
cur_pos++;
while ( path[cur_pos] == '0' )
cur_pos++;
// if season number is 0, move back because previous while skipped it
if( number == TEXT("0") )
cur_pos--;
// make sure season's number is the same as provided in argument
// `number`
#ifdef _WIN32
if ( wcsncmp( path + cur_pos, number.c_str(), number.size() ) )
#else
if ( strncmp( path + cur_pos, number.c_str(), number.size() ) )
#endif
continue;
cur_pos += number.size();
if ( ( path[cur_pos] == 'e' || path[cur_pos] == 'E' ) &&
iswdigit( path[cur_pos + 1] ) ) {
ep_pos = cur_pos + 1;
return true;
if ( !ncompare( path + cur_pos, number.c_str(), number.size() ) ) {
cur_pos += number.size();
if ( ( path[cur_pos] == 'e' || path[cur_pos] == 'E' ) &&
iswdigit( path[cur_pos + 1] ) ) {
ep_pos = cur_pos + 1;
return true;
}
}
}
cur_pos++;