dateUpload for AniWorld & SerienStream #116

Merged
NBA2K1 merged 6 commits from main into main 2024-12-15 18:09:37 +00:00
NBA2K1 commented 2024-12-13 02:02:51 +00:00 (Migrated from github.com)
No description provided.
kodjodevf commented 2024-12-13 17:15:33 +00:00 (Migrated from github.com)

Use this code instead :

async getUploadDateFromEpisode(url) {
     const baseUrl = this.source.baseUrl;
     const res = await this.client.get(baseUrl + url);
     const document = new Document(res.body);
     const dateString = document.selectFirst('strong[style="color: white;"]').text;
     const dateTimePart = dateString.split(", ")[1];
     const [date, time] = dateTimePart.split(" ");
     const [day, month, year] = date.split(".");
     const formattedDate = `${year}-${month}-${day.padStart(2, "0")}`;
     return String(new Date(formattedDate).valueOf());
 }
Use this code instead : ``` async getUploadDateFromEpisode(url) { const baseUrl = this.source.baseUrl; const res = await this.client.get(baseUrl + url); const document = new Document(res.body); const dateString = document.selectFirst('strong[style="color: white;"]').text; const dateTimePart = dateString.split(", ")[1]; const [date, time] = dateTimePart.split(" "); const [day, month, year] = date.split("."); const formattedDate = `${year}-${month}-${day.padStart(2, "0")}`; return String(new Date(formattedDate).valueOf()); } ```
NBA2K1 commented 2024-12-14 00:30:39 +00:00 (Migrated from github.com)

Use this code instead :

async getUploadDateFromEpisode(url) {
     const baseUrl = this.source.baseUrl;
     const res = await this.client.get(baseUrl + url);
     const document = new Document(res.body);
     const dateString = document.selectFirst('strong[style="color: white;"]').text;
     const dateTimePart = dateString.split(", ")[1];
     const [date, time] = dateTimePart.split(" ");
     const [day, month, year] = date.split(".");
     const formattedDate = `${year}-${month}-${day.padStart(2, "0")}`;
     return String(new Date(formattedDate).valueOf());
 }

But your code doesn't make use of the time, and doesn't take the Daylight Saving Times into account. That's why I wanted to use Intl, and since it isn't implemented I made my own small function getLastSundayOfMonth to determine whether the time was in MESZ (CEST) or MEZ (CET).
BTW the dateString would look like this: "Sonntag, 08.09.2024 16:40", so there is no need to use padStart.

> Use this code instead : > > ``` > async getUploadDateFromEpisode(url) { > const baseUrl = this.source.baseUrl; > const res = await this.client.get(baseUrl + url); > const document = new Document(res.body); > const dateString = document.selectFirst('strong[style="color: white;"]').text; > const dateTimePart = dateString.split(", ")[1]; > const [date, time] = dateTimePart.split(" "); > const [day, month, year] = date.split("."); > const formattedDate = `${year}-${month}-${day.padStart(2, "0")}`; > return String(new Date(formattedDate).valueOf()); > } > ``` But your code doesn't make use of the time, and doesn't take the Daylight Saving Times into account. That's why I wanted to use Intl, and since it isn't implemented I made my own small function getLastSundayOfMonth to determine whether the time was in MESZ (CEST) or MEZ (CET). BTW the dateString would look like this: "Sonntag, 08.09.2024 16:40", so there is no need to use padStart.
kodjodevf commented 2024-12-14 05:30:59 +00:00 (Migrated from github.com)

It's because it doesn't seem to return the right values

It's because it doesn't seem to return the right values
NBA2K1 commented 2024-12-14 09:50:40 +00:00 (Migrated from github.com)

I tried it on https://aniworld.to/anime/stream/attack-on-titan
and on
https://aniworld.to/anime/stream/dan-da-dan and got the correct values.
Where did you get wrong values?

I tried it on https://aniworld.to/anime/stream/attack-on-titan and on https://aniworld.to/anime/stream/dan-da-dan and got the correct values. Where did you get wrong values?
NBA2K1 commented 2024-12-14 22:09:20 +00:00 (Migrated from github.com)

Huh strange, I've only tested it in the code-editor and it worked there perfectly:

grafik

Now I tried it on the normal anime view and it doesn't work, like you said:

grafik

How come?

Huh strange, I've only tested it in the code-editor and it worked there perfectly: ![grafik](https://github.com/user-attachments/assets/f90a41ba-87cb-4a47-b6b5-ac11ddcd2ef3) Now I tried it on the normal anime view and it doesn't work, like you said: ![grafik](https://github.com/user-attachments/assets/26c13976-7288-4136-843e-bf6594274d04) How come?
kodjodevf commented 2024-12-15 15:10:36 +00:00 (Migrated from github.com)

Fixed, use it like this :

async getUploadDateFromEpisode(url) {
       const baseUrl = this.source.baseUrl;
       const res = await this.client.get(baseUrl + url);
       const getLastSundayOfMonth = (year, month) => {
           const lastDay = new Date(year, month, 0);
           const lastSunday = lastDay.getDate() - lastDay.getDay();
           return new Date(year, month - 1, lastSunday);
       };
       const document = new Document(res.body);
       const dateString = document.selectFirst('strong[style="color: white;"]').text;
       const dateTimePart = dateString.split(", ")[1];
       const [date, time] = dateTimePart.split(" ");
       const [day, month, year] = date.split(".");
       const [hours, minutes] = time.split(":");
       const dayInt = parseInt(day);
       const monthInt = parseInt(month);
       const yearInt = parseInt(year);
       const hoursInt = parseInt(hours);
       const minutesInt = parseInt(minutes);
       const lastSundayOfMarch = getLastSundayOfMonth(yearInt, 3);
       const lastSundayOfOctober = getLastSundayOfMonth(yearInt, 10);
       const jsDate = new Date(yearInt, monthInt - 1, dayInt, hoursInt, minutesInt);
       // If Date between lastSundayOfMarch & lastSundayOfOctober -> CEST (MESZ)
       const isInDST = jsDate >= lastSundayOfMarch && jsDate < lastSundayOfOctober;
       let timeZoneOffset = isInDST ? 0 : 1;
       // If it's in CEST, subtract 1 hour from UTC (to get local time in CEST)
       const correctedTime = new Date(jsDate.getTime() + (timeZoneOffset - 1) * 60 * 60 * 1000);
       return String(correctedTime.valueOf());
   }
Fixed, use it like this : ``` async getUploadDateFromEpisode(url) { const baseUrl = this.source.baseUrl; const res = await this.client.get(baseUrl + url); const getLastSundayOfMonth = (year, month) => { const lastDay = new Date(year, month, 0); const lastSunday = lastDay.getDate() - lastDay.getDay(); return new Date(year, month - 1, lastSunday); }; const document = new Document(res.body); const dateString = document.selectFirst('strong[style="color: white;"]').text; const dateTimePart = dateString.split(", ")[1]; const [date, time] = dateTimePart.split(" "); const [day, month, year] = date.split("."); const [hours, minutes] = time.split(":"); const dayInt = parseInt(day); const monthInt = parseInt(month); const yearInt = parseInt(year); const hoursInt = parseInt(hours); const minutesInt = parseInt(minutes); const lastSundayOfMarch = getLastSundayOfMonth(yearInt, 3); const lastSundayOfOctober = getLastSundayOfMonth(yearInt, 10); const jsDate = new Date(yearInt, monthInt - 1, dayInt, hoursInt, minutesInt); // If Date between lastSundayOfMarch & lastSundayOfOctober -> CEST (MESZ) const isInDST = jsDate >= lastSundayOfMarch && jsDate < lastSundayOfOctober; let timeZoneOffset = isInDST ? 0 : 1; // If it's in CEST, subtract 1 hour from UTC (to get local time in CEST) const correctedTime = new Date(jsDate.getTime() + (timeZoneOffset - 1) * 60 * 60 * 1000); return String(correctedTime.valueOf()); } ```
NBA2K1 commented 2024-12-15 17:53:48 +00:00 (Migrated from github.com)

Oh I feel dumb. I literally put it into my comment, that it's in milliseconds. But I converted it into seconds, since the Unix timestamp uses seconds. I have only paid attention to the "dateUpload is a string" part of the comment, hahaha.

Oh I feel dumb. I literally put it into my comment, that it's in milliseconds. But I converted it into seconds, since the Unix timestamp uses seconds. I have only paid attention to the "dateUpload is a string" part of the comment, hahaha.
kodjodevf commented 2024-12-15 18:05:22 +00:00 (Migrated from github.com)

Also don't forget to increment version number

Also don't forget to increment version number
kodjodevf commented 2024-12-15 18:09:33 +00:00 (Migrated from github.com)

Thanks

Thanks
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Creepso/mangayomi-extensions#116
No description provided.