def _download_files(self, film, filmurl, pathname, filename, extension):
        # make sure the destination directory exists
        if not xbmcvfs.exists(pathname):
            xbmcvfs.mkdir(pathname)
        # prepare resulting filenames
        movname = pathname + filename + extension
        srtname = pathname + filename + u'.srt'
        ttmname = pathname + filename + u'.ttml'

        # download video
        progress = KodiProgressDialog()
        progress.create(self.plugin.language(30974), filename + extension)
        # pylint: disable=broad-except
        try:
            progress.update(0)
            mvutils.url_retrieve_vfs(
                filmurl, movname, progress.url_retrieve_hook)
            progress.close()
            self.notifier.show_notification(
                30960, self.plugin.language(30976).format(filmurl))
        except Exception as err:
            progress.close()
            self.plugin.error('Failure downloading {}: {}', filmurl, err)
            self.notifier.show_error(
                30952, self.plugin.language(30975).format(filmurl, err))
            return False

        # download subtitles
        if self.settings.downloadsrt and film.url_sub:
            self.download_subtitle(film, ttmname, srtname, filename)

        return True
Beispiel #2
0
    def download_subtitle(self, film, ttmname, srtname, filename):
        """
        Downloads and converts a subtitle track of a film
        to SRT format.

        Args:
            film(Film): the film object loaded from the database

            ttmname(str): the filename of the downloaded subtitle
                in original format

            srtname(str): the filename of the downloaded subtitle
                file after conversion to SRT format

            filename(str): a filename stub without extension for
                UI display
        """
        self.logger.debug('download_subtitle')
        ret = False
        if film.url_sub:
            progress = KodiProgressDialog()
            progress.create(30978, filename + u'.ttml')
            # pylint: disable=broad-except
            try:
                progress.update(0)
                mvutils.url_retrieve_vfs(film.url_sub, ttmname,
                                         progress.url_retrieve_hook)
                try:
                    ttml2srtConverter = ttml2srt()
                    ttml2srtConverter.do(xbmcvfs.File(ttmname, 'r'),
                                         xbmcvfs.File(srtname, 'w'))
                    ret = True
                except Exception as err:
                    self.logger.error('Failed to convert to srt: {}', err)
                progress.close()
            except Exception as err:
                progress.close()
                self.logger.error('Failure downloading {}: {}', film.url_sub,
                                  err)
        return ret
 def download_subtitle(self, film, ttmname, srtname, filename):
     ret = False
     if film.url_sub:
         bgd = KodiBGDialog()
         bgd.Create(30978, filename + u'.ttml')
         # pylint: disable=broad-except
         try:
             bgd.Update(0)
             mvutils.url_retrieve_vfs(film.url_sub, ttmname,
                                      bgd.UrlRetrieveHook)
             try:
                 ttml2srt(xbmcvfs.File(ttmname, 'r'),
                          xbmcvfs.File(srtname, 'w'))
                 ret = True
             except Exception as err:
                 self.plugin.info('Failed to convert to srt: {}', err)
             bgd.Close()
         except Exception as err:
             bgd.Close()
             self.plugin.error('Failure downloading {}: {}', film.url_sub,
                               err)
     return ret
Beispiel #4
0
    def doDownloadFilm(self, filmid, quality):
        if self.settings.downloadpath:
            film = self.db.RetrieveFilmInfo(filmid)
            if film is None:
                # film not found - should never happen
                return

            # check if the download path is reachable
            if not xbmcvfs.exists(self.settings.downloadpath):
                self.notifier.ShowError(self.language(30952),
                                        self.language(30979))
                return

            # get the best url
            if quality == '0' and film.url_video_sd:
                videourl = film.url_video_sd
            elif quality == '2' and film.url_video_hd:
                videourl = film.url_video_hd
            else:
                videourl = film.url_video

            # prepare names
            showname = mvutils.cleanup_filename(film.show)[:64]
            filestem = mvutils.cleanup_filename(film.title)[:64]
            extension = os.path.splitext(videourl)[1]
            if not extension:
                extension = u'.mp4'
            if not filestem:
                filestem = u'Film-{}'.format(film.id)
            if not showname:
                showname = filestem

            # prepare download directory and determine episode number
            dirname = self.settings.downloadpath + showname + '/'
            episode = 1
            if xbmcvfs.exists(dirname):
                (
                    _,
                    epfiles,
                ) = xbmcvfs.listdir(dirname)
                for epfile in epfiles:
                    match = re.search('^.* [eE][pP]([0-9]*)\.[^/]*$', epfile)
                    if match and len(match.groups()) > 0:
                        if episode <= int(match.group(1)):
                            episode = int(match.group(1)) + 1
            else:
                xbmcvfs.mkdir(dirname)

            # prepare resulting filenames
            fileepi = filestem + u' - EP%04d' % episode
            movname = dirname + fileepi + extension
            srtname = dirname + fileepi + u'.srt'
            ttmname = dirname + fileepi + u'.ttml'
            nfoname = dirname + fileepi + u'.nfo'

            # download video
            bgd = KodiBGDialog()
            bgd.Create(self.language(30974), fileepi + extension)
            try:
                bgd.Update(0)
                mvutils.url_retrieve_vfs(videourl, movname,
                                         bgd.UrlRetrieveHook)
                bgd.Close()
                self.notifier.ShowNotification(
                    30960,
                    self.language(30976).format(videourl))
            except Exception as err:
                bgd.Close()
                self.error('Failure downloading {}: {}', videourl, err)
                self.notifier.ShowError(
                    30952,
                    self.language(30975).format(videourl, err))

            # download subtitles
            if film.url_sub:
                bgd = KodiBGDialog()
                bgd.Create(30978, fileepi + u'.ttml')
                try:
                    bgd.Update(0)
                    mvutils.url_retrieve_vfs(film.url_sub, ttmname,
                                             bgd.UrlRetrieveHook)
                    try:
                        ttml2srt(xbmcvfs.File(ttmname, 'r'),
                                 xbmcvfs.File(srtname, 'w'))
                    except Exception as err:
                        self.info('Failed to convert to srt: {}', err)
                    bgd.Close()
                except Exception as err:
                    bgd.Close()
                    self.error('Failure downloading {}: {}', film.url_sub, err)

            # create NFO Files
            self._make_nfo_files(film, episode, dirname, nfoname, videourl)
        else:
            self.notifier.ShowError(30952, 30958)
Beispiel #5
0
	def doDownloadFilm( self, filmid, quality ):
		if self.settings.downloadpath:
			film = self.db.RetrieveFilmInfo( filmid )
			if film is None:
				# film not found - should never happen
				return

			# check if the download path is reachable
			if not xbmcvfs.exists( self.settings.downloadpath ):
				self.notifier.ShowError( self.language( 30952 ), self.language( 30979 ) )
				return

			# get the best url
			if quality == '0' and film.url_video_sd:
				videourl = film.url_video_sd
			elif quality == '2' and film.url_video_hd:
				videourl = film.url_video_hd
			else:
				videourl = film.url_video

			# prepare names
			showname	= mvutils.cleanup_filename( film.show )[:64]
			filestem	= mvutils.cleanup_filename( film.title )[:64]
			extension	= os.path.splitext( videourl )[1]
			if not extension:
				extension = u'.mp4'
			if not filestem:
				filestem = u'Film-{}'.format( film.id )
			if not showname:
				showname = filestem

			# prepare download directory and determine episode number
			dirname = self.settings.downloadpath + showname + '/'
			episode = 1
			if xbmcvfs.exists( dirname ):
				( _, epfiles, ) = xbmcvfs.listdir( dirname )
				for epfile in epfiles:
					match = re.search( '^.* [eE][pP]([0-9]*)\.[^/]*$', epfile )
					if match and len( match.groups() ) > 0:
						if episode <= int( match.group(1) ):
							episode = int( match.group(1) ) + 1
			else:
				xbmcvfs.mkdir( dirname )

			# prepare resulting filenames
			fileepi = filestem + u' - EP%04d' % episode
			movname = dirname + fileepi + extension
			srtname = dirname + fileepi + u'.srt'
			ttmname = dirname + fileepi + u'.ttml'
			nfoname = dirname + fileepi + u'.nfo'

			# download video
			bgd = KodiBGDialog()
			bgd.Create( self.language( 30974 ), fileepi + extension )
			try:
				bgd.Update( 0 )
				mvutils.url_retrieve_vfs( videourl, movname, bgd.UrlRetrieveHook )
				bgd.Close()
				self.notifier.ShowNotification( 30960, self.language( 30976 ).format( videourl ) )
			except Exception as err:
				bgd.Close()
				self.error( 'Failure downloading {}: {}', videourl, err )
				self.notifier.ShowError( 30952, self.language( 30975 ).format( videourl, err ) )

			# download subtitles
			if film.url_sub:
				bgd = KodiBGDialog()
				bgd.Create( 30978, fileepi + u'.ttml' )
				try:
					bgd.Update( 0 )
					mvutils.url_retrieve_vfs( film.url_sub, ttmname, bgd.UrlRetrieveHook )
					try:
						ttml2srt( xbmcvfs.File( ttmname, 'r' ), xbmcvfs.File( srtname, 'w' ) )
					except Exception as err:
						self.info( 'Failed to convert to srt: {}', err )
					bgd.Close()
				except Exception as err:
					bgd.Close()
					self.error( 'Failure downloading {}: {}', film.url_sub, err )

			# create NFO Files
			self._make_nfo_files( film, episode, dirname, nfoname, videourl )
		else:
			self.notifier.ShowError( 30952, 30958 )