allowing to subscribe to multiple channels at once

This commit is contained in:
simon 2021-09-15 21:09:46 +07:00
parent 361d785e2e
commit fe33e9178c
5 changed files with 52 additions and 52 deletions

View File

@ -46,7 +46,7 @@ def process_url_list(url_str):
url_list = re.split('\n+', url_str[0]) url_list = re.split('\n+', url_str[0])
youtube_ids = [] youtube_ids = []
for url in url_list: for url in url_list:
url_clean = url.strip().split('/')[-1] url_clean = url.strip().strip('/').split('/')[-1]
for i in to_replace: for i in to_replace:
url_clean = url_clean.replace(i, '') url_clean = url_clean.replace(i, '')
url_no_param = url_clean.split('&')[0] url_no_param = url_clean.split('&')[0]

View File

@ -5,26 +5,29 @@
<div class="title-bar"> <div class="title-bar">
<h1>Channels</h1> <h1>Channels</h1>
</div> </div>
<div class="two-col"> <div class="info-box info-box-2">
<div> <div class="icon-text">
<h2>Subscribe to channel</h2> <img id="add-icon" onclick="showForm()" src="{% static 'img/icon-add.svg' %}" alt="add-icon">
<p>Input channel ID, channel URL or Video of a channel</p> <p>Subscribe to Channels</p>
<form action="/channel/" method="post"> <div class="show-form">
{% csrf_token %} <form id="hidden-form" action="/channel/" method="post">
<input type="text" id="subscribe" name="subscribe" autocomplete="off"> {% csrf_token %}
<button type="submit">Subscribe</button> <textarea rows="3" placeholder="Input channel ID, channel URL or Video of a channel" id="subscribe" name="subscribe"></textarea>
</form> <button type="submit">Subscribe</button>
</form>
</div>
</div> </div>
<div class="search-form"> <div class="search-form icon-text">
<div class="search-icon">
<img src="{% static 'img/icon-search.svg' %}" alt="search-icon" onclick="showSearch()">
<p>Search Channels</p>
</div>
<form onSubmit="return channelRedirect();" id="search-box"> <form onSubmit="return channelRedirect();" id="search-box">
{% csrf_token %} {% csrf_token %}
<input name="videoSearch" list="resultBox" type="text" id="searchInput" autocomplete="off" oninput="searchChannels(this.value)"> <input name="videoSearch" list="resultBox" type="text" id="searchInput" autocomplete="off" oninput="searchChannels(this.value)">
<datalist id="resultBox"> <datalist id="resultBox">
</datalist> </datalist>
</form> </form>
<div class="search-icon">
<img src="{% static 'img/icon-search.svg' %}" alt="search-icon" onclick="showSearch()">
</div>
</div> </div>
</div> </div>
<div class="padding-box"> <div class="padding-box">

View File

@ -4,33 +4,31 @@
<div class="title-bar"> <div class="title-bar">
<h1>Recent Videos</h1> <h1>Recent Videos</h1>
</div> </div>
<div class="two-col"> <div class="info-box info-box-2">
<div class="sort"> <div class="sort">
<div> <p>Sort order from <span class="settings-current">{{ sortorder }}</span>
<p>Sort order from <span class="settings-current">{{ sortorder }}</span>
<select name="sort" id="sort" onchange="sortChange(this.value)"> <select name="sort" id="sort" onchange="sortChange(this.value)">
<option value="" disabled selected> -- change sort order -- </option> <option value="" disabled selected> -- change sort order -- </option>
<option value="published">date published</option> <option value="published">date published</option>
<option value="downloaded">date downloaded</option> <option value="downloaded">date downloaded</option>
</select></p> </select>
</div> </p>
<div> <p>Hide watched videos <span class="settings-current">{{ hide_watched }}</span>
<p>Hide watched videos <span class="settings-current">{{ hide_watched }}</span>
<select name="watched" id="watched" onchange="hideWatched(this.value)"> <select name="watched" id="watched" onchange="hideWatched(this.value)">
<option value="" disabled selected> -- change hide watched -- </option> <option value="" disabled selected> -- change hide watched -- </option>
<option value="0">show watched videos</option> <option value="0">show watched videos</option>
<option value="1">hide watched videos</option> <option value="1">hide watched videos</option>
</select></p> </select>
</div> </p>
</div> </div>
<div class="search-form"> <div class="search-form icon-text">
<div class="search-icon">
<img src="{% static 'img/icon-search.svg' %}" alt="search-icon" onclick="showSearch()">
</div>
<form action="/" method="POST" id="search-box"> <form action="/" method="POST" id="search-box">
{% csrf_token %} {% csrf_token %}
<input name="videoSearch" list="resultBox" type="text" id="searchInput" autocomplete="off"> <input name="videoSearch" list="resultBox" type="text" id="searchInput" autocomplete="off">
</form> </form>
<div class="search-icon">
<img src="{% static 'img/icon-search.svg' %}" alt="search-icon" onclick="showSearch()">
</div>
</div> </div>
</div> </div>
<div id="player" class="video-player"></div> <div id="player" class="video-player"></div>

View File

@ -314,28 +314,41 @@ class ChannelView(View):
colors = config['application']['colors'] colors = config['application']['colors']
return es_url, colors return es_url, colors
@staticmethod def post(self, request):
def post(request):
""" handle http post requests """ """ handle http post requests """
subscriptions_post = dict(request.POST) subscriptions_post = dict(request.POST)
print(subscriptions_post) print(subscriptions_post)
subscriptions_post = dict(request.POST) subscriptions_post = dict(request.POST)
if 'subscribe' in subscriptions_post.keys(): if 'subscribe' in subscriptions_post.keys():
youtube_ids = process_url_list(subscriptions_post['subscribe']) sub_str = subscriptions_post['subscribe']
if youtube_ids[0]['type'] == 'video': try:
youtube_id = youtube_ids[0]['url'] youtube_ids = process_url_list(sub_str)
vid_details = PendingList().get_youtube_details(youtube_id) self.subscribe_to(youtube_ids)
except ValueError:
print('parsing subscribe ids failed!')
print(sub_str)
sleep(1)
return redirect('channel', permanent=True)
@staticmethod
def subscribe_to(youtube_ids):
""" process the subscribe ids """
for youtube_id in youtube_ids:
if youtube_id['type'] == 'video':
to_sub = youtube_id['url']
vid_details = PendingList().get_youtube_details(to_sub)
channel_id_sub = vid_details['channel_id'] channel_id_sub = vid_details['channel_id']
elif youtube_id['type'] == 'channel':
channel_id_sub = youtube_id['url']
else: else:
channel_id_sub = youtube_ids[0]['url'] raise ValueError('failed to subscribe to: ' + youtube_id)
ChannelSubscription().change_subscribe( ChannelSubscription().change_subscribe(
channel_id_sub, channel_subscribed=True channel_id_sub, channel_subscribed=True
) )
print('subscribed to: ' + channel_id_sub) print('subscribed to: ' + channel_id_sub)
sleep(1)
return redirect('channel', permanent=True)
class VideoView(View): class VideoView(View):
""" resolves to /video/<video-id>/ """ resolves to /video/<video-id>/

View File

@ -182,11 +182,7 @@ button:hover {
.sort { .sort {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
} align-content: center;
.sort > div {
width: 100%;
display: inline;
} }
.padding-box { .padding-box {
@ -201,13 +197,6 @@ button:hover {
width: 50%; width: 50%;
} }
.search-form {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
}
.search-form input { .search-form input {
width: 90%; width: 90%;
} }
@ -615,9 +604,6 @@ button:hover {
.sort { .sort {
display: block; display: block;
} }
.sort > div {
display: block;
}
.sort select { .sort select {
width: 100%; width: 100%;
margin: unset; margin: unset;