# -*- coding: utf8 -*- import os import sys import gettext import sqlite3 class video(object): def __init__(self, title, description, ytid, conf, downloaded, id=0): self.__ID = id self.title = title self.description = description self.ytid = ytid self.__conf = conf self.__downloaded = downloaded def DownloadVideo(self, directory): self.__targetdir = self.__conf.values["downloaddir"] + "/" + directory if os.access(self.__targetdir, os.F_OK) == False: try: os.makedirs(self.__targetdir, 0750) except os.error: print >> sys.stderr, _("Download directory does not exist and can't be created. Please check your configuration and try again") os.chdir(self.__targetdir) if self.__downloaded == 0: if os.system("youtube-dl --max-quality=22 -t %s > /dev/null" %self.ytid) == 0: try: self.__database = sqlite3.connect(self.conf.dbpath) self.__cursor = self.__database.cursor() self.__query = "UPDATE videos SET downloaded ='1' WHERE id = ?" self.__cursor.execute(self.__query, (self.__ID,)) self.__database.commit() self.__database.close() except sqlite3.OperationalError: print >> sys.stderr, _("""The Video \"%s\" has been downloaded but the status could not be updated in the database. Please check what went wrong and correct it""" %self.title) return True else: return False def AssignDBID(self, id): self.__ID = id