subscriptions page
This commit is contained in:
parent
4a54c4fe30
commit
24642455d0
@ -1,4 +1,6 @@
|
|||||||
from youtube import common, settings, channel
|
from youtube import common, channel
|
||||||
|
import settings
|
||||||
|
from string import Template
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import os
|
import os
|
||||||
import secrets
|
import secrets
|
||||||
@ -10,6 +12,10 @@ try:
|
|||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
print('Error: atoma not installed, subscriptions will not work')
|
print('Error: atoma not installed, subscriptions will not work')
|
||||||
|
|
||||||
|
with open('yt_subscriptions_template.html', 'r', encoding='utf-8') as f:
|
||||||
|
subscriptions_template = Template(f.read())
|
||||||
|
|
||||||
|
|
||||||
# https://stackabuse.com/a-sqlite-tutorial-with-python/
|
# https://stackabuse.com/a-sqlite-tutorial-with-python/
|
||||||
|
|
||||||
database_path = os.path.join(settings.data_dir, "subscriptions.sqlite")
|
database_path = os.path.join(settings.data_dir, "subscriptions.sqlite")
|
||||||
@ -35,7 +41,7 @@ def open_database():
|
|||||||
title text NOT NULL,
|
title text NOT NULL,
|
||||||
duration text,
|
duration text,
|
||||||
time_published integer NOT NULL,
|
time_published integer NOT NULL,
|
||||||
description text,
|
description text
|
||||||
)''')
|
)''')
|
||||||
connection.commit()
|
connection.commit()
|
||||||
except:
|
except:
|
||||||
@ -73,11 +79,19 @@ def _get_videos(number, offset):
|
|||||||
connection = open_database()
|
connection = open_database()
|
||||||
try:
|
try:
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute('''SELECT video_id, title, duration, time_published, description, channel_id, channel_name
|
db_videos = cursor.execute('''SELECT video_id, title, duration, channel_name
|
||||||
FROM videos
|
FROM videos
|
||||||
INNER JOIN subscribed_channels on videos.uploader_id = subscribed_channels.id
|
INNER JOIN subscribed_channels on videos.uploader_id = subscribed_channels.id
|
||||||
ORDER BY time_published DESC
|
ORDER BY time_published DESC
|
||||||
LIMIT ? OFFSET ?''', number, offset)
|
LIMIT ? OFFSET ?''', (number, offset))
|
||||||
|
|
||||||
|
for db_video in db_videos:
|
||||||
|
yield {
|
||||||
|
'id': db_video[0],
|
||||||
|
'title': db_video[1],
|
||||||
|
'duration': db_video[2],
|
||||||
|
'author': db_video[3],
|
||||||
|
}
|
||||||
except:
|
except:
|
||||||
connection.rollback()
|
connection.rollback()
|
||||||
raise
|
raise
|
||||||
@ -176,3 +190,18 @@ def _get_upstream_videos(channel_id, channel_name, time_last_checked):
|
|||||||
info['time published'] = youtube_timestamp_to_posix(info['published'])
|
info['time published'] = youtube_timestamp_to_posix(info['published'])
|
||||||
videos.append(info)
|
videos.append(info)
|
||||||
return videos
|
return videos
|
||||||
|
|
||||||
|
def get_subscriptions_page(env, start_response):
|
||||||
|
items_html = '''<nav class="item-grid">\n'''
|
||||||
|
|
||||||
|
for item in _get_videos(30, 0):
|
||||||
|
items_html += common.video_item_html(info, common.small_video_item_template)
|
||||||
|
items_html += '''\n</nav>'''
|
||||||
|
|
||||||
|
start_response('200 OK', [('Content-type','text/html'),])
|
||||||
|
return subscriptions_template.substitute(
|
||||||
|
header = common.get_header(),
|
||||||
|
items = items_html,
|
||||||
|
page_buttons = '',
|
||||||
|
).encode('utf-8')
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import os
|
import os
|
||||||
from youtube import local_playlist, watch, search, playlist, channel, comments, common, post_comment, accounts
|
from youtube import local_playlist, watch, search, playlist, channel, comments, common, post_comment, accounts, subscriptions
|
||||||
import settings
|
import settings
|
||||||
YOUTUBE_FILES = (
|
YOUTUBE_FILES = (
|
||||||
"/shared.css",
|
"/shared.css",
|
||||||
@ -24,6 +24,8 @@ get_handlers = {
|
|||||||
'post_comment': post_comment.get_post_comment_page,
|
'post_comment': post_comment.get_post_comment_page,
|
||||||
'delete_comment': post_comment.get_delete_comment_page,
|
'delete_comment': post_comment.get_delete_comment_page,
|
||||||
'login': accounts.get_account_login_page,
|
'login': accounts.get_account_login_page,
|
||||||
|
|
||||||
|
'subscriptions': subscriptions.get_subscriptions_page,
|
||||||
}
|
}
|
||||||
post_handlers = {
|
post_handlers = {
|
||||||
'edit_playlist': local_playlist.edit_playlist,
|
'edit_playlist': local_playlist.edit_playlist,
|
||||||
|
24
yt_subscriptions_template.html
Normal file
24
yt_subscriptions_template.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Subscriptions</title>
|
||||||
|
<link href="/youtube.com/shared.css" type="text/css" rel="stylesheet">
|
||||||
|
<link href="/youtube.com/favicon.ico" type="image/x-icon" rel="icon">
|
||||||
|
<link title="Youtube local" href="/youtube.com/opensearch.xml" rel="search" type="application/opensearchdescription+xml">
|
||||||
|
<style type="text/css">
|
||||||
|
.item-list{
|
||||||
|
width:1000px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
$header
|
||||||
|
<main>
|
||||||
|
$items
|
||||||
|
<nav class="page-button-row">
|
||||||
|
$page_buttons
|
||||||
|
</nav>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user