예제 #1
0
    def get_downloads(self):
        video_lst = []
        if not os.path.isdir(self.downloads_path):
            util.make_path(self.downloads_path)

        downloads = os.listdir(self.downloads_path)
        for download in downloads:
            download_path = os.path.join(self.downloads_path, download)

            if os.path.isdir(download_path):
                continue

            if os.path.splitext(download_path)[1] in VIDEO_EXTENSIONS:
                filename = os.path.basename(os.path.splitext(download_path)[0])
                url = download_path
                subs = None
                if filename in [os.path.splitext(x)[0] for x in downloads if os.path.splitext(x)[1] in SUBTITLES_EXTENSIONS]:
                    subs = filename + ".srt"

                it = PDownload(download_path)
                it.name = filename
                it.url = url
                it.subs = subs

                downloadManager = DownloadManager.getInstance()
                download = downloadManager.findDownloadByIT(it)

                if download is not None:
                    it.finish_time = download.finish_time
                    it.start_time = download.start_time
                    it.state = download.state
                    it.textState = download.textState
                video_lst.append(it)

        return video_lst
예제 #2
0
 def download(self,
              item,
              startCB,
              finishCB,
              playDownload=False,
              mode="",
              overrideCB=None):
     """Downloads item PVideo itemem calls startCB when download starts
        and finishCB when download finishes
     """
     quiet = False
     headers = item.settings['extra-headers']
     log.debug("Download headers %s", headers)
     downloadManager = DownloadManager.getInstance()
     d = downloadManager.createDownload(name=item.name,
                                        url=item.url,
                                        stream=item.stream,
                                        filename=item.filename,
                                        live=item.live,
                                        destination=self.downloads_path,
                                        startCB=startCB,
                                        finishCB=finishCB,
                                        quiet=quiet,
                                        playDownload=playDownload,
                                        headers=headers,
                                        mode=mode)
     if item.subs is not None and item.subs != '':
         log.debug('subtitles link: %s', item.subs)
         subs_file_path = os.path.splitext(d.local)[0] + '.srt'
         util.download_to_file(item.subs, subs_file_path)
     downloadManager.addDownload(d, overrideCB)
예제 #3
0
        def do_download():
            # have to rename to start_cb otherwise python
            # doesnt see start_callback
            start_cb = start_callback
            finish_cb = finish_callback
            if start_cb is None:
                start_cb = DownloadManagerMessages.startDownloadCB
            if finish_cb is None:
                finish_cb = DownloadManagerMessages.finishDownloadCB
            override_cb = DownloadManagerMessages.overrideDownloadCB

            downloadManager = DownloadManager.getInstance()
            d = downloadManager.createDownload(name=item.name,
                                               url=item.url,
                                               stream=item.stream,
                                               filename=item.filename,
                                               live=item.live,
                                               destination=destination[0],
                                               startCB=start_cb,
                                               finishCB=finish_cb,
                                               quiet=False,
                                               playDownload=play_download,
                                               headers=headers,
                                               mode=mode)

            if item.subs:
                remote = item.subs
                local = os.path.splitext(d.local)[0] + '.srt'
                if os.path.isfile(remote):
                    copyfile(remote, local)
                elif remote.startswith('http'):
                    util.download_to_file(remote, local)
            downloadManager.addDownload(d, override_cb)
예제 #4
0
    def get_downloads(self):
        video_lst = []
        if not os.path.isdir(self.downloads_path):
            util.make_path(self.downloads_path)

        downloads = os.listdir(self.downloads_path)
        for download in downloads:
            download_path = os.path.join(self.downloads_path, download)

            if os.path.isdir(download_path):
                continue

            if os.path.splitext(download_path)[1] in VIDEO_EXTENSIONS:
                filename = os.path.basename(os.path.splitext(download_path)[0])
                url = download_path
                subs = None
                if filename in [os.path.splitext(x)[0] for x in downloads if os.path.splitext(x)[1] in SUBTITLES_EXTENSIONS]:
                    subs = filename + ".srt"

                it = PDownload(download_path)
                it.name = filename
                it.url = url
                it.subs = subs

                downloadManager = DownloadManager.getInstance()
                download = downloadManager.findDownloadByIT(it)

                if download is not None:
                    it.finish_time = download.finish_time
                    it.start_time = download.start_time
                    it.state = download.state
                    it.textState = download.textState
                video_lst.append(it)

        return video_lst
예제 #5
0
        def do_download():
            try:
                # have to rename to start_cb otherwise python
                # doesnt see start_callback
                start_cb = start_callback
                finish_cb = finish_callback
                if start_cb is None:
                    start_cb = DownloadManagerMessages.startDownloadCB
                if finish_cb is None:
                    finish_cb = DownloadManagerMessages.finishDownloadCB
                override_cb = DownloadManagerMessages.overrideDownloadCB

                downloadManager = DownloadManager.getInstance()
                d = downloadManager.createDownload(
                    name=item.name, url=item.url, 
                    stream=item.stream, filename=filename[0],
                    live=item.live, destination=destination[0],
                    startCB=start_cb, finishCB=finish_cb, quiet=False,
                    playDownload=play_download, headers=headers, mode=mode)

                if item.subs:
                    remote = item.subs
                    local = os.path.splitext(d.local)[0] + '.srt'
                    if os.path.isfile(remote):
                        copyfile(remote, local)
                    elif remote.startswith('http'):
                        util.download_to_file(remote, local)
                downloadManager.addDownload(d, override_cb)
            except:
                log.logError("Download '%s' failed.\n%s"%(item.name, traceback.format_exc()))
                session.openWithCallback(ask_if_download_callback, MessageBox, text=_("Download error, look into the log file."), timeout=10, type=MessageBox.TYPE_ERROR)
                pass
예제 #6
0
        def do_download():
            try:
                # have to rename to start_cb otherwise python
                # doesnt see start_callback
                start_cb = start_callback
                finish_cb = finish_callback
                if start_cb is None:
                    start_cb = DownloadManagerMessages.startDownloadCB
                if finish_cb is None:
                    finish_cb = DownloadManagerMessages.finishDownloadCB
                override_cb = DownloadManagerMessages.overrideDownloadCB

                downloadManager = DownloadManager.getInstance()
                d = downloadManager.createDownload(
                    name=item.name, url=item.url, 
                    stream=item.stream, filename=filename[0],
                    live=item.live, destination=destination[0],
                    startCB=start_cb, finishCB=finish_cb, quiet=False,
                    playDownload=play_download, headers=headers, mode=mode)

                if item.subs:
                    remote = item.subs
                    local = os.path.splitext(d.local)[0] + '.srt'
                    if os.path.isfile(remote):
                        copyfile(remote, local)
                    elif remote.startswith('http'):
                        util.download_to_file(remote, local)
                downloadManager.addDownload(d, override_cb)
            except:
                log.logError("Download '%s' failed.\n%s"%(item.name, traceback.format_exc()))
                session.openWithCallback(ask_if_download_callback, MessageBox, text=_("Download error, look into the log file."), timeout=10, type=MessageBox.TYPE_ERROR)
                pass
예제 #7
0
 def download(self, item, startCB, finishCB, playDownload=False, mode="", overrideCB=None):
     """Downloads item PVideo itemem calls startCB when download starts
        and finishCB when download finishes
     """
     quiet = False
     headers = item.settings['extra-headers']
     log.debug("Download headers %s", headers)
     downloadManager = DownloadManager.getInstance()
     d = downloadManager.createDownload(name=item.name, url=item.url, stream=item.stream, filename=item.filename,
                                        live=item.live, destination=self.downloads_path,
                                        startCB=startCB, finishCB=finishCB, quiet=quiet,
                                        playDownload=playDownload, headers=headers, mode=mode)
     if item.subs is not None and item.subs != '':
         log.debug('subtitles link: %s' , item.subs)
         subs_file_path = os.path.splitext(d.local)[0] + '.srt'
         util.download_to_file(item.subs, subs_file_path)
     downloadManager.addDownload(d, overrideCB)