|
12 | 12 | import struct |
13 | 13 | import subprocess |
14 | 14 | import uuid |
15 | | -from helpers import is_safe_path, send_device_description, send_scpd_xml |
| 15 | +from helpers import ( |
| 16 | + is_safe_path, |
| 17 | + send_device_description, |
| 18 | + send_scpd_xml, |
| 19 | + handle_get_protocol_info, |
| 20 | +) |
16 | 21 | from http.server import BaseHTTPRequestHandler |
17 | 22 | from urllib.parse import unquote, urlparse, quote |
18 | 23 |
|
@@ -743,7 +748,7 @@ def handle_soap_request(self, post_data, soap_action=""): |
743 | 748 | if "Browse" in soap_data or "Browse" in soap_action: |
744 | 749 | self.handle_browse_request(soap_data) |
745 | 750 | elif "GetProtocolInfo" in soap_data or "GetProtocolInfo" in soap_action: |
746 | | - self.handle_get_protocol_info() |
| 751 | + handle_get_protocol_info(self) |
747 | 752 | elif ( |
748 | 753 | "GetCurrentConnectionIDs" in soap_data |
749 | 754 | or "GetCurrentConnectionIDs" in soap_action |
@@ -801,67 +806,6 @@ def handle_soap_request(self, post_data, soap_action=""): |
801 | 806 | traceback.print_exc() |
802 | 807 | self.send_error(500, "Internal server error") |
803 | 808 |
|
804 | | - def handle_get_protocol_info(self): |
805 | | - """Handle ConnectionManager GetProtocolInfo requests""" |
806 | | - try: |
807 | | - print("Handling GetProtocolInfo request") |
808 | | - |
809 | | - # Define supported protocols with expanded format support |
810 | | - source_protocols = [ |
811 | | - # Video formats |
812 | | - "http-get:*:video/mp4:DLNA.ORG_PN=AVC_MP4_MP_SD_AAC_MULT5;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
813 | | - "http-get:*:video/x-msvideo:DLNA.ORG_PN=AVI;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
814 | | - "http-get:*:video/x-matroska:DLNA.ORG_PN=MATROSKA;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
815 | | - "http-get:*:video/quicktime:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
816 | | - "http-get:*:video/x-ms-wmv:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
817 | | - "http-get:*:video/x-flv:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
818 | | - "http-get:*:video/webm:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
819 | | - "http-get:*:video/x-m4v:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
820 | | - "http-get:*:video/3gpp:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
821 | | - # Audio formats |
822 | | - "http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
823 | | - "http-get:*:audio/wav:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
824 | | - "http-get:*:audio/mp4:DLNA.ORG_PN=AAC_ISO_320;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
825 | | - "http-get:*:audio/x-m4a:DLNA.ORG_PN=AAC_ISO_320;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
826 | | - "http-get:*:audio/flac:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
827 | | - "http-get:*:audio/ogg:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
828 | | - "http-get:*:audio/x-ms-wma:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
829 | | - "http-get:*:audio/aiff:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000", |
830 | | - # Image formats |
831 | | - "http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_LRG;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=00D00000000000000000000000000000", |
832 | | - "http-get:*:image/png:DLNA.ORG_PN=PNG_LRG;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=00D00000000000000000000000000000", |
833 | | - "http-get:*:image/gif:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=00D00000000000000000000000000000", |
834 | | - "http-get:*:image/bmp:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=00D00000000000000000000000000000", |
835 | | - "http-get:*:image/tiff:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=00D00000000000000000000000000000", |
836 | | - "http-get:*:image/webp:DLNA.ORG_OP=01;DLNA.ORG_FLAGS=00D00000000000000000000000000000", |
837 | | - ] |
838 | | - |
839 | | - source_info = ",".join(source_protocols) |
840 | | - sink_info = "" # This server doesn't act as a sink |
841 | | - |
842 | | - response = f"""<?xml version="1.0" encoding="utf-8"?> |
843 | | -<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> |
844 | | - <s:Body> |
845 | | - <u:GetProtocolInfoResponse xmlns:u="urn:schemas-upnp-org:service:ConnectionManager:1"> |
846 | | - <Source>{source_info}</Source> |
847 | | - <Sink>{sink_info}</Sink> |
848 | | - </u:GetProtocolInfoResponse> |
849 | | - </s:Body> |
850 | | -</s:Envelope>""" |
851 | | - |
852 | | - self.send_response(200) |
853 | | - self.send_header("Content-Type", "text/xml; charset=utf-8") |
854 | | - self.send_header("Content-Length", str(len(response))) |
855 | | - self.end_headers() |
856 | | - self.wfile.write(response.encode()) |
857 | | - if self.verbose: |
858 | | - print("Sent GetProtocolInfo response") |
859 | | - |
860 | | - except Exception as e: |
861 | | - print(f"Error handling GetProtocolInfo: {e}") |
862 | | - traceback.print_exc() |
863 | | - self.send_error(500, "Internal server error") |
864 | | - |
865 | 809 | def handle_get_current_connection_ids(self): |
866 | 810 | """Handle ConnectionManager GetCurrentConnectionIDs requests""" |
867 | 811 | try: |
|
0 commit comments