Rename directory -> download_directory; add queuefile_extension.
This commit is contained in:
parent
213278edcc
commit
59eab3f997
4 changed files with 38 additions and 7 deletions
|
@ -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):
|
||||
'''
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue