aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/channel.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2018-12-17 02:24:55 -0800
committerJames Taylor <user234683@users.noreply.github.com>2018-12-17 02:24:55 -0800
commit75b0c52f5743f837f7dc676fb780882388820e4d (patch)
treef2047e26ed8fd69e3830405e9fa8f1c2a0090377 /youtube/channel.py
parent4825337f3b4ba7064e83f75c12abf44ff30ab6d7 (diff)
downloadyt-local-75b0c52f5743f837f7dc676fb780882388820e4d.tar.lz
yt-local-75b0c52f5743f837f7dc676fb780882388820e4d.tar.xz
yt-local-75b0c52f5743f837f7dc676fb780882388820e4d.zip
Ability to sort channel videos by oldest and by views
Diffstat (limited to 'youtube/channel.py')
-rw-r--r--youtube/channel.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/youtube/channel.py b/youtube/channel.py
index a2acb23..8bb549e 100644
--- a/youtube/channel.py
+++ b/youtube/channel.py
@@ -146,7 +146,7 @@ def channel_tabs_html(channel_id, current_tab, search_box_value=''):
)
else:
result += channel_tab_template.substitute(
- href_attribute = 'href="' + URL_ORIGIN + "/channel/" + channel_id + "/" + tab_name.lower() + '"',
+ href_attribute = ' href="' + URL_ORIGIN + '/channel/' + channel_id + '/' + tab_name.lower() + '"',
tab_name = tab_name,
)
result += channel_search_template.substitute(
@@ -154,11 +154,26 @@ def channel_tabs_html(channel_id, current_tab, search_box_value=''):
search_box_value = html.escape(search_box_value),
)
return result
-
-
+channel_sort_button_template = Template('''\n<a class="sort-button"$href_attribute>$text</a>''')
+sorts = {1: 'views', 2: 'oldest', 3: 'newest'}
+def channel_sort_buttons_html(channel_id, current_sort):
+ result = ''
+ current_sort = int(current_sort)
+ for i in range(1,4):
+ if i == current_sort:
+ result += channel_sort_button_template.substitute(
+ href_attribute='',
+ text = 'Sorted by ' + sorts[current_sort]
+ )
+ else:
+ result += channel_sort_button_template.substitute(
+ href_attribute=' href="' + URL_ORIGIN + '/channel/' + channel_id + '/videos?sort=' + str(i) + '"',
+ text = 'Sort by ' + sorts[i]
+ )
+ return result
-def channel_videos_html(polymer_json, current_page=1, number_of_videos = 1000, current_query_string=''):
+def channel_videos_html(polymer_json, current_page=1, current_sort=3, number_of_videos = 1000, current_query_string=''):
microformat = polymer_json[1]['response']['microformat']['microformatDataRenderer']
channel_url = microformat['urlCanonical'].rstrip('/')
channel_id = channel_url[channel_url.rfind('/')+1:]
@@ -178,6 +193,7 @@ def channel_videos_html(polymer_json, current_page=1, number_of_videos = 1000, c
header = common.get_header(),
channel_title = microformat['title'],
channel_tabs = channel_tabs_html(channel_id, 'Videos'),
+ sort_buttons = channel_sort_buttons_html(channel_id, current_sort),
avatar = '/' + microformat['thumbnail']['thumbnails'][0]['url'],
page_title = microformat['title'] + ' - Channel',
items = items_html,
@@ -336,7 +352,7 @@ def get_channel_page(url, query_string=''):
gevent.joinall(tasks)
number_of_videos, polymer_json = tasks[0].value, tasks[1].value
- return channel_videos_html(polymer_json, page_number, number_of_videos, query_string)
+ return channel_videos_html(polymer_json, page_number, sort, number_of_videos, query_string)
elif tab == 'about':
polymer_json = common.fetch_url('https://www.youtube.com/channel/' + channel_id + '/about?pbj=1', common.desktop_ua + headers_1)
polymer_json = json.loads(polymer_json)