Search in sources :

Example 1 with VideoResult

use of com.dante.data.model.VideoResult in project 91Pop by DanteAndroid.

the class Parse91PronVideo method parseMyFavorite.

/**
 * 解析我的收藏
 *
 * @param html html
 * @return list
 */
public static BaseResult<List<UnLimit91PornItem>> parseMyFavorite(String html) {
    int totalPage = 1;
    List<UnLimit91PornItem> unLimit91PornItemList = new ArrayList<>();
    Document doc = Jsoup.parse(html);
    Element body = doc.getElementById("leftside");
    Elements videos = doc.select("div.myvideo");
    for (Element element : videos) {
        UnLimit91PornItem unLimit91PornItem = new UnLimit91PornItem();
        String contentUrl = element.select("a").first().attr("href");
        String viewKey = contentUrl.substring(contentUrl.indexOf("=") + 1, contentUrl.length());
        unLimit91PornItem.setViewKey(viewKey);
        Logger.t(TAG).d(viewKey);
        String title = element.select("strong").first().text();
        unLimit91PornItem.setTitle(title);
        Logger.t(TAG).d(title);
        String imgUrl = element.select("img").first().attr("src");
        unLimit91PornItem.setImgUrl(imgUrl);
        Logger.t(TAG).d(imgUrl);
        String allInfo = element.text();
        Logger.t(TAG).d(allInfo);
        String duration = allInfo.substring(allInfo.indexOf("时长") + 3, allInfo.indexOf("Views") - 3);
        unLimit91PornItem.setDuration(duration);
        Logger.t(TAG).d(duration);
        String info = allInfo.substring(allInfo.indexOf("添加时间"), allInfo.length());
        unLimit91PornItem.setInfo(info);
        Logger.t(TAG).d(info);
        String rvid = element.select("input").first().attr("value");
        Logger.t(TAG).d("rvid::" + rvid);
        VideoResult videoResult = new VideoResult();
        videoResult.setId(VideoResult.OUT_OF_WATCH_TIMES);
        videoResult.setVideoId(rvid);
        unLimit91PornItem.setVideoResult(videoResult);
        unLimit91PornItemList.add(unLimit91PornItem);
    }
    // 总页数
    Element pagingnav = body.getElementById("paging");
    Elements a = pagingnav.select("a");
    if (a.size() >= 2) {
        String ppp = a.get(a.size() - 2).text();
        if (TextUtils.isDigitsOnly(ppp)) {
            totalPage = Integer.parseInt(ppp);
            Logger.d("总页数:" + totalPage);
        }
    }
    BaseResult<List<UnLimit91PornItem>> baseResult = new BaseResult<>();
    // 尝试解析删除信息
    Elements msgElements = doc.select("div.msgbox");
    if (msgElements != null) {
        String msgInfo = msgElements.text();
        if (!TextUtils.isEmpty(msgInfo)) {
            baseResult.setCode(BaseResult.SUCCESS_CODE);
            baseResult.setMessage(msgInfo);
        }
    } else {
        String errorMsg = parseErrorInfo(html);
        if (!TextUtils.isEmpty(errorMsg)) {
            baseResult.setMessage(errorMsg);
            baseResult.setCode(BaseResult.ERROR_CODE);
        }
    }
    baseResult.setTotalPage(totalPage);
    baseResult.setData(unLimit91PornItemList);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) VideoResult(com.dante.data.model.VideoResult) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem)

Example 2 with VideoResult

use of com.dante.data.model.VideoResult in project 91Pop by DanteAndroid.

the class Parse91PronVideo method parseVideoPlayUrl.

/**
 * 解析视频播放连接
 *
 * @param html 视频页
 * @return 视频连接
 */
public static VideoResult parseVideoPlayUrl(String html) {
    VideoResult videoResult = new VideoResult();
    if (html.contains("你每天只可观看10个视频")) {
        Logger.d("已经超出观看上限了");
        // 设置标志位,用于上传日志
        videoResult.setId(VideoResult.OUT_OF_WATCH_TIMES);
        return videoResult;
    }
    Document doc = Jsoup.parse(html);
    String videoUrl = doc.select("video").first().select("source").first().attr("src");
    videoResult.setVideoUrl(videoUrl);
    Logger.t(TAG).d("视频链接:" + videoUrl);
    int startIndex = videoUrl.lastIndexOf("/");
    int endIndex = videoUrl.indexOf(".mp4");
    String videoId = videoUrl.substring(startIndex + 1, endIndex);
    videoResult.setVideoId(videoId);
    Logger.t(TAG).d("视频Id:" + videoId);
    String ownnerUrl = doc.select("a[href*=UID]").first().attr("href");
    String ownnerId = ownnerUrl.substring(ownnerUrl.indexOf("=") + 1, ownnerUrl.length());
    videoResult.setOwnnerId(ownnerId);
    Logger.t(TAG).d("作者Id:" + ownnerId);
    String ownnerName = doc.select("a[href*=UID]").first().text();
    videoResult.setOwnnerName(ownnerName);
    Logger.t(TAG).d("作者:" + ownnerName);
    String allInfo = doc.getElementById("videodetails-content").text();
    String addDate = allInfo.substring(allInfo.indexOf("添加时间"), allInfo.indexOf("作者"));
    videoResult.setAddDate(addDate);
    Logger.t(TAG).d("添加时间:" + addDate);
    String otherInfo = allInfo.substring(allInfo.indexOf("注册"), allInfo.indexOf("简介"));
    videoResult.setUserOtherInfo(otherInfo);
    Logger.t(TAG).d(otherInfo);
    String thumImg = doc.getElementById("vid").attr("poster");
    videoResult.setThumbImgUrl(thumImg);
    Logger.t(TAG).d("缩略图:" + thumImg);
    String videoName = doc.getElementById("viewvideo-title").text();
    videoResult.setVideoName(videoName);
    Logger.t(TAG).d("视频标题:" + videoName);
    return videoResult;
}
Also used : VideoResult(com.dante.data.model.VideoResult) Document(org.jsoup.nodes.Document)

Example 3 with VideoResult

use of com.dante.data.model.VideoResult in project 91Pop by DanteAndroid.

the class UnLimit91PornItemDao method loadCurrentDeep.

protected UnLimit91PornItem loadCurrentDeep(Cursor cursor, boolean lock) {
    UnLimit91PornItem entity = loadCurrent(cursor, 0, lock);
    int offset = getAllColumns().length;
    VideoResult videoResult = loadCurrentOther(daoSession.getVideoResultDao(), cursor, offset);
    if (videoResult != null) {
        entity.setVideoResult(videoResult);
    }
    return entity;
}
Also used : VideoResult(com.dante.data.model.VideoResult) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem)

Example 4 with VideoResult

use of com.dante.data.model.VideoResult in project 91Pop by DanteAndroid.

the class BasePlayVideo method initData.

private void initData() {
    UnLimit91PornItem tmp = dataManager.findUnLimit91PornItemByViewKey(unLimit91PornItem.getViewKey());
    if (tmp == null || tmp.getVideoResult() == null) {
        presenter.loadVideoUrl(unLimit91PornItem);
    } else {
        unLimit91PornItem = tmp;
        videoplayerContainer.setVisibility(View.VISIBLE);
        Logger.t(TAG).d("使用已有播放地址");
        // 浏览历史
        unLimit91PornItem.setViewHistoryDate(new Date());
        dataManager.updateUnLimit91PornItem(unLimit91PornItem);
        VideoResult videoResult = unLimit91PornItem.getVideoResult();
        setToolBarLayoutInfo(unLimit91PornItem);
        playVideo(unLimit91PornItem.getTitle(), videoResult.getVideoUrl(), videoResult.getVideoName(), videoResult.getThumbImgUrl());
        // 加载评论
        presenter.loadVideoComment(videoResult.getVideoId(), unLimit91PornItem.getViewKey(), true);
    }
}
Also used : VideoResult(com.dante.data.model.VideoResult) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem) Date(java.util.Date)

Example 5 with VideoResult

use of com.dante.data.model.VideoResult in project 91Pop by DanteAndroid.

the class DownloadPresenter method downloadVideo.

@Override
public void downloadVideo(UnLimit91PornItem unLimit91PornItem, boolean isDownloadNeedWifi, boolean isForceReDownload, DownloadListener downloadListener) {
    UnLimit91PornItem tmp = dataManager.findUnLimit91PornItemByViewKey(unLimit91PornItem.getViewKey());
    if (tmp == null || tmp.getVideoResultId() == 0) {
        if (downloadListener != null) {
            downloadListener.onError("还未解析成功视频地址");
        } else {
            ifViewAttached(new ViewAction<DownloadView>() {

                @Override
                public void run(@NonNull DownloadView view) {
                    view.showMessage("还未解析成功视频地址", TastyToast.WARNING);
                }
            });
        }
        return;
    }
    VideoResult videoResult = tmp.getVideoResult();
    // 先检查文件
    File toFile = new File(tmp.getDownLoadPath(dataManager));
    if (toFile.exists() && toFile.length() > 0) {
        if (downloadListener != null) {
            downloadListener.onError("已下载,请查看下载目录");
        } else {
            ifViewAttached(new ViewAction<DownloadView>() {

                @Override
                public void run(@NonNull DownloadView view) {
                    view.showMessage("已下载,请查看下载目录", TastyToast.INFO);
                }
            });
        }
        return;
    }
    // 如果已经缓存完成,直接使用缓存代理完成
    if (proxy.isCached(videoResult.getVideoUrl())) {
        try {
            copyCacheFile(videoCacheDir, tmp, downloadListener);
        } catch (IOException e) {
            if (downloadListener != null) {
                downloadListener.onError("缓存文件错误,无法拷贝");
            } else {
                ifViewAttached(new ViewAction<DownloadView>() {

                    @Override
                    public void run(@NonNull DownloadView view) {
                        view.showMessage("缓存文件错误,无法拷贝", TastyToast.ERROR);
                    }
                });
            }
            e.printStackTrace();
        }
        return;
    }
    // 检查当前状态
    if (tmp.getStatus() == FileDownloadStatus.progress && tmp.getDownloadId() != 0 && !isForceReDownload) {
        if (downloadListener != null) {
            downloadListener.onError("已经在下载了");
        } else {
            ifViewAttached(new ViewAction<DownloadView>() {

                @Override
                public void run(@NonNull DownloadView view) {
                    view.showMessage("已经在下载了", TastyToast.SUCCESS);
                }
            });
        }
        return;
    }
    Logger.d("视频连接:" + videoResult.getVideoUrl());
    String path = unLimit91PornItem.getDownLoadPath(dataManager);
    Logger.d(path);
    int id = DownloadManager.getImpl().startDownload(videoResult.getVideoUrl(), path, isDownloadNeedWifi, isForceReDownload);
    if (tmp.getAddDownloadDate() == null) {
        tmp.setAddDownloadDate(new Date());
    }
    tmp.setDownloadId(id);
    dataManager.updateUnLimit91PornItem(tmp);
    if (downloadListener != null) {
        downloadListener.onSuccess("开始下载");
    } else {
        ifViewAttached(new ViewAction<DownloadView>() {

            @Override
            public void run(@NonNull DownloadView view) {
                view.showMessage("开始下载", TastyToast.SUCCESS);
            }
        });
    }
}
Also used : VideoResult(com.dante.data.model.VideoResult) NonNull(android.support.annotation.NonNull) IOException(java.io.IOException) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem) File(java.io.File) Date(java.util.Date)

Aggregations

VideoResult (com.dante.data.model.VideoResult)10 UnLimit91PornItem (com.dante.data.model.UnLimit91PornItem)4 NonNull (android.support.annotation.NonNull)2 Date (java.util.Date)2 Document (org.jsoup.nodes.Document)2 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 LoadMoreView (com.chad.library.adapter.base.loadmore.LoadMoreView)1 BaseResult (com.dante.data.model.BaseResult)1 FavoriteException (com.dante.exception.FavoriteException)1 MessageException (com.dante.exception.MessageException)1 VideoException (com.dante.exception.VideoException)1 RetryWhenProcess (com.dante.rxjava.RetryWhenProcess)1 AuthorActivity (com.dante.ui.porn91video.author.AuthorActivity)1 Disposable (io.reactivex.disposables.Disposable)1 Function (io.reactivex.functions.Function)1