diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-10-30 23:10:32 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-10-30 23:10:32 -0700 |
commit | 2be1743133b6f54c36fdb49f8e9ae304a2abe127 (patch) | |
tree | a3374caf6df8da635c9c44488e663b987d8f9842 | |
parent | 93cbea380b6d6c72f9dfa542336c1baf2950ee83 (diff) | |
download | yt-local-2be1743133b6f54c36fdb49f8e9ae304a2abe127.tar.lz yt-local-2be1743133b6f54c36fdb49f8e9ae304a2abe127.tar.xz yt-local-2be1743133b6f54c36fdb49f8e9ae304a2abe127.zip |
Search plugin: use same port number that server is running on
-rw-r--r-- | youtube/opensearch.xml | 2 | ||||
-rw-r--r-- | 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 @@ <Url type="text/html" method="GET" template="http://localhost/youtube.com/search"> <Param name="query" value="{searchTerms}"/> </Url> -<SearchForm>http://localhost/youtube.com/search</SearchForm> +<SearchForm>http://localhost:$port_number/youtube.com/search</SearchForm> </SearchPlugin>
\ 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' |