Skip to content

Commit

Permalink
chore: make episodes release date optional
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Sep 13, 2021
1 parent 0b2730b commit 0818b60
Show file tree
Hide file tree
Showing 35 changed files with 28 additions and 70 deletions.
4 changes: 0 additions & 4 deletions src/app/crawlers/abstract/base.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Anime } from '../../models/anime';
import { Episode } from '../../models/episode';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { today } from 'src/app/helpers/date.helper';

interface Cache {
animeList: Anime[],
Expand Down Expand Up @@ -44,9 +43,6 @@ export abstract class BaseCrawler {
text :
`${this.baseUrl.replace(/\/$/, '')}/${text?.replace(/^\//, '')}`;
},
today: (text: string) => {
return today();
},
date: (text: string) => {
return new Date(text)?.getTime();
}
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostar/addanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export class AddAnimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostar/anime4up.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class AnimeFourUpCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostar/arabanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class ArabAnimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostar/egyanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export class EgyAnimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostar/okanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export class OkanimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostar/witanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class WitAnimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostar/zimabdko.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export class ZimabdkoCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vosten/4anime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export class FourAnimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vosten/animefrenzy.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class AnimeFrenzyCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '.iep > .iepsbox > a .iepst3 time@datetime | number',
},
this.filters
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vosten/animekisa.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class AnimeKisaCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '.info-box > div > time@time | date',
},
this.filters
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vosten/animixplay.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class AnimixPlayCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: 'a .timetext | date',
},
this.filters
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vosten/darkanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export class DarkAnimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vosten/gogoanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class GogoAnimeCrawler extends LatestEpisodesCrawler {
lang: '.type@class | subtitles',
}
],
//subtitlesLang: '.type@class | subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vosten/gogoanime2.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export class GogoAnimeCrawler extends LatestEpisodesCrawler {
lang: '.type | subtitles',
}
],
//subtitlesLang: '.type | subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vosten/yugenanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class YugenAnimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: 'a.ep-details .ep-statistics time@datetime | date',
},
this.filters
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/animeko.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class AnimeKoCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: ':prev div .untitle | date',
},
this.filters
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/animeresistance.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class AnimeResistanceCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '.published | date',
},
this.filters
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/fullanimevf.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class FullAnimeVFCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: 'time.entry-date@datetime | date',
},
this.filters
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/japmanga.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class JapMangaCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '.grd-post-date | date',
},
this.filters
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/mangas-vostfr.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export class MangasVostfrCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '.post-info .date span | date',
},
this.filters
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostfr/mavanimes.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export class MavAnimesCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/neko-sama.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class NekoSamaCrawler extends LatestEpisodesCrawler {
lang: 'vostfr',
}
],
//subtitlesLang: 'vostfr',
releaseDate: this.filters.date(episode.time),
});
});
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostfr/neko-sama2.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export class NekoSamaCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
//releaseDate: 'span.time | date',
releaseDate: '| today',
},
this.filters
);
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/otakufr.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class OtakuFrCrawler extends LatestEpisodesCrawler {
lang: '.traduction | subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: ':prev div.title | date',
},
this.filters
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostfr/toonanime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export class ToonAnimeCrawler extends LatestEpisodesCrawler {
lang: '.label__rate | subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/voiranime.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class VoirAnimeCrawler extends LatestEpisodesCrawler {
lang: '| subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '.chapter-item:first-child .post-on | date',
},
this.filters
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostfr/voiranimeorg.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class VoirAnimeOrgCrawler extends LatestEpisodesCrawler {
lang: '.item-head > h3 > a | subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
1 change: 0 additions & 1 deletion src/app/crawlers/vostfr/vostfree.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class VostFreeCrawler extends LatestEpisodesCrawler {
lang: '.quality',
}
],
//subtitlesLang: '.quality',
releaseDate: '.info ul.additional li.type:first-child a | date',
},
this.filters
Expand Down
2 changes: 0 additions & 2 deletions src/app/crawlers/vostfr/wacvostfr.crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export class WacVostfrCrawler extends LatestEpisodesCrawler {
lang: ':self | subtitles',
}
],
//subtitlesLang: '| subtitles',
releaseDate: '| today', // since we don't have the release date info. let's just return today's date
},
this.filters
);
Expand Down
10 changes: 7 additions & 3 deletions src/app/helpers/date.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ export const dateBefore = (numberOfDays: number, asString: boolean = false): any

export const isInToday = (inputDate: Date) => {
const today = now();
return today.setHours(0, 0, 0, 0) === inputDate.setHours(0, 0, 0, 0);
return dateOnly(today) === dateOnly(inputDate);
};

export const sameDates = (date1: Date|number|string, date2: Date|number|string) => {
return new Date(date1).setHours(0, 0, 0, 0) === new Date(date2).setHours(0, 0, 0, 0);
export const sameDates = (date1: Date|number|string, date2: Date|number|string, defaultDate?: Date|number|string) => {
const dates = {
date1: date1 ? dateOnly(new Date(date1)) : defaultDate,
date2: date2 ? dateOnly(new Date(date2)) : defaultDate,
};
return dates.date1 === dates.date2;
};
2 changes: 1 addition & 1 deletion src/app/models/episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Episode {
cover?: string;
number: number;
fetchingDate?: EpisodeDate;
releaseDate: EpisodeDate;
releaseDate?: EpisodeDate;
streamLinks: EpisodeLink[];
downloadLinks?: EpisodeLink[];
subtitlesLang?: string;
Expand Down
5 changes: 3 additions & 2 deletions src/app/modules/background/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnimeProviderService } from 'src/app/services/anime-provider.service';
import { take } from 'rxjs/operators';
import { Episode, EpisodeLink } from 'src/app/models/episode';
import { DebugService } from 'src/app/services/debug.service';
import { isInToday, now } from 'src/app/helpers/date.helper';
import { isInToday, now, today } from 'src/app/helpers/date.helper';
import { isSimilar } from 'src/app/helpers/string.helper';
import { Router } from '@angular/router';
import { FavoriteAnimesService } from 'src/app/services/favorite-animes.service';
Expand Down Expand Up @@ -131,10 +131,11 @@ export class MainComponent implements OnInit {
await this.favoriteAnimes.refresh();

episodes.forEach((episode: Episode) => {
const releaseDate: number = episode.releaseDate || today();
// Generate notification messages (for favorite animes episodes only)
if (
!this.isAlreadyChecked(episode) &&
isInToday(new Date(episode.releaseDate)) &&
isInToday(new Date(releaseDate)) &&
!this.viewedEpisodes.isViewed(episode) &&
this.favoriteAnimes.isFavorite(episode.anime.title) &&
this.hasMatchingSubtitles(episode)
Expand Down
10 changes: 4 additions & 6 deletions src/app/modules/popup/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { AnimeProviderService } from 'src/app/services/anime-provider.service';
import { Episode, EpisodeRange } from 'src/app/models/episode';
import { SettingsService } from 'src/app/services/settings.service';
import { dateOnly, sameDates } from 'src/app/helpers/date.helper';
import { dateOnly, sameDates, today } from 'src/app/helpers/date.helper';
import { Subject } from 'rxjs';
import { View } from 'src/app/models/settings';
import { FavoriteAnimesService } from 'src/app/services/favorite-animes.service';
Expand Down Expand Up @@ -104,7 +104,7 @@ export class MainComponent implements OnInit, OnDestroy {
continue; // go to next episode
}
const range: Episode[] = (this.episodes as Episode[]).slice(index).filter((e: Episode) => {
return e.anime.title === episode.anime.title && (!this.settings.displayEpisodesDayByDay || sameDates(e.releaseDate, episode.releaseDate));
return e.anime.title === episode.anime.title && (!this.settings.displayEpisodesDayByDay || sameDates(e.releaseDate, episode.releaseDate, today()));
}).sort((a: Episode, b: Episode) => a.number - b.number);
if (range.length > 1) {
const episodeRange = new EpisodeRange(range, episode.releaseDate);
Expand All @@ -130,10 +130,8 @@ export class MainComponent implements OnInit, OnDestroy {
if (day) {
const dayDate = dateOnly(new Date(day));
this.episodesByDays[day] = this.episodes.filter((episode: Episode|EpisodeRange) => {
if (!episode.releaseDate) {
return false;
}
return dayDate === dateOnly(new Date(episode.releaseDate));
const episodeDate: number = episode.releaseDate ? dateOnly(new Date(episode.releaseDate)) : today();
return dayDate === episodeDate;
});
}
});
Expand Down
22 changes: 13 additions & 9 deletions src/app/services/anime-provider.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Episode, EpisodeSortingCriteria } from '../models/episode';
import { isSimilar } from '../helpers/string.helper';
import { Observable, concat, forkJoin, timer } from 'rxjs';
import { map, concatMap, takeWhile } from 'rxjs/operators';
import { dateOnly, sameDates } from '../helpers/date.helper';
import { dateOnly, sameDates, today } from '../helpers/date.helper';
import { SettingsService } from './settings.service';
import { DebugService } from './debug.service';

Expand Down Expand Up @@ -122,9 +122,15 @@ export class AnimeProviderService {
// sort
if (uniqueEpisodes.length) {
uniqueEpisodes = uniqueEpisodes.sort(
this.settings.sortEpisodesBy === EpisodeSortingCriteria.FetchingDate ?
(a: Episode, b: Episode) => (sameDates(a.releaseDate, b.releaseDate) ? a.fetchingDate - b.fetchingDate : b.releaseDate - a.releaseDate) :
(a: Episode, b: Episode) => b.releaseDate - a.releaseDate
(a: Episode, b: Episode) => {
const releaseDate = {
a: a.releaseDate || today(),
b: b.releaseDate || today(),
};
return this.settings.sortEpisodesBy === EpisodeSortingCriteria.FetchingDate ?
(sameDates(releaseDate.a, releaseDate.b) ? a.fetchingDate - b.fetchingDate : releaseDate.b - releaseDate.a) :
releaseDate.b - releaseDate.a;
}
);
}
return uniqueEpisodes;
Expand All @@ -133,11 +139,9 @@ export class AnimeProviderService {
private getEpisodesDays(episodes: Episode[]): number[] {
let days: number[] = [];
episodes.forEach((episode: Episode) => {
if (episode.releaseDate) {
const day = dateOnly(new Date(episode.releaseDate));
if (days.indexOf(day) === -1) {
days.push(day);
}
const day: number = episode.releaseDate ? dateOnly(new Date(episode.releaseDate)) : today();
if (days.indexOf(day) === -1) {
days.push(day);
}
});
return days;
Expand Down

0 comments on commit 0818b60

Please sign in to comment.