diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-06-10 17:04:06 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-06-10 17:04:06 -0700 |
commit | 103b37030fcd073b5f44b9ddc79da0ce15325a96 (patch) | |
tree | f0f577a0e418cc56984673fc031024d7eed2d770 /youtube/subscriptions.py | |
parent | e7989db931132f71c54b8924e5194410cc7f9bbc (diff) | |
download | yt-local-103b37030fcd073b5f44b9ddc79da0ce15325a96.tar.lz yt-local-103b37030fcd073b5f44b9ddc79da0ce15325a96.tar.xz yt-local-103b37030fcd073b5f44b9ddc79da0ce15325a96.zip |
Unsubscribe button on channels if already subscribed
Diffstat (limited to 'youtube/subscriptions.py')
-rw-r--r-- | youtube/subscriptions.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py index b6a4e0e..e12fa0b 100644 --- a/youtube/subscriptions.py +++ b/youtube/subscriptions.py @@ -68,6 +68,20 @@ def with_open_db(function, *args, **kwargs): with connection as cursor: return function(cursor, *args, **kwargs) +def is_subscribed(channel_id): + if not os.path.exists(database_path): + return False + + with open_database() as connection: + with connection as cursor: + result = cursor.execute('''SELECT EXISTS( + SELECT 1 + FROM subscribed_channels + WHERE yt_channel_id=? + LIMIT 1 + )''', [channel_id]).fetchone() + return bool(result[0]) + def _subscribe(cursor, channels): ''' channels is a list of (channel_id, channel_name) ''' |