Récupérée un valeur dans un fichier XML en SH

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
Chris54220
Messages : 124
Inscription : 20 mars 2016, 20:54
Localisation : Nancy

Récupérée un valeur dans un fichier XML en SH

Message par Chris54220 »

Bonjour quand j'interroge un serveur il me donne en reponse sa

Code : Tout sélectionner

<MediaContainer size="1">
<Video addedAt="1274632648" art="/library/metadata/337/art/1510846984" contentRating="TV-PG" duration="2508760" grandparentArt="/library/metadata/337/art/1510846984" grandparentKey="/library/metadata/337" grandparentRatingKey="337" grandparentTheme="/library/metadata/337/theme/1510846984" grandparentThumb="/library/metadata/337/thumb/1510846984" grandparentTitle="Kyle XY" guid="com.plexapp.agents.thetvdb://76143/1/7?lang=fr" index="7" key="/library/metadata/345" lastViewedAt="1514126156" librarySectionID="1" librarySectionKey="/library/sections/1" librarySectionTitle="Séries" originallyAvailableAt="2006-08-07" parentIndex="1" parentKey="/library/metadata/338" parentRatingKey="338" parentThumb="/library/metadata/338/thumb/1510846957" parentTitle="Season 1" rating="7.7" ratingKey="345" sessionKey="2" summary="Kyle désespère de voir sa mémoire lui jouer ainsi des tours. Il a bel et bien rêvé du Professeur Kern, porté disparu. Aurait-il été témoin de son meurtre ? Nicole propose au jeune homme d'oublier cette affaire et de se détendre un peu. Kyle se découvre alors un don pour le basket. Impressionné par son adresse au jeu, Charlie le convainc de rejoindre l'équipe..." thumb="/library/metadata/345/thumb/1510846965" title="L'esprit d'équipe" titleSort="L'esprit d'equipe" type="episode" updatedAt="1510846965" viewOffset="1057847" year="2006">
<Media id="311" videoProfile="advanced simple" audioChannels="2" audioCodec="mp3" bitrate="1707" container="mpegts" duration="2508760" height="352" protocol="hls" videoCodec="h264" videoFrameRate="PAL" videoResolution="SD" width="624" selected="1">
<Part id="311" videoProfile="advanced simple" bitrate="1707" container="mpegts" duration="2508760" height="352" protocol="hls" width="624" decision="transcode" selected="1">
<Stream bitrate="1533" codec="h264" frameRate="25" height="352" id="786" streamType="1" width="624" decision="transcode" location="segments-av"/>
<Stream bitrate="174" bitrateMode="cbr" channels="2" codec="mp3" id="787" selected="1" streamType="2" decision="copy" location="segments-av"/>
</Part>
</Media>
<Director filter="director=630" id="630" tag="Patrick Williams"/>
<Writer filter="writer=628" id="628" tag="Bryan Wynbrandt"/>
<Writer filter="writer=629" id="629" tag="Steven Lilien"/>
<User id="1" thumb="https://plex.tv/users/a29870c5cd904142/avatar?c=1510844735" title="Christopher54"/>
<Player address="192.168.1.147" device="SM-G935F" machineIdentifier="15d11d3581571f84-com-plexapp-android" model="hero2lte" platform="Android" platformVersion="7.0" product="Plex for Android" profile="Android" remotePublicAddress="213.111.36.84" state="playing" title="Galaxy S7 Edge" vendor="samsung" version="6.11.2.3107" local="1" userID="1"/>
<Session id="15d11d3581571f84-com-plexapp-android" bandwidth="1976" location="lan"/>
<TranscodeSession key="/transcode/sessions/15d11d3581571f84-com-plexapp-android" throttled="0" complete="0" progress="74" speed="8" duration="2508760" remaining="85" context="streaming" sourceVideoCodec="mpeg4" sourceAudioCodec="mp3" videoDecision="transcode" audioDecision="copy" protocol="hls" container="mpegts" videoCodec="h264" audioCodec="mp3" audioChannels="2" transcodeHwRequested="0" timeStamp="1514126074.6894648" maxOffsetAvailable="1854" minOffsetAvailable="1"/>
</Video>
</MediaContainer>
Maintenant j'aimerai récupérer des info de dans

exemple state

st_status=$(curl -s "http://255.255.255.255:99999/status/ses ... fgrdgdghdA" | partie que je ne sais pas quoi mettre)


Merci d'avance
Chrominator
Messages : 1042
Inscription : 19 déc. 2015, 07:29
Localisation : France

Re: Récupérée un valeur dans un fichier XML en SH

Message par Chrominator »

Essaye avec xmllint qu'on trouve dans les dépots :

Code : Tout sélectionner

st_status=$(curl -s "http://255.255.255.255:99999/status/sessions/?X-Plex-Token=MHTdfgrdgdghdA" | xmllint --xpath 'string(//MediaContainer/Video/Player/@state)' -)
Un bon frein vaut mieux que deux sparadraps.

Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Répondre