mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
* Removes `MAX_BALANCE` from bank, user `bank.get_max_balance()` now `[p]bankset maxbal` can be used to set the maximum bank balance Signed-off-by: Guy <guyreis96@gmail.com> * Initial Commit Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * I need to make sure I keep aika on her toes. Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * Fixes a few missing kwargs and case consistency Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * Fixes a few missing kwargs and case consistency v2 and typos Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * Reset cooldowns + add changelogs Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * Add 3 extra file formats. Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * IRDUMB - fix capitalization. Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * Fix a silent error, and some incorrect messages. Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Remove unnecessary emojis from queue when they are not needed Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Remove duplicated call in `[p]playlist update` Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Remove duplicated call in `[p]playlist update` Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Resolve conflicts Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * Bring all files up to date + Black Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * Facepalm Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * *Sigh* Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * *Sigh* 2.0 Signed-off-by: Draper <27962761+Drapersniper@users.noreply.github.com> * Merge branch 'V3/develop' of https://github.com/Cog-Creators/Red-DiscordBot into audio-misc-pt1 Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> # Resolve Conflicts: # redbot/cogs/audio/audio.py # redbot/cogs/audio/utils.py * Import missing Typecheck Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Fix Broken docstrings Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Sort Local Tracks Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * 🤦 Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Reorder the sorting of local tracks, `alphanumerical lower then alphanumerical upper` `a comes before A, but B comes after A` Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Black formatting Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Make the local file sorting case insensitive Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Add global blacklist/whitelist + fix some issues with original server based whitelist/blacklist Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Remove the pre-commit yaml Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Nottin to see Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Further improvement to the blacklists Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Further improvement to the blacklists Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Fix the __str__ method on LocalTracks Object * Rename LocalTracks.to_string_hidden() to LocalTracks.to_string_user() To keep it inline with the Query object * Remove encoding pragmas + a few typo fixes * Update some typehints + fix some typos * Remove this duplicate call * Black * fix capitalization * Address preda's review Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Remove the API from the audio cog - Is in direct conflict with goals stated in #2804 - Features this was intended to enable can be enabled in other more appropriate ways later on * changelog * Address Aika's review * Black * *sigh* dont use github web ui * Fuck windows Long live linux... *sigh* no lets ensure windows users can still use local tracks * Merge branch 'V3/develop' of https://github.com/Cog-Creators/Red-DiscordBot into refactoring Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> # Conflicts: # redbot/cogs/audio/audio.py * 👀 + chore Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * facepalm Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * facepalm... again y u h8 me bruh Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * fuk this fuk u tube fuck python fuck all Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * awyehfqwajefhnqeffawefqa eqewarfqaesf qwef qaf qwfr Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * fuck everything Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * oh lord saviour resus i love you just make this work Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Change logic to be no errors within last 10 seconds... this should be a valid work around discord ratelimits caused by the spam * Remove auto deletion Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * See I did a ting Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * irdumb Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * black Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Add an is_url attribute to Query objects * chore Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Black * Address Aikas review Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Hyperlink Playlist names Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Make shit bold Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * why was this here Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * why was this here Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Initial commit * Workinnng Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Improve SQL Statements + migrate from SQL Alchemy + Databases to APSW Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * apsw tested and working Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * chose Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Migrate Playlist to DB 3 TODO 1 Migrate Config to Schema 3 without playlists and update get_playlist methods Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Revert "Migrate Playlist to DB 3 TODO 1 Migrate Config to Schema 3 without playlists and update get_playlist methods" This reverts commit 4af33cff Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Implement schema migration * Lets not touch the deps since #3192 is already adding them * chore * *sigh* Black * Follow the existing logic and always default Playlist to guild scope * wghqjegqf black * Update usage of last_fetched and last_updated to be Ints... However column migration still pending * Some bug fixes * Update usage of last_fetched and last_updated to be Ints... However column migration still pending * working Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * partial match Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * better partial match Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * black Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * I thought i done this before * Delete 3195.misc.1.rst Wrong PR * Thanks Sinbad Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Thanks Sinbad Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Log Errors in init ... Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Update error logs. Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Create index Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * :Drapersweat: Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Chore Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Revert "Chore" This reverts commit edcc9a9f UGHHHH Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Allow removing tracks from queue by URL Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Words matter Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * chore Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * arghhh CONFLICTS Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Review sinbads latest comment .. ToDo.. Nuke existing playlist - check version and set version Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * migrate the DB schema to v3 (to keep in line with the schema visioning of Config * Add a Todo * *sigh* conflicts and black * *sigh* black * Passively delete playlist deletion mechanism * Delete Old entries on startup * Since we are dropping the table mightaware make these into JSON for future proofing * Don't Dump strings in JSON field ? :think: * Move some things around to make easier to use 1 connection to the Audio DB * Move some things around to make easier to use 1 connection to the Audio DB * *sigh* * Clean up api * *sigh* black * Red + reorder some variables * 🤦 * how could i forget this ....... * Black Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Black Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Black Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * #automagically Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * FINAFUCKINGLY Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * FINAFUCKINGLY Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Remove unused config default Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Remove the API from the audio Cog (Properly) Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Missed these changes Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * ARGHHH Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Some fixes I've noticed while running through the code line by line Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Translation + UX (show playlist author ID if can't find user) Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* missed this one Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * this is no longer needed .... Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * 🤦 Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * fix new lines in error messages Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Black * Sinbads Review Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Sinbads Review Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* copy paste Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * imrpove backups Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Im a fucking idiot Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Fix #3238 Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * chore Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * humans Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * humans Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * add play alias to playlists Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Im dumb ... Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Im dumb ... Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * fix new line Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * fix new line Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * show playlist count on playlist picker Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * DJ/Vote system fixes Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * DJ/Vote system fixes Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* fix currency check Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * show playlist count on playlist picker Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * DJ/Vote system fixes Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * DJ/Vote system fixes Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* fix currency check Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Fix duplicate messages on timeout Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * fix SQL Statement logic Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * fix SQL Statement logic Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Markdown escape Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Markdown escape Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Markdown escape fix Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Markdown escape fix Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * clean up local cache more frequently Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * clean up db more frequently Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Await in hell Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* im dumb Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* im dumb Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Black cuz I hate red Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Black cuz I hate red Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * StringIO to ByteIO Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * StringIO to ByteIO Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* im dumb Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * :Facepalm: the whole purpose of this is so its offline so this can be backed up without being blocking Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Run write queries on ThreadPoolExecutor Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Backup Audio.db Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* im dumb Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * blaaaack Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * *sigh* Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * formatting Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * remove duplicated string of code Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * ffs awaits Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> Co-authored-by: Michael H <michael@michaelhall.tech>
398 lines
7.6 KiB
Python
398 lines
7.6 KiB
Python
# TODO: https://github.com/Cog-Creators/Red-DiscordBot/pull/3195#issuecomment-567821701
|
|
# Thanks a lot Sinbad!
|
|
|
|
__all__ = [
|
|
# PRAGMA Statements
|
|
"PRAGMA_SET_temp_store",
|
|
"PRAGMA_SET_journal_mode",
|
|
"PRAGMA_SET_read_uncommitted",
|
|
"PRAGMA_FETCH_user_version",
|
|
"PRAGMA_SET_user_version",
|
|
# Playlist table statements
|
|
"PLAYLIST_CREATE_TABLE",
|
|
"PLAYLIST_DELETE",
|
|
"PLAYLIST_DELETE_SCOPE",
|
|
"PLAYLIST_DELETE_SCHEDULED",
|
|
"PLAYLIST_FETCH_ALL",
|
|
"PLAYLIST_FETCH_ALL_WITH_FILTER",
|
|
"PLAYLIST_FETCH_ALL_CONVERTER",
|
|
"PLAYLIST_FETCH",
|
|
"PLAYLIST_UPSERT",
|
|
"PLAYLIST_CREATE_INDEX",
|
|
# YouTube table statements
|
|
"YOUTUBE_DROP_TABLE",
|
|
"YOUTUBE_CREATE_TABLE",
|
|
"YOUTUBE_CREATE_INDEX",
|
|
"YOUTUBE_UPSERT",
|
|
"YOUTUBE_UPDATE",
|
|
"YOUTUBE_QUERY",
|
|
"YOUTUBE_DELETE_OLD_ENTRIES",
|
|
# Spotify table statements
|
|
"SPOTIFY_DROP_TABLE",
|
|
"SPOTIFY_CREATE_INDEX",
|
|
"SPOTIFY_CREATE_TABLE",
|
|
"SPOTIFY_UPSERT",
|
|
"SPOTIFY_QUERY",
|
|
"SPOTIFY_UPDATE",
|
|
"SPOTIFY_DELETE_OLD_ENTRIES",
|
|
# Lavalink table statements
|
|
"LAVALINK_DROP_TABLE",
|
|
"LAVALINK_CREATE_TABLE",
|
|
"LAVALINK_CREATE_INDEX",
|
|
"LAVALINK_UPSERT",
|
|
"LAVALINK_UPDATE",
|
|
"LAVALINK_QUERY",
|
|
"LAVALINK_QUERY_LAST_FETCHED_RANDOM",
|
|
"LAVALINK_DELETE_OLD_ENTRIES",
|
|
"LAVALINK_FETCH_ALL_ENTRIES_GLOBAL",
|
|
]
|
|
|
|
# PRAGMA Statements
|
|
PRAGMA_SET_temp_store = """
|
|
PRAGMA temp_store = 2;
|
|
"""
|
|
PRAGMA_SET_journal_mode = """
|
|
PRAGMA journal_mode = wal;
|
|
"""
|
|
PRAGMA_SET_read_uncommitted = """
|
|
PRAGMA read_uncommitted = 1;
|
|
"""
|
|
PRAGMA_FETCH_user_version = """
|
|
pragma user_version;
|
|
"""
|
|
PRAGMA_SET_user_version = """
|
|
pragma user_version=3;
|
|
"""
|
|
|
|
# Playlist table statements
|
|
PLAYLIST_CREATE_TABLE = """
|
|
CREATE TABLE IF NOT EXISTS playlists (
|
|
scope_type INTEGER NOT NULL,
|
|
playlist_id INTEGER NOT NULL,
|
|
playlist_name TEXT NOT NULL,
|
|
scope_id INTEGER NOT NULL,
|
|
author_id INTEGER NOT NULL,
|
|
deleted BOOLEAN DEFAULT false,
|
|
playlist_url TEXT,
|
|
tracks JSON,
|
|
PRIMARY KEY (playlist_id, scope_id, scope_type)
|
|
);
|
|
"""
|
|
PLAYLIST_DELETE = """
|
|
UPDATE playlists
|
|
SET
|
|
deleted = true
|
|
WHERE
|
|
(
|
|
scope_type = :scope_type
|
|
AND playlist_id = :playlist_id
|
|
AND scope_id = :scope_id
|
|
)
|
|
;
|
|
"""
|
|
PLAYLIST_DELETE_SCOPE = """
|
|
DELETE
|
|
FROM
|
|
playlists
|
|
WHERE
|
|
scope_type = :scope_type ;
|
|
"""
|
|
PLAYLIST_DELETE_SCHEDULED = """
|
|
DELETE
|
|
FROM
|
|
playlists
|
|
WHERE
|
|
deleted = true;
|
|
"""
|
|
PLAYLIST_FETCH_ALL = """
|
|
SELECT
|
|
playlist_id,
|
|
playlist_name,
|
|
scope_id,
|
|
author_id,
|
|
playlist_url,
|
|
tracks
|
|
FROM
|
|
playlists
|
|
WHERE
|
|
scope_type = :scope_type
|
|
AND scope_id = :scope_id
|
|
AND deleted = false
|
|
;
|
|
"""
|
|
PLAYLIST_FETCH_ALL_WITH_FILTER = """
|
|
SELECT
|
|
playlist_id,
|
|
playlist_name,
|
|
scope_id,
|
|
author_id,
|
|
playlist_url,
|
|
tracks
|
|
FROM
|
|
playlists
|
|
WHERE
|
|
(
|
|
scope_type = :scope_type
|
|
AND scope_id = :scope_id
|
|
AND author_id = :author_id
|
|
AND deleted = false
|
|
)
|
|
;
|
|
"""
|
|
PLAYLIST_FETCH_ALL_CONVERTER = """
|
|
SELECT
|
|
playlist_id,
|
|
playlist_name,
|
|
scope_id,
|
|
author_id,
|
|
playlist_url,
|
|
tracks
|
|
FROM
|
|
playlists
|
|
WHERE
|
|
(
|
|
scope_type = :scope_type
|
|
AND
|
|
(
|
|
playlist_id = :playlist_id
|
|
OR
|
|
LOWER(playlist_name) LIKE "%" || COALESCE(LOWER(:playlist_name), "") || "%"
|
|
)
|
|
AND deleted = false
|
|
)
|
|
;
|
|
"""
|
|
PLAYLIST_FETCH = """
|
|
SELECT
|
|
playlist_id,
|
|
playlist_name,
|
|
scope_id,
|
|
author_id,
|
|
playlist_url,
|
|
tracks
|
|
FROM
|
|
playlists
|
|
WHERE
|
|
(
|
|
scope_type = :scope_type
|
|
AND playlist_id = :playlist_id
|
|
AND scope_id = :scope_id
|
|
AND deleted = false
|
|
)
|
|
"""
|
|
PLAYLIST_UPSERT = """
|
|
INSERT INTO
|
|
playlists ( scope_type, playlist_id, playlist_name, scope_id, author_id, playlist_url, tracks )
|
|
VALUES
|
|
(
|
|
:scope_type, :playlist_id, :playlist_name, :scope_id, :author_id, :playlist_url, :tracks
|
|
)
|
|
ON CONFLICT (scope_type, playlist_id, scope_id) DO
|
|
UPDATE
|
|
SET
|
|
playlist_name = excluded.playlist_name,
|
|
playlist_url = excluded.playlist_url,
|
|
tracks = excluded.tracks;
|
|
"""
|
|
PLAYLIST_CREATE_INDEX = """
|
|
CREATE INDEX IF NOT EXISTS name_index ON playlists (scope_type, playlist_id, playlist_name, scope_id);
|
|
"""
|
|
|
|
# YouTube table statements
|
|
YOUTUBE_DROP_TABLE = """
|
|
DROP TABLE IF EXISTS youtube;
|
|
"""
|
|
YOUTUBE_CREATE_TABLE = """
|
|
CREATE TABLE IF NOT EXISTS youtube(
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
track_info TEXT,
|
|
youtube_url TEXT,
|
|
last_updated INTEGER,
|
|
last_fetched INTEGER
|
|
);
|
|
"""
|
|
YOUTUBE_CREATE_INDEX = """
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_youtube_url
|
|
ON youtube (track_info, youtube_url);
|
|
"""
|
|
YOUTUBE_UPSERT = """INSERT INTO
|
|
youtube
|
|
(
|
|
track_info,
|
|
youtube_url,
|
|
last_updated,
|
|
last_fetched
|
|
)
|
|
VALUES
|
|
(
|
|
:track_info,
|
|
:track_url,
|
|
:last_updated,
|
|
:last_fetched
|
|
)
|
|
ON CONFLICT
|
|
(
|
|
track_info,
|
|
youtube_url
|
|
)
|
|
DO UPDATE
|
|
SET
|
|
track_info = excluded.track_info,
|
|
last_updated = excluded.last_updated
|
|
"""
|
|
YOUTUBE_UPDATE = """
|
|
UPDATE youtube
|
|
SET last_fetched=:last_fetched
|
|
WHERE track_info=:track;
|
|
"""
|
|
YOUTUBE_QUERY = """
|
|
SELECT youtube_url, last_updated
|
|
FROM youtube
|
|
WHERE
|
|
track_info=:track
|
|
AND last_updated > :maxage
|
|
;
|
|
"""
|
|
YOUTUBE_DELETE_OLD_ENTRIES = """
|
|
DELETE FROM youtube
|
|
WHERE
|
|
last_updated < :maxage;
|
|
"""
|
|
|
|
# Spotify table statements
|
|
SPOTIFY_DROP_TABLE = """
|
|
DROP TABLE IF EXISTS spotify;
|
|
"""
|
|
SPOTIFY_CREATE_TABLE = """
|
|
CREATE TABLE IF NOT EXISTS spotify(
|
|
id TEXT,
|
|
type TEXT,
|
|
uri TEXT,
|
|
track_name TEXT,
|
|
artist_name TEXT,
|
|
song_url TEXT,
|
|
track_info TEXT,
|
|
last_updated INTEGER,
|
|
last_fetched INTEGER
|
|
);
|
|
"""
|
|
SPOTIFY_CREATE_INDEX = """
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_spotify_uri
|
|
ON spotify (id, type, uri);
|
|
"""
|
|
SPOTIFY_UPSERT = """INSERT INTO
|
|
spotify
|
|
(
|
|
id, type, uri, track_name, artist_name,
|
|
song_url, track_info, last_updated, last_fetched
|
|
)
|
|
VALUES
|
|
(
|
|
:id, :type, :uri, :track_name, :artist_name,
|
|
:song_url, :track_info, :last_updated, :last_fetched
|
|
)
|
|
ON CONFLICT
|
|
(
|
|
id,
|
|
type,
|
|
uri
|
|
)
|
|
DO UPDATE
|
|
SET
|
|
track_name = excluded.track_name,
|
|
artist_name = excluded.artist_name,
|
|
song_url = excluded.song_url,
|
|
track_info = excluded.track_info,
|
|
last_updated = excluded.last_updated;
|
|
"""
|
|
SPOTIFY_UPDATE = """
|
|
UPDATE spotify
|
|
SET last_fetched=:last_fetched
|
|
WHERE uri=:uri;
|
|
"""
|
|
SPOTIFY_QUERY = """
|
|
SELECT track_info, last_updated
|
|
FROM spotify
|
|
WHERE
|
|
uri=:uri
|
|
AND last_updated > :maxage;
|
|
"""
|
|
SPOTIFY_DELETE_OLD_ENTRIES = """
|
|
DELETE FROM spotify
|
|
WHERE
|
|
last_updated < :maxage;
|
|
"""
|
|
|
|
# Lavalink table statements
|
|
LAVALINK_DROP_TABLE = """
|
|
DROP TABLE IF EXISTS lavalink ;
|
|
"""
|
|
LAVALINK_CREATE_TABLE = """
|
|
CREATE TABLE IF NOT EXISTS lavalink(
|
|
query TEXT,
|
|
data JSON,
|
|
last_updated INTEGER,
|
|
last_fetched INTEGER
|
|
|
|
);
|
|
"""
|
|
LAVALINK_CREATE_INDEX = """
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_lavalink_query
|
|
ON lavalink (query);
|
|
"""
|
|
LAVALINK_UPSERT = """INSERT INTO
|
|
lavalink
|
|
(
|
|
query,
|
|
data,
|
|
last_updated,
|
|
last_fetched
|
|
)
|
|
VALUES
|
|
(
|
|
:query,
|
|
:data,
|
|
:last_updated,
|
|
:last_fetched
|
|
)
|
|
ON CONFLICT
|
|
(
|
|
query
|
|
)
|
|
DO UPDATE
|
|
SET
|
|
data = excluded.data,
|
|
last_updated = excluded.last_updated;
|
|
"""
|
|
LAVALINK_UPDATE = """
|
|
UPDATE lavalink
|
|
SET last_fetched=:last_fetched
|
|
WHERE query=:query;
|
|
"""
|
|
LAVALINK_QUERY = """
|
|
SELECT data, last_updated
|
|
FROM lavalink
|
|
WHERE
|
|
query=:query
|
|
AND last_updated > :maxage;
|
|
"""
|
|
LAVALINK_QUERY_LAST_FETCHED_RANDOM = """
|
|
SELECT data
|
|
FROM lavalink
|
|
WHERE
|
|
last_fetched > :day
|
|
AND last_updated > :maxage
|
|
ORDER BY RANDOM()
|
|
LIMIT 10
|
|
;
|
|
"""
|
|
LAVALINK_DELETE_OLD_ENTRIES = """
|
|
DELETE FROM lavalink
|
|
WHERE
|
|
last_updated < :maxage;
|
|
"""
|
|
LAVALINK_FETCH_ALL_ENTRIES_GLOBAL = """
|
|
SELECT query, data
|
|
FROM lavalink
|
|
"""
|