aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/subscriptions.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-06-10 17:04:06 -0700
committerJames Taylor <user234683@users.noreply.github.com>2019-06-10 17:04:06 -0700
commit103b37030fcd073b5f44b9ddc79da0ce15325a96 (patch)
treef0f577a0e418cc56984673fc031024d7eed2d770 /youtube/subscriptions.py
parente7989db931132f71c54b8924e5194410cc7f9bbc (diff)
downloadyt-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.py14
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) '''