1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #
- # This file is part of stov, written by Helmut Pozimski 2012-2015.
- #
- # stov is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, version 2 of the License.
- #
- # stov is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with stov. If not, see <http://www.gnu.org/licenses/>.
- # -*- coding: utf8 -*-
- """This module takes care of managing and downloading single videos."""
- import os
- import logging
- from lib_stov import stov_exceptions
- from lib_stov import youtubedl_wrapper
- LOGGER = logging.getLogger("stov")
- class Video(object):
- """This class stores all the attributes of a single video and is
- also able to download it using youtube-dl.
- """
- def __init__(self, title, site_id, conf, downloaded, failcount=0,
- video_id=0):
- self._id = video_id
- self.title = title
- self.site_id = site_id
- self.__conf = conf
- self.downloaded = downloaded
- self.failcnt = int(failcount)
- def download_video(self, directory, itag_value, url):
- """
- Downloads the video by calling youtube-dl as an external process"
- :param directory: directory to download to
- :type directory: str
- :param itag_value: quality specifier
- :type itag_value: int
- :param video_codec: video codec to download
- :type video_codec: str
- :param url: url to the video
- :type url: str
- :return: boolean value
- :rtype: bool
- """
- targetdir = self.__conf.values["downloaddir"] + "/" + directory
- if not os.access(targetdir, os.F_OK):
- try:
- LOGGER.debug(_("Creating directory %s"), targetdir)
- os.makedirs(targetdir, 0o750)
- except os.error:
- raise stov_exceptions.DirectoryCreationFailedException()
- os.chdir(targetdir)
- if self.downloaded == 0:
- try:
- youtubedl_wrapper.download_video(self.__conf, url,
- itag_value)
- except stov_exceptions.YoutubeDlCallFailed:
- self.failcnt = int(self.failcnt) + 1
- return False
- else:
- self.downloaded = 1
- return True
- def get_id(self):
- """Resturns the id attribute assigned to the object."""
- return self._id
|