123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- import 'package:video/model/videoDetail.dart';
- import 'request.dart';
- class RegularDetail {
- static getHttpDetail(String url) async {
- var responseBody = await Request.getByHttpHtml(url);
- VideoDetail recommends = getRecommend(responseBody);
- return recommends;
- }
- static VideoDetail getRecommend(String responseBody) {
- RegExp regHeader =
- new RegExp(r'class="vodBox">[\s\S]*?</div>[\s\S]*?</div>');
- RegExp regInfo = new RegExp(r'class="vodinfobox">[\s\S]*?</div>');
- RegExp regPlayInfo = new RegExp(r'id="play_1">[\s\S]*?</div>');
- RegExp regDownloadInfo = new RegExp(r'id="down_1">[\s\S]*?</div>');
- Iterable<Match> matchesHeader = regHeader.allMatches(responseBody);
- Iterable<Match> matchesInfo = regInfo.allMatches(responseBody);
- Iterable<Match> matchesPlayInfo = regPlayInfo.allMatches(responseBody);
- Iterable<Match> matchesDownloadInfo =
- regDownloadInfo.allMatches(responseBody);
- VideoDetail listHeader = new VideoDetail();
- VideoDetail listInfo = new VideoDetail();
- VideoDetail listPlayInfo = new VideoDetail();
- VideoDetail listDownloadinfo = new VideoDetail();
- listPlayInfo.videoUrl = [];
- VideoDetail videoDetail;
- for (Match m in matchesHeader) {
- //groupCount返回正则表达式的分组数
- //由于group(0)保存了匹配信息,因此字符串的总长度为:分组数+1
- String match = m.group(0);
- //在此匹配
- listHeader = getHeaderItems(match);
- }
- for (Match m in matchesInfo) {
- String match = m.group(0);
- //在此匹配
- listInfo = getInfoItems(match);
- }
- for (Match m in matchesPlayInfo) {
- String match = m.group(0);
- //在此匹配
- listPlayInfo.videoUrl = getPlayInfoItems(match);
- }
- for (Match m in matchesDownloadInfo) {
- String match = m.group(0);
- listDownloadinfo.downloadUrl = getDownloadItems(match);
- }
- videoDetail = new VideoDetail(
- title: listHeader.title,
- imageUrl: listHeader.imageUrl,
- score: listHeader.score,
- starring: listInfo.starring,
- releaseTime: listInfo.releaseTime,
- description: listInfo.description,
- videoUrl: listPlayInfo.videoUrl,
- downloadUrl: listDownloadinfo.downloadUrl,
- );
- return videoDetail;
- }
- static VideoDetail getHeaderItems(String match) {
- RegExp reg = new RegExp(
- r'class="vodBox">[\s\S]*?src="(.*?)"[\s\S]*?h2>(.*?)</h2>[\s\S]*?<label>(.*?)</label>[\s\S]*?</div>');
- Iterable<Match> matches = reg.allMatches(match);
- String url = "";
- String title = "";
- String score = "";
- VideoDetail video;
- for (Match m in matches) {
- //groupCount返回正则表达式的分组数
- //由于group(0)保存了匹配信息,因此字符串的总长度为:分组数+1
- for (int i = 0; i < m.groupCount + 1; i++) {
- String match = m.group(i);
- switch (i) {
- case 1:
- url = match;
- break;
- case 2:
- title = match;
- break;
- case 3:
- score = match;
- break;
- }
- }
- }
- video = new VideoDetail(
- imageUrl: url,
- title: title,
- score: score,
- );
- return video;
- }
- static VideoDetail getInfoItems(String match) {
- RegExp reg = new RegExp(r'li[\s\S]*?>(.*?)<span>(.*?)</span>[\s\S]*?</li>');
- Iterable<Match> matches = reg.allMatches(match);
- String starring = "";
- String releaseTime = "";
- String str = "";
- String description = "";
- VideoDetail video;
- for (Match m in matches) {
- //groupCount返回正则表达式的分组数
- //由于group(0)保存了匹配信息,因此字符串的总长度为:分组数+1
- for (int i = 0; i < m.groupCount + 1; i++) {
- String match = m.group(i);
- switch (i) {
- case 1:
- str = match;
- break;
- case 2:
- str += match;
- break;
- }
- }
- if (str.contains("主演")) {
- starring = str;
- } else if (str.contains("上映")) {
- releaseTime = str;
- }
- }
- RegExp regDescription =
- new RegExp(r'class="more" txt="(.*?)"[\s\S]*?>[\s\S]*?</span>');
- Iterable<Match> matcheDescription = regDescription.allMatches(match);
- for (Match m in matcheDescription) {
- description = m.group(1);
- }
- video = new VideoDetail(
- starring: starring,
- releaseTime: releaseTime,
- description: description,
- );
- return video;
- }
- static List<String> getPlayInfoItems(String match) {
- RegExp reg = new RegExp(r'value="(.*?)"[\s\S]*?checked="" />');
- Iterable<Match> matches = reg.allMatches(match);
- List<String> videoUrl = [];
- for (Match m in matches) {
- //groupCount返回正则表达式的分组数
- //由于group(0)保存了匹配信息,因此字符串的总长度为:分组数+1
- if (m.group(1).contains("http")) {
- videoUrl.add(m.group(1));
- }
- }
- return videoUrl;
- }
- static List<String> getDownloadItems(String match) {
- RegExp reg = new RegExp(r'value="(.*?)"[\s\S]*?checked="" />');
- Iterable<Match> matches = reg.allMatches(match);
- List<String> videoUrl = [];
- for (Match m in matches) {
- //groupCount返回正则表达式的分组数
- //由于group(0)保存了匹配信息,因此字符串的总长度为:分组数+1
- if (m.group(1).contains("http")) {
- videoUrl.add(m.group(1));
- }
- }
- return videoUrl;
- }
- }
|