diff options
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/channel.py | 26 | ||||
-rw-r--r-- | youtube/comments.css | 5 | ||||
-rw-r--r-- | youtube/comments.py | 6 | ||||
-rw-r--r-- | youtube/shared.css | 5 | ||||
-rw-r--r-- | youtube/watch.py | 3 |
5 files changed, 29 insertions, 16 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) diff --git a/youtube/comments.css b/youtube/comments.css index bcd5b30..79d88c3 100644 --- a/youtube/comments.css +++ b/youtube/comments.css @@ -43,11 +43,6 @@ grid-column-gap: 10px; justify-content:start; } - .comment-links a{ - background-color: #d0d0d0; - padding: 2px; - justify-self:start; - } .comments{ margin-top:10px; diff --git a/youtube/comments.py b/youtube/comments.py index fe89ac9..abc0a79 100644 --- a/youtube/comments.py +++ b/youtube/comments.py @@ -272,11 +272,11 @@ def get_comments_html(comments): def video_comments(video_id, sort=0, offset=0, lc='', secret_key=''): if settings.enable_comments: post_comment_url = common.URL_ORIGIN + "/post_comment?video_id=" + video_id - post_comment_link = '''<a class="post-comment-link" href="''' + post_comment_url + '''">Post comment</a>''' + post_comment_link = '''<a class="sort-button" href="''' + post_comment_url + '''">Post comment</a>''' other_sort_url = common.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(video_id, sort=1 - sort, lc=lc) other_sort_name = 'newest' if sort == 0 else 'top' - other_sort_link = '''<a href="''' + other_sort_url + '''">Sort by ''' + other_sort_name + '''</a>''' + other_sort_link = '''<a class="sort-button" href="''' + other_sort_url + '''">Sort by ''' + other_sort_name + '''</a>''' comment_links = '''<div class="comment-links">\n''' comment_links += other_sort_link + '\n' + post_comment_link + '\n' @@ -355,7 +355,7 @@ def get_comments_page(query_string): other_sort_url = common.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(metadata['video_id'], sort=1 - metadata['sort']) other_sort_name = 'newest' if metadata['sort'] == 0 else 'top' - other_sort_link = '''<a href="''' + other_sort_url + '''">Sort by ''' + other_sort_name + '''</a>''' + other_sort_link = '''<a class="sort-button" href="''' + other_sort_url + '''">Sort by ''' + other_sort_name + '''</a>''' comment_links = '''<div class="comment-links">\n''' diff --git a/youtube/shared.css b/youtube/shared.css index 1c25b6d..b23f6b7 100644 --- a/youtube/shared.css +++ b/youtube/shared.css @@ -365,3 +365,8 @@ address{ font-weight: bold; text-align: center; } +.sort-button{ + background-color: #d0d0d0; + padding: 2px; + justify-self: start; +}
\ No newline at end of file diff --git a/youtube/watch.py b/youtube/watch.py index 5515616..2d10ec1 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -325,9 +325,6 @@ def get_watch_page(query_string): note = html.escape(downloader._format_note(format)), ) - post_comment_url = common.URL_ORIGIN + "/post_comment?v=" + id - post_comment_link = '''<a class="post-comment-link" href="''' + post_comment_url + '''">Post comment</a>''' - page = yt_watch_template.substitute( video_title = html.escape(info["title"]), |