Search in sources :

Example 16 with UnLimit91PornItem

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

the class Parse91PronVideo method parseAuthorVideos.

/**
 * 解析作者更多视频
 *
 * @param html html
 * @return list
 */
public static BaseResult<List<UnLimit91PornItem>> parseAuthorVideos(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("查看") - 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);
        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<>();
    baseResult.setTotalPage(totalPage);
    baseResult.setData(unLimit91PornItemList);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) 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 17 with UnLimit91PornItem

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

the class Parse91PronVideo method parseHot.

/**
 * 解析其他类别
 *
 * @param html 类别
 * @return 列表
 */
public static BaseResult<List<UnLimit91PornItem>> parseHot(String html) {
    int totalPage = 1;
    List<UnLimit91PornItem> unLimit91PornItemList = new ArrayList<>();
    Document doc = Jsoup.parse(html);
    Element body = doc.getElementById("fullside");
    Elements listchannel = body.getElementsByClass("listchannel");
    for (Element element : listchannel) {
        UnLimit91PornItem unLimit91PornItem = new UnLimit91PornItem();
        String contentUrl = element.select("a").first().attr("href");
        // Logger.d(contentUrl);
        contentUrl = contentUrl.substring(0, contentUrl.indexOf("&"));
        // Logger.d(contentUrl);
        String viewKey = contentUrl.substring(contentUrl.indexOf("=") + 1);
        unLimit91PornItem.setViewKey(viewKey);
        String imgUrl = element.select("a").first().select("img").first().attr("src");
        // Logger.d(imgUrl);
        unLimit91PornItem.setImgUrl(imgUrl);
        String title = element.select("a").first().select("img").first().attr("title");
        // Logger.d(title);
        unLimit91PornItem.setTitle(title);
        String allInfo = element.text();
        int sindex = allInfo.indexOf("时长");
        String duration = allInfo.substring(sindex + 3, sindex + 8);
        unLimit91PornItem.setDuration(duration);
        int start = allInfo.indexOf("添加时间");
        String info = allInfo.substring(start);
        unLimit91PornItem.setInfo(info.replace("还未被评分", ""));
        // Logger.d(info);
        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<>();
    baseResult.setTotalPage(totalPage);
    baseResult.setData(unLimit91PornItemList);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) 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 18 with UnLimit91PornItem

use of com.dante.data.model.UnLimit91PornItem 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)

Example 19 with UnLimit91PornItem

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

the class DownloadPresenter method copyCacheFile.

/**
 * 直接拷贝缓存好的视频即可
 *
 * @param unLimit91PornItem
 */
private void copyCacheFile(final File videoCacheDir, final UnLimit91PornItem unLimit91PornItem, final DownloadListener downloadListener) throws IOException {
    Observable.create(new ObservableOnSubscribe<File>() {

        @Override
        public void subscribe(ObservableEmitter<File> e) throws Exception {
            VideoCacheFileNameGenerator myFileNameGenerator = new VideoCacheFileNameGenerator();
            String cacheFileName = myFileNameGenerator.generate(unLimit91PornItem.getVideoResult().getVideoUrl());
            File fromFile = new File(videoCacheDir, cacheFileName);
            if (!fromFile.exists() || fromFile.length() <= 0) {
                e.onError(new Exception("缓存文件错误,无法拷贝"));
            }
            e.onNext(fromFile);
            e.onComplete();
        }
    }).map(new Function<File, UnLimit91PornItem>() {

        @Override
        public UnLimit91PornItem apply(File fromFile) throws Exception {
            File toFile = new File(unLimit91PornItem.getDownLoadPath(dataManager));
            if (toFile.exists() && toFile.length() > 0) {
                throw new Exception("已经下载过了");
            } else {
                if (!toFile.createNewFile()) {
                    throw new Exception("创建文件失败");
                }
            }
            FileUtils.copyFile(fromFile, toFile);
            unLimit91PornItem.setTotalFarBytes((int) fromFile.length());
            unLimit91PornItem.setSoFarBytes((int) fromFile.length());
            return unLimit91PornItem;
        }
    }).map(new Function<UnLimit91PornItem, String>() {

        @Override
        public String apply(UnLimit91PornItem unLimit91PornItem) throws Exception {
            unLimit91PornItem.setStatus(FileDownloadStatus.completed);
            unLimit91PornItem.setProgress(100);
            unLimit91PornItem.setFinishedDownloadDate(new Date());
            unLimit91PornItem.setDownloadId(FileDownloadUtils.generateId(unLimit91PornItem.getVideoResult().getVideoUrl(), unLimit91PornItem.getDownLoadPath(dataManager)));
            dataManager.updateUnLimit91PornItem(unLimit91PornItem);
            return "下载完成";
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).compose(provider.<String>bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new CallBackWrapper<String>() {

        @Override
        public void onBegin(Disposable d) {
        }

        @Override
        public void onSuccess(final String s) {
            if (downloadListener != null) {
                downloadListener.onSuccess(s);
            } else {
                ifViewAttached(new ViewAction<DownloadView>() {

                    @Override
                    public void run(@NonNull DownloadView view) {
                        view.showMessage(s, TastyToast.SUCCESS);
                    }
                });
            }
        }

        @Override
        public void onError(final String msg, int code) {
            if (downloadListener != null) {
                downloadListener.onError(msg);
            } else {
                ifViewAttached(new ViewAction<DownloadView>() {

                    @Override
                    public void run(@NonNull DownloadView view) {
                        view.showMessage(msg, TastyToast.ERROR);
                    }
                });
            }
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) VideoCacheFileNameGenerator(com.dante.utils.VideoCacheFileNameGenerator) IOException(java.io.IOException) Date(java.util.Date) Function(io.reactivex.functions.Function) NonNull(android.support.annotation.NonNull) File(java.io.File) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem)

Example 20 with UnLimit91PornItem

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

the class FinishedFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    unbinder = ButterKnife.bind(this, view);
    List<UnLimit91PornItem> mUnLimit91PornItemList = new ArrayList<>();
    mDownloadAdapter = new DownloadVideoAdapter(R.layout.item_unlimit_91porn_download, mUnLimit91PornItemList);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(mDownloadAdapter);
    mDownloadAdapter.setEmptyView(R.layout.empty_view, recyclerView);
    mDownloadAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
            UnLimit91PornItem unLimit91PornItem = (UnLimit91PornItem) adapter.getItem(position);
            openMp4File(unLimit91PornItem);
        }
    });
    mDownloadAdapter.setOnItemLongClickListener(new BaseQuickAdapter.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
            final UnLimit91PornItem unLimit91PornItem = (UnLimit91PornItem) adapter.getItem(position);
            if (unLimit91PornItem == null)
                return false;
            new AlertDialog.Builder(context).setMessage("刪除此任务?").setPositiveButton("好的", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    File file = new File(unLimit91PornItem.getDownLoadPath(dataManager));
                    if (file.exists()) {
                        showDeleteFileDialog(unLimit91PornItem);
                    } else {
                        presenter.deleteDownloadedTask(unLimit91PornItem, false);
                        presenter.loadFinishedData();
                    }
                }
            }).show();
            return true;
        }
    });
    presenter.loadFinishedData();
}
Also used : DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem) DownloadVideoAdapter(com.dante.adapter.DownloadVideoAdapter) File(java.io.File)

Aggregations

UnLimit91PornItem (com.dante.data.model.UnLimit91PornItem)29 BaseResult (com.dante.data.model.BaseResult)10 ArrayList (java.util.ArrayList)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)8 View (android.view.View)8 BindView (butterknife.BindView)8 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)8 List (java.util.List)7 RecyclerView (android.support.v7.widget.RecyclerView)6 MessageException (com.dante.exception.MessageException)6 NonNull (android.support.annotation.NonNull)5 OnLoadViewListener (com.helper.loadviewhelper.help.OnLoadViewListener)5 LoadViewHelper (com.helper.loadviewhelper.load.LoadViewHelper)5 Function (io.reactivex.functions.Function)5 Document (org.jsoup.nodes.Document)5 Element (org.jsoup.nodes.Element)5 Elements (org.jsoup.select.Elements)5 VideoResult (com.dante.data.model.VideoResult)4 FavoriteException (com.dante.exception.FavoriteException)4 Disposable (io.reactivex.disposables.Disposable)4