diff --git a/utilities/database_upgrader.py b/utilities/database_upgrader.py index 741fa58..0ca3b59 100644 --- a/utilities/database_upgrader.py +++ b/utilities/database_upgrader.py @@ -115,6 +115,34 @@ def upgrade_4_to_5(ycdldb): [uploads_playlist, channel] ) +def upgrade_5_to_6(ycdldb): + ''' + In this version, the `directory` column of the channels table was renamed + to `download_directory` to be in line with the default config's name for + the same value, and the `queuefile_extension` column was added. + ''' + ycdldb.sql.execute('ALTER TABLE channels RENAME TO channels_old') + ycdldb.sql.execute(''' + CREATE TABLE channels( + id TEXT, + name TEXT, + uploads_playlist TEXT, + download_directory TEXT COLLATE NOCASE, + queuefile_extension TEXT COLLATE NOCASE, + automark TEXT + ) + ''') + ycdldb.sql.execute(''' + INSERT INTO channels SELECT + id, + name, + uploads_playlist, + directory, + NULL, + automark + FROM channels_old + ''') + ycdldb.sql.execute('DROP TABLE channels_old') def upgrade_all(data_directory): ''' diff --git a/ycdl/constants.py b/ycdl/constants.py index 6f566db..b652443 100644 --- a/ycdl/constants.py +++ b/ycdl/constants.py @@ -1,6 +1,6 @@ from voussoirkit import sqlhelpers -DATABASE_VERSION = 5 +DATABASE_VERSION = 6 DB_VERSION_PRAGMA = f''' PRAGMA user_version = {DATABASE_VERSION}; ''' @@ -19,7 +19,8 @@ CREATE TABLE IF NOT EXISTS channels( id TEXT, name TEXT, uploads_playlist TEXT, - directory TEXT COLLATE NOCASE, + download_directory TEXT COLLATE NOCASE, + queuefile_extension TEXT COLLATE NOCASE, automark TEXT ); CREATE TABLE IF NOT EXISTS videos( diff --git a/ycdl/objects.py b/ycdl/objects.py index 2c225d2..49c2855 100644 --- a/ycdl/objects.py +++ b/ycdl/objects.py @@ -21,7 +21,8 @@ class Channel(Base): self.id = db_row['id'] self.name = db_row['name'] self.uploads_playlist = db_row['uploads_playlist'] - self.directory = db_row['directory'] + self.download_directory = db_row['download_directory'] + self.queuefile_extension = db_row['queuefile_extension'] self.automark = db_row['automark'] or "pending" def delete(self, commit=True): diff --git a/ycdl/ycdldb.py b/ycdl/ycdldb.py index 36a8511..5d8e691 100644 --- a/ycdl/ycdldb.py +++ b/ycdl/ycdldb.py @@ -109,6 +109,7 @@ class YCDLDBChannelMixin: *, commit=True, download_directory=None, + queuefile_extension=None, get_videos=False, name=None, ): @@ -127,7 +128,8 @@ class YCDLDBChannelMixin: 'id': channel_id, 'name': name, 'uploads_playlist': self.youtube.get_user_uploads_playlist_id(channel_id), - 'directory': download_directory, + 'download_directory': download_directory, + 'queuefile_extension': queuefile_extension, 'automark': "pending", } self.sql_insert(table='channels', data=data) @@ -254,15 +256,14 @@ class YCDLDBVideoMixin: try: channel = self.get_channel(video.author_id) - download_directory = channel.directory - download_directory = download_directory or self.config['download_directory'] + download_directory = channel.download_directory or self.config['download_directory'] except exceptions.NoSuchChannel: download_directory = self.config['download_directory'] download_directory = pathclass.Path(download_directory) os.makedirs(download_directory.absolute_path, exist_ok=True) - extension = self.config['queuefile_extension'] + extension = channel.queuefile_extension or self.config['queuefile_extension'] queuefile = download_directory.with_child(video_id).replace_extension(extension) open(queuefile.absolute_path, 'a').close()