Skip to content

Commit

Permalink
Use tooltip as date
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedon-dev committed Mar 29, 2024
1 parent ea1b491 commit 80e0187
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/plugins/xhamster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,27 @@ class XHamsterPlugin extends PluginBase {
}
}

// Inside the script element, find the date of the video
List<String> dateStringList = jscript.split('mlRelatedSnapshotId":"');
// Use the tooltip as video upload date
DateTime date = DateTime.utc(1970, 1, 1);
if (dateStringList.length > 2) {
String dateString =
dateStringList[1].substring(0, dateStringList[1].indexOf('_'));

String? dateString = rawHtml
.querySelector(
'div[class="entity-info-container__date tooltip-nocache"]')
?.attributes["data-tooltip"]!;
// 2022-05-06 12:33:41 UTC
if (dateString != null) {
// Convert to a format that DateTime can read
// Convert to 20120227T132700 format
dateString = dateString
.replaceFirst("-", "")
.replaceFirst("-", "")
.replaceFirst("-", "T")
.replaceAll("-", "");
date = DateTime.parse(dateString);
.replaceAll("-", "")
.replaceFirst(" ", "T")
.replaceAll(":", "")
.replaceAll(" UTC", "");
// catch any errors
try {
date = DateTime.parse(dateString);
} on FormatException {
print("COULDNT CONVERT DATE TO DATETIME!!! SETTING TO 1970");
}
} else {
print("COULDNT FIND DATE!!! SETTING TO 1970");
}
Expand Down

0 comments on commit 80e0187

Please sign in to comment.