Added account login page
This commit is contained in:
parent
fef272af4f
commit
d5e2e3ee8a
@ -7,6 +7,7 @@ import re
|
|||||||
import settings
|
import settings
|
||||||
import http.cookiejar
|
import http.cookiejar
|
||||||
import io
|
import io
|
||||||
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(settings.data_dir, 'accounts.txt'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(settings.data_dir, 'accounts.txt'), 'r', encoding='utf-8') as f:
|
||||||
@ -38,6 +39,58 @@ def cookie_jar_from_lwp_str(lwp_str):
|
|||||||
def account_cookie_jar(username):
|
def account_cookie_jar(username):
|
||||||
return cookie_jar_from_lwp_str(accounts[username]['cookies'])
|
return cookie_jar_from_lwp_str(accounts[username]['cookies'])
|
||||||
|
|
||||||
|
def get_account_login_page(query_string):
|
||||||
|
style = '''
|
||||||
|
main{
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0px, 3fr) 640px 40px 500px minmax(0px,2fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
main form{
|
||||||
|
margin-top:20px;
|
||||||
|
grid-column:2;
|
||||||
|
display:grid;
|
||||||
|
justify-items: start;
|
||||||
|
align-content: start;
|
||||||
|
grid-row-gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#username, #password{
|
||||||
|
grid-column:2;
|
||||||
|
width: 250px;
|
||||||
|
}
|
||||||
|
#add-account-button{
|
||||||
|
margin-top:20px;
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
page = '''
|
||||||
|
<form action="''' + common.URL_ORIGIN + '''/login" method="POST">
|
||||||
|
<div class="form-field">
|
||||||
|
<label for="username">Username:</label>
|
||||||
|
<input type="text" id="username" name="username">
|
||||||
|
</div>
|
||||||
|
<div class="form-field">
|
||||||
|
<label for="password">Password:</label>
|
||||||
|
<input type="password" id="password" name="password">
|
||||||
|
</div>
|
||||||
|
<div id="save-account-checkbox">
|
||||||
|
<input type="checkbox" id="save-account" name="save" checked>
|
||||||
|
<label for="save-account">Save account info to disk (password will not be saved, only the login cookie)</label>
|
||||||
|
</div>
|
||||||
|
<input type="submit" value="Add account" id="add-account-button">
|
||||||
|
</form>
|
||||||
|
'''
|
||||||
|
|
||||||
|
return common.yt_basic_template.substitute(
|
||||||
|
page_title = "Login",
|
||||||
|
style = style,
|
||||||
|
header = common.get_header(),
|
||||||
|
page = page,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------
|
# ---------------------------------
|
||||||
# Code ported from youtube-dl
|
# Code ported from youtube-dl
|
||||||
# ---------------------------------
|
# ---------------------------------
|
||||||
@ -271,7 +324,7 @@ def _login(username, password, cookie_jar):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
check_cookie_results = common.fetch_url(check_cookie_url, report-text="Checked cookie", cookie_jar_send=cookie_jar, cookie_jar_receive=cookie_jar).decode('utf-8')
|
check_cookie_results = common.fetch_url(check_cookie_url, report_text="Checked cookie", cookie_jar_send=cookie_jar, cookie_jar_receive=cookie_jar).decode('utf-8')
|
||||||
except (urllib.error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
except (urllib.error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -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
|
from youtube import local_playlist, watch, search, playlist, channel, comments, common, post_comment, accounts
|
||||||
import settings
|
import settings
|
||||||
YOUTUBE_FILES = (
|
YOUTUBE_FILES = (
|
||||||
"/shared.css",
|
"/shared.css",
|
||||||
@ -74,6 +74,10 @@ def youtube(env, start_response):
|
|||||||
start_response('200 OK', (('Content-type',mime_type),) )
|
start_response('200 OK', (('Content-type',mime_type),) )
|
||||||
return f.read().replace(b'$port_number', str(settings.port_number).encode())
|
return f.read().replace(b'$port_number', str(settings.port_number).encode())
|
||||||
|
|
||||||
|
elif path == "/login":
|
||||||
|
start_response('200 OK', (('Content-type','text/html'),) )
|
||||||
|
return accounts.get_account_login_page(query_string=query_string).encode()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
start_response('200 OK', (('Content-type','text/html'),) )
|
start_response('200 OK', (('Content-type','text/html'),) )
|
||||||
return channel.get_channel_page_general_url(path, query_string=query_string).encode()
|
return channel.get_channel_page_general_url(path, query_string=query_string).encode()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user