From 2be1743133b6f54c36fdb49f8e9ae304a2abe127 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Tue, 30 Oct 2018 23:10:32 -0700 Subject: Search plugin: use same port number that server is running on --- youtube/opensearch.xml | 2 +- youtube/youtube.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/youtube/opensearch.xml b/youtube/opensearch.xml index fd10f42..7071a25 100644 --- a/youtube/opensearch.xml +++ b/youtube/opensearch.xml @@ -7,5 +7,5 @@ -http://localhost/youtube.com/search +http://localhost:$port_number/youtube.com/search \ No newline at end of file diff --git a/youtube/youtube.py b/youtube/youtube.py index 29fa6a0..925bcab 100644 --- a/youtube/youtube.py +++ b/youtube/youtube.py @@ -1,9 +1,9 @@ import mimetypes import urllib.parse from youtube import local_playlist, watch, search, playlist, channel, comments, common, account_functions +import settings YOUTUBE_FILES = ( "/shared.css", - "/opensearch.xml", '/comments.css', '/favicon.ico', ) @@ -47,14 +47,23 @@ def youtube(env, start_response): elif path.startswith("/playlists"): start_response('200 OK', (('Content-type','text/html'),) ) return local_playlist.get_playlist_page(path[10:], query_string=query_string).encode() + elif path.startswith("/api/"): start_response('200 OK', () ) result = common.fetch_url('https://www.youtube.com' + path + ('?' + query_string if query_string else '')) result = result.replace(b"align:start position:0%", b"") return result + elif path == "/post_comment": start_response('200 OK', () ) return account_functions.get_post_comment_page(query_string).encode() + + elif path == "/opensearch.xml": + with open("youtube" + path, 'rb') as f: + mime_type = mimetypes.guess_type(path)[0] or 'application/octet-stream' + start_response('200 OK', (('Content-type',mime_type),) ) + return f.read().replace(b'$port_number', str(settings.port_number).encode()) + else: start_response('404 Not Found', () ) return b'404 Not Found' -- cgit v1.2.3