-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclaire_vlc.py
229 lines (129 loc) · 6.81 KB
/
claire_vlc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
VLC_LUA_PORT = "8080"
VLC_PASSWORD = 'password'
import requests
import logging as logging
for handler in logging.root.handlers[:]: logging.root.removeHandler(handler)
logging.basicConfig(
level=logging.WARNING,
format='\t\t[%(levelname)s] %(message)s'
)
logger = logging.getLogger(__name__)
#logger.setLevel(logging.WARNING)
logger.debug("clairecjs_vlc started")
def get_vlc_status():
vlc_lua_port = VLC_LUA_PORT
vlc_password = VLC_PASSWORD
vlc_ip_address = "localhost"
url = f"http://{vlc_ip_address}:{vlc_lua_port}/requests/status.json"
logger.debug(f"* VLC control URL is {url}")
# If you set a password, use HTTP Basic Authentication
auth = ('', vlc_password) # (username, password), leave username as an empty string
response = requests.get(url, auth=auth)
if response.status_code == 200:
# The response will contain JSON data with the status of VLC
status = response.json()
#print(status)
# Extracting specific values
show_name = status.get( 'info', {}).get( 'title', 'Unknown')
video_resolution = status.get( 'video', {}).get( 'width', 'Unknown'), status.get('video', {}).get('height', 'Unknown')
frame_rate = status.get( 'video', {}).get( 'fps', 'Unknown')
codec = status.get( 'info', {}).get( 'codec', 'Unknown')
language = status.get( 'info', {}).get('language', 'Unknown')
position = status.get('position', 'Unknown')
#print(f"Show Name: {show_name}")
#print(f"Video Resolution: {video_resolution[0]}x{video_resolution[1]}")
#print(f"Frame Rate: {frame_rate} fps")
#print(f"Codec: {codec}")
#print(f"Language: {language}")
#print(f"Position: {position}")
return status
else:
print(f"Failed to connect to VLC. Status code: {response.status_code}")
return None
def is_vlc_running():
"""Check if VLC is running by checking for VLC's process."""
# This approach will vary depending on the OS. Here's a simple cross-platform example:
import psutil
for proc in psutil.process_iter(['pid', 'name']):
if proc.info['name'] == 'vlc.exe' or proc.info['name'] == 'vlc':
return True
return False
if __name__ == "__main__":
print(f"\n******* is_vlc_running ************")
print(f"--> {is_vlc_running()}")
print(f"\n******* getting vlc_status *******")
vlc_status = get_vlc_status()
#rint(f"--> {get_vlc_status}")
print(f"\n--> vlc status:\n")
for key, value in vlc_status.items():
print(f" {key}: {value}")
print(f"\n\n--> vlc status:\n")
for key, value in vlc_status.items(): print(f"\t{key}\t:\t{value}")
print(f"\n\n\n******* vlc information? *******")
for key, value in vlc_status.get("information").items(): print(f"\t{key}\t:\t{value}")
print(f"\n\n\n******* vlc category info? *******")
information = vlc_status .get("information", {"Unknown"})
category = information.get( "category", {"Unknown"})
for key, value in category.items(): print(f"\t{key}\t:\t{value}")
print(f"\n\n\n******* vlc meta info? *******")
information = vlc_status .get("information", {"Unknown"})
category = information.get( "category", {"Unknown"})
meta = category .get( "meta", {"Unknown"})
for key, value in meta.items(): print(f"\t{key}\t:\t{value}")
print(f"\n\n\n******* vlc specific info? *******")
vlc_status = get_vlc_status()
vlc_information = vlc_status .get("information", {"Unknown" })
vlc_category = vlc_information.get( "category", {"Unknown" })
vlc_meta = vlc_category .get( "meta", {"Unknown" })
print(f"\n\n\n******* vlc title? *******")
vlc_title = vlc_meta .get( "title", {meta.get("filename")})
print(f"\t\tvlc title: {vlc_title}")
print(f"\n\n\n******* vlc nice info? *******")
vlc_status = get_vlc_status()
vlc_information = vlc_status .get( "information", {"Unknown" })
vlc_length_in_s = vlc_status .get( "length", {"Unknown" })
vlc_position_in_s = vlc_status .get( "time", {"Unknown" })
vlc_category = vlc_information.get( "category", {"Unknown" })
vlc_meta = vlc_category .get( "meta", {"Unknown" })
vlc_title = vlc_meta .get( "title", {"Unknown" }) #fall back on filename?
vlc_season = vlc_meta .get( "seasonNumber", {"Unknown" })
vlc_episode = vlc_meta .get("episodeNumber", {"Unknown" })
vlc_filename = vlc_meta .get( "filename", {"Unknown" })
print(f"\t\tvlc title: {vlc_title }")
print(f"\t\tvlc season: {vlc_season }")
print(f"\t\tvlc ep: {vlc_episode }")
print(f"\t\tvlc filename: {vlc_filename }")
print(f"\t\tvlc len (s): {vlc_length_in_s}")
#### TRASHCAN:
#def fetch_vlc_metadata():
# """Fetch metadata from VLC using python-vlc."""
# import vlc
# if is_vlc_running():
# try:
# instance = vlc.Instance() # Initialize VLC instance
# player = vlc.MediaPlayer(instance)
# media = player.get_media() # Get media
# if media: # Fetch and print the current media title
# title = media.get_mrl() # This may return the file path or URL
# dashboard_logger.debug("Current VLC Title (Python VLC):", title)
# for key in ["title", "artist", "album", "genre", "tracknumber", "date", "comment"]:
# value = media.get_meta(getattr(vlc.MediaMeta, f'META_{key.upper()}', None))
# dashboard_logger.debug(f" {key}: {value}")
# duration = media.get_duration()
# state = player.get_state()
# for key in dir(media): # Get other details if available
# if key.startswith("get_"):
# try:
# value = getattr(media, key)()
# if value: dashboard_logger.debug(f" {key}: {value}")
# except Exception as e:
# pass
# dashboard_logger.debug("All info (mrl):", mrl)
# else:
# dashboard_logger.debug("No media is currently loaded in VLC.")
# return media;
# except Exception as e:
# dashboard_logger.debug(f"Error with VLC Python bindings: {e}")
# else:
# dashboard_logger.debug("VLC is not running.")
# return None