Fix video likes and dislikes count. Closes #30

Update version.
This commit is contained in:
Hexah 2020-06-07 22:30:08 +02:00
parent caf26ed17f
commit d174130c6b
5 changed files with 23 additions and 5 deletions

View File

@ -9,6 +9,9 @@
- Update `xml` dependency. - Update `xml` dependency.
- Fixed closed caption api. - Fixed closed caption api.
## 1.0.2-beta
- Fix video likes and dislikes count. #30
<hr> <hr>
## 0.0.1 ## 0.0.1

View File

@ -22,6 +22,10 @@ class Engagement extends Equatable {
return 1 + 4.0 * likeCount / (likeCount + dislikeCount); return 1 + 4.0 * likeCount / (likeCount + dislikeCount);
} }
@override
String toString() =>
'$viewCount views, $likeCount likes, $dislikeCount dislikes';
@override @override
List<Object> get props => [viewCount, likeCount, dislikeCount]; List<Object> get props => [viewCount, likeCount, dislikeCount];
} }

View File

@ -14,7 +14,8 @@ import 'stream_info_provider.dart';
class WatchPage { class WatchPage {
final RegExp _videoLikeExp = RegExp(r'"label"\s*:\s*"([\d,\.]+) likes"'); final RegExp _videoLikeExp = RegExp(r'"label"\s*:\s*"([\d,\.]+) likes"');
final RegExp _videoDislikeExp = RegExp(r'"label"\s*:\s*"([\d,\.]+) dislikes'); final RegExp _videoDislikeExp =
RegExp(r'"label"\s*:\s*"([\d,\.]+) dislikes"');
final Document _root; final Document _root;
@ -26,7 +27,12 @@ class WatchPage {
_root.querySelector('meta[property="og:url"]') != null; _root.querySelector('meta[property="og:url"]') != null;
//TODO: Update this to the new "parsing method" w/ regex "label"\s*:\s*"([\d,\.]+) likes" //TODO: Update this to the new "parsing method" w/ regex "label"\s*:\s*"([\d,\.]+) likes"
int get videoLikeCount => int.parse(_root int get videoLikeCount => int.parse(_videoLikeExp
.firstMatch(_root.outerHtml)
?.group(1)
?.stripNonDigits()
?.nullIfWhitespace ??
_root
.querySelector('.like-button-renderer-like-button') .querySelector('.like-button-renderer-like-button')
?.text ?.text
?.stripNonDigits() ?.stripNonDigits()
@ -34,7 +40,12 @@ class WatchPage {
'0'); '0');
//TODO: Update this to the new "parsing method" w/ regex "label"\s*:\s*"([\d,\.]+) dislikes" //TODO: Update this to the new "parsing method" w/ regex "label"\s*:\s*"([\d,\.]+) dislikes"
int get videoDislikeCount => int.parse(_root int get videoDislikeCount => int.parse(_videoDislikeExp
.firstMatch(_root.outerHtml)
?.group(1)
?.stripNonDigits()
?.nullIfWhitespace ??
_root
.querySelector('.like-button-renderer-dislike-button') .querySelector('.like-button-renderer-dislike-button')
?.text ?.text
?.stripNonDigits() ?.stripNonDigits()

View File

@ -8,7 +8,7 @@ class YoutubeHttpClient {
final Map<String, String> _userAgent = const { final Map<String, String> _userAgent = const {
'user-agent': 'user-agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36' 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}; };
/// Throws if something is wrong with the response. /// Throws if something is wrong with the response.

View File

@ -1,6 +1,6 @@
name: youtube_explode_dart name: youtube_explode_dart
description: A port in dart of the youtube explode library. Supports several API functions without the need of Youtube API Key. description: A port in dart of the youtube explode library. Supports several API functions without the need of Youtube API Key.
version: 1.0.1-beta version: 1.0.2-beta
homepage: https://github.com/Hexer10/youtube_explode_dart homepage: https://github.com/Hexer10/youtube_explode_dart
environment: environment: