Rename directory -> download_directory; add queuefile_extension.

This commit is contained in:
voussoir 2020-08-10 05:46:18 -07:00
parent 213278edcc
commit 59eab3f997
4 changed files with 38 additions and 7 deletions

View file

@ -115,6 +115,34 @@ def upgrade_4_to_5(ycdldb):
[uploads_playlist, channel] [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): def upgrade_all(data_directory):
''' '''

View file

@ -1,6 +1,6 @@
from voussoirkit import sqlhelpers from voussoirkit import sqlhelpers
DATABASE_VERSION = 5 DATABASE_VERSION = 6
DB_VERSION_PRAGMA = f''' DB_VERSION_PRAGMA = f'''
PRAGMA user_version = {DATABASE_VERSION}; PRAGMA user_version = {DATABASE_VERSION};
''' '''
@ -19,7 +19,8 @@ CREATE TABLE IF NOT EXISTS channels(
id TEXT, id TEXT,
name TEXT, name TEXT,
uploads_playlist TEXT, uploads_playlist TEXT,
directory TEXT COLLATE NOCASE, download_directory TEXT COLLATE NOCASE,
queuefile_extension TEXT COLLATE NOCASE,
automark TEXT automark TEXT
); );
CREATE TABLE IF NOT EXISTS videos( CREATE TABLE IF NOT EXISTS videos(

View file

@ -21,7 +21,8 @@ class Channel(Base):
self.id = db_row['id'] self.id = db_row['id']
self.name = db_row['name'] self.name = db_row['name']
self.uploads_playlist = db_row['uploads_playlist'] 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" self.automark = db_row['automark'] or "pending"
def delete(self, commit=True): def delete(self, commit=True):

View file

@ -109,6 +109,7 @@ class YCDLDBChannelMixin:
*, *,
commit=True, commit=True,
download_directory=None, download_directory=None,
queuefile_extension=None,
get_videos=False, get_videos=False,
name=None, name=None,
): ):
@ -127,7 +128,8 @@ class YCDLDBChannelMixin:
'id': channel_id, 'id': channel_id,
'name': name, 'name': name,
'uploads_playlist': self.youtube.get_user_uploads_playlist_id(channel_id), 'uploads_playlist': self.youtube.get_user_uploads_playlist_id(channel_id),
'directory': download_directory, 'download_directory': download_directory,
'queuefile_extension': queuefile_extension,
'automark': "pending", 'automark': "pending",
} }
self.sql_insert(table='channels', data=data) self.sql_insert(table='channels', data=data)
@ -254,15 +256,14 @@ class YCDLDBVideoMixin:
try: try:
channel = self.get_channel(video.author_id) channel = self.get_channel(video.author_id)
download_directory = channel.directory download_directory = channel.download_directory or self.config['download_directory']
download_directory = download_directory or self.config['download_directory']
except exceptions.NoSuchChannel: except exceptions.NoSuchChannel:
download_directory = self.config['download_directory'] download_directory = self.config['download_directory']
download_directory = pathclass.Path(download_directory) download_directory = pathclass.Path(download_directory)
os.makedirs(download_directory.absolute_path, exist_ok=True) 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) queuefile = download_directory.with_child(video_id).replace_extension(extension)
open(queuefile.absolute_path, 'a').close() open(queuefile.absolute_path, 'a').close()