Jump to content

C# .Net API Wrapper MediaServer


Siox

Recommended Posts

Hallo zusammen,

 

Dear english Reader,

see below the german text.

 

ich wollte euch gerne ein Projekt vorstellen, welches ich schon ewig vor hatte. Leider ist erst jetzt etwas daraus geworden.

 

Im Prinzip geht es bei meinem Projekt darum, die Media Server API in die objektorientierte .Net Welt zu holen. Mein Projekt ist also ein Wrapper der nicht viel Wissen um die API mitbringen soll. Der Wrapper soll sich um alles selbst kümmern. Also um die Kommunikation mit dem Media Server und mit dem Aufbereiten der Daten.

 

Was der Wrapper leisten soll:

Der Wrapper soll es ermöglichen z.B. Massenänderungen an Aufnahmen vorzunehmen. Er soll es ferner ermöglichen leicht nach Inhalten zu suchen und diese auf dem Player seiner Wahl abzuspielen. Den Player selbst muss man entweder selbst erstellen oder man greift auf die integrierte DVBViewer Kontrollfunktionen zurück. Er soll auch eine komplette Ferndiagnose möglich machen. So denke ich darüber nach, den Wrapper auch nach .Net Core zu portieren, damit ich ein Überwachungstool des Servers auf einem Raspberry PI umsetzen kann. Auch ein Port nach UWP ist möglich, damit lassen sich Windows Store Apps umsetzen.

 

Ich dachte mir nun: Wenn ich ihn weiter entwickele, dann darf er ruhig auf die Bedürfnisse anderer zugeschnitten werden.

 

Den Sourcecode des Projektes habe ich auf Github online gestellt. Getestet wird der Wrapper von mir aktuell in einer CLI Anwendung.

 

English Version:

I wanted to introduce you to a project that I had planned for ages. Unfortunately, only now has something come of it.

In principle, my project is about getting the Media Server API into the object-oriented .Net world. My project is a wrapper that does not have much knowledge about the API. The wrapper should take care of everything. So to the communication with the Media Server and the preparation of the data.

What the wrapper should do:

The wrapper should allow e.g. Make mass changes to recordings. He should also make it easy to search for content and play it on the player of his choice. You either have to create the player yourself or you can access the integrated DVBViewer control functions. He should also make a complete remote diagnosis possible. So I'm thinking about porting the wrapper to .Net Core so I can implement a server monitoring tool on a Raspberry PI. A port to UWP is possible, so that can be implemented Windows Store Apps.

I thought to myself: If I continue to develop it, then it can be tailored to the needs of others.

I put the source code of the project online on Github. The wrapper is currently being tested by me in a CLI application.

 

screenshotCLI.png?raw=true

 

German:

Eine Demo CLI-Anwendung ist in der Beschreibung des Git. Sowie auch der Stand des Projektes.

 

Um selbst damit zu starten, brauchst du nichts weiter über den MediaServer wissen, außer die IP-Adresse, den Benutzernamen und das Passwort.

So hat man das Wichtigste mit den folgenden Zeilen Code schon erledigt.

 

English:

A demo CLI application is in the description of Git. As well as the state of the project.

To start it yourself, you do not need to know anything about the MediaServer except the IP address, username and password.
So you have already done the important thing with the following lines code.

var dvbServ = new DVBViewerServerApi
            {
                IpAddress = "Name-of-PC or IpAddress",
                //Password is now a SecureString, read the readme on Github
                //Password = "password for guest or admin",
                User = "username for guest or admin",
                Port = 8089
            };

German:

Ich freue mich auf Reaktionen und Kommentare dazu.

 

Hinzugekommen ist eine Demo-Applikation, welche in WPF geschrieben ist. Diese App funktioniert ab Windows 7. Einen Download findest du am Ende dieses Beitrages.

Diese App unterstützt die Sprachen Deutsch und Englisch.

 

English:

I look forward to reactions and comments.
 
Added is a demo application written in WPF. This app works from Windows 7. You will find a download at the end of this article.
This app supports the languages German and English.

 

image.thumb.png.94e7afb3d3f6322479e7637fe571b24c.png

 

Link zur Source: Projekt auf Github.com

Link zur Demo mit grafischer Oberfläche - Sourcecode: Projekt auf Github.com

Link zur Demo Release - Ausführbare Datei: Release auf Github.com

Edited by Siox
Update
Link to comment

Sehr schön. :thumbsup:  Alles, was die Anbindung des DVBViewer Media Servers "nach außen" verbessert, ist willkommen. Wenn du Unterstützung z.B. in Form von weitergehenden Informationen benötigst, lasse es uns wissen.

Link to comment

Danke für das positive Feedback. Eine Frage habe ich doch gleich. Wie lest ihr die Daten über die Clients aus, welche gerade live connected sind?

image.png.1e3b03ff7fbb2761e497026531b3951f.png

 

Edited by Siox
Link to comment

Invoke:

Quote

http://127.0.0.1:8089/api/status2.html

Retrieves:

Quote
<Status>
<timercount> 1 </ timercount>
<reccount> 1 </ reccount>
<nexttimer> 3314 </ nexttimer>
<nextrec> 3314 </ nextrec>
<streamclientcount> 1 </ streamclientcount>
<rtspclientcount> 1 </ rtspclientcount>
<unicastclientcount> 0 </ unicastclientcount>
<lastuiaccess> 12487 </ lastuiaccess>
<standbyblock> 1 </ standbyblock>
<tunercount> 1 </ tunercount>
<streamtunercount> 1 </ streamtunercount>
<rectunercount> 1 </ rectunercount>
<epgudate> 0 </ epgudate>
<rights> full </ rights>
<recfiles> 3587 </ recfiles>
<Recfolders>
<folder size = " 2000325439488 " free = " 49186123776 " >   F: \ TV \ Recording Service </ folder>
<folder size = " 174063611904 " free = " 173727080448 " >   D: \ Recording Service </ folder>
</ Recfolders>
</ Status>

Where a DVBViewer client (in my case ) counts up :

streamclientcount = 1

rtspclientcount = 1

streamtunercount = 1

Edited by majstang
Link to comment
54 minutes ago, Siox said:

Wie lest ihr die Daten über die Clients aus, welche gerade live connected sind?

 

Dafür gibt es kein API. Du könntest nur die ganze HTML-Seite anfordern und auswerten (z.B. mit http://127.0.0.1:8089/status.html?aktion=status). Eine zukünftige Kompatibilität ist dabei jedoch nicht gewährleistet.

Link to comment

Hi majstang,

 

thx for the feedback. :) Did you find the error? :D (IP-Address?)

 

@Griga danke, habe ich beim Studieren der Configs und Datenbanken bemerkt. Dachte aber, es gibt da etwas was ich übersehen habe. :whistle:

So wie die unzähligen API Aufrufe die ich jedesmal neu entdecke, wenn ich wieder die Changelogs lese.

Link to comment

Neue API? Nein... Es wäre eher eine Aufwertung der aktuellen dvbcommand.html. Quasi nur um das XmlElement (Attribute) "Online=1" oder "Online=0". (DVBViewer Clients)

 

Im Prinzip geht es aber darum, dass man von außen sieht, kann ich z.B. Wartungsarbeiten an den Datenbanken vornehmen oder den Server neustarten ohne jemanden zu blockieren / abzuwürgen.

 

//Edit: Ja dafür kann man auch den Serverstatus nehmen. B) Und ja, dann gibt es eben erst einmal nur historische DVBViewer Clients.

Edited by Siox
Link to comment
15 minutes ago, Siox said:

thx for the feedback. :) Did you find the error? :D (IP-Address?)

Sorry, the Chrome german to english translation does strange things to the format, a space was auto added in the IP-adress;)

Link to comment
vor 4 Minuten schrieb majstang:

Sorry, the Chrome german to english translation does strange things to the format, a space was auto added in the IP-adress;)

 

No, I meant. The status2.html doesn't show any IP-Addresses. o:)

Edited by Siox
Link to comment

Ich habe gerade folgendes versucht zu kommentieren:

//http://192.168.2.101:8089/tasks.html?task=UpdateVideoDB&aktion=tasks

Doch ich scheitere an der Aussage: Aktualisiere Mediendatenbanken.

Denn was heisst denn aktualisieren: Es werden neue Dateien hinzugefügt; Es werden nicht mehr existente Dateien entfernt; Es wird beides getan.

Wenn letzteres zutrifft, wieso benötige ich dann "Datenbank neu aufbauen"? Was ja auch sehr viel länger dauert.

Link to comment

Interessant... :) , das betrifft die Aufnahmedatenbank. Ich spreche von der Mediendatenbank. Wird aber wohl ähnlich ablaufen. Um aber mal auf das Dokument zurück zukommen. Ich nutze den RS schon so viele Jahre, das in der Historischen Aufnahme Aufnahmetabelle "RecordedList" knapp 4000 Aufnahmen hinterlegt sind. Und immer wenn ich mal wieder einen Auto-Timer Eintrag mache, bin ich froh, dass der DMS diese Tabelle aktiv nutzt. Denn so werden gefundene Timer einfach deaktiviert und ich vermeide die Aufnahme von Dingen, die ich schon gesehen und die dann nocheinmal aufgenommen wurden wären. Auch wenn vielleicht die Aufnahme gar nicht mehr existiert.

 

Damit lässt sich auch anderes machen. So kann man dem Anwender die Nachricht zukommen lassen, dass bereits eine Aufnahme an Datum etc dafür geplant war /aufgenommen wurde. Wenn er z.B. einen Timer im Webinterface plant. Mir hat diese Funktion hunderte von Aufnahmen zu Leschs Kosmos erspart. Wo das Öffentlich Rechtliche nicht gerade sparsam im Wiederholen ist.

 

Leider musste ich auch feststellen, dass sich bei mir keine Einträge in der Datenbank befinden, welche found=0 haben. Aber das liegt daran, dass ich alle 24 Stunden die Funktion Aufnahme Datenbank bereinigen ausführe, weil ich oft Aufnahmen schneide und zu den Medien schiebe, oder einfach alte Sachen lösche und dann den frei werdenden Speicher wieder hinten auffülle, indem ich Aufnahmen aus Ordner 3 in Ordner 2 verschiebe. (Mit Aufnahmedatenbank aktualisieren) Denn der DMS nimmt ja immer da auf, wo er noch freien Speicher findet. Und ich mag nicht in allen 3 Festplatten nach aktuellen Aufnahmen suchen, sondern möchte alles chronologisch sortiert vorfinden.

 

Von daher wäre ein Ersatzloses streichen der RecordedList ein herber Rückschlag. Außer ihr sorgt dafür, dass tatsächlich keine Einträge mehr aus der Tabelle Recordings verschwinden.

 

Ich kann dir die Aufnahmedatenbank gerne zukommen lassen. Da sind Daten aus ca. 10 7 Jahren DVB Aufnahmen drin. :)

Edited by Siox
Link to comment

@Griga vielen Dank... :)

 

        //TODO: Unbedingt eine Funktion schreiben, welche die Delphiwerte in DateTime übersetzt.

        /// <summary>
        /// TDateTime aus Delphi: Zuletzt geändert an Datum
        /// </summary>
        [XmlElement(ElementName = "TIME")]
        public double Time { get; set; }

        /// <summary>
        /// TDateTime aus Delphi: Hinzugefügt an Datum
        /// </summary>
        [XmlElement(ElementName = "ADDED")]
        public double Added { get; set; }

Habe ich direkt notiert.

 

Link to comment
vor 15 Minuten schrieb janee:

Mit  

DateTime.FromOADate(double d);

kannst du das auch in ein lesbares Format bringen.

und Umgekehrt genauso: DateTime.ToOADate()

Vielen Dank. Habe ich direkt umgesetzt. Leider kann ich das nicht direkt verstecken, weil ich die Klassen deserialisiere. Hat aber trotzdem super funktioniert.

        //TODO: Unbedingt eine Funcktion schreiben, welche die Delphiwerte in DateTime übersetzt.
        /// <summary>
        /// Datum der letzten Änderung
        /// </summary>
        public DateTime Time
        {
            get
            {
                return DateTime.FromOADate(DTime);
            }
        }

        /// <summary>
        /// Das letzte Datum der Änderung als Gleitkommazahl im Delphiformat
        /// </summary>
        [XmlElement(ElementName = "TIME")]
        public double DTime { get; set; }

 

Link to comment

Ok, Update zu Version 0.0.2.1

 

Changelog: Änderungen

 

Das Wichtigste voran:

  • Suche über den Videotitel in der VideoDatenbank
  • Abspielen des Videos direkt auf einem DVBViewer seiner Wahl, wenn Online
  • Erzeugen eines UPnP Strings (URL) für die Wiedergabe auf einem beliebigen Videoplayer
  • Erzeugen einer m3u Datei über eine Liste von Videos zum Abspielen auf einem beliebigen Videoplayer
Link to comment

Ich bin gerade dabei und teste den ApiWrapper an einer Windows Anwendung. Das soll eine Demo werden, was der Wrapper kann und wie man ihn einsetzt.

 

image.thumb.png.1a20c946231d28646bdce0293f962199.png

 

image.thumb.png.550c3ca69cd87fda951eb48b6b838f45.png

 

image.thumb.png.c68453dce661d7695586287734b0cc50.png

Edited by Siox
Link to comment

Version 0.0.2.3:

 

v0.0.2.3

  • changed access modifiers of getter methods in some classes
  • renamed Recording to RecordingList
  • add RecordingSeries as seperate object to RecordingItem
  • Recordings can now be filtered by Series
  • added functions to generate M3U Files for video and recordings
  • some improvements and bugfixes

v0.0.2.2

  • Changed Type of Password from String to SecureString
    • Added Class to encrypt and decrypt a password to store it in a file
      • The decryption and encryption methods are bound to the Windows account
      • For more details, see the readme.md
Link to comment

Wer den Wrapper in einer zum Wrapper begleitenden grafischen Version einmal selbst Testen möchte, der kann dies in einer begleitenden App durchaus machen. Die Anwendung läuft ab WIndows 7 egal ob für x86 oder x64. Da ich den Sourcecode dafür noch nicht freigebe, hier nur der Download über meinen (leider nicht so gut gefüllten) Blog. Den Sourcecode zu dieser Anwendung werde ich aber auch über Github frei zur Verfügung stellen.

 

https://code.sp-datenbank.de/11-coding/csharp/16-c-DVBViewer-media-server-api-wrapper.html

Link to comment

Habe die komplette UI nochmal die letzten Tage komplett überarbeitet. Das heißt Fehler etc. Den Sourcecode habe ich auf Github online gestellt.

The completely UI Demo has been reworked to fix error messages and crashes. I added multi language support for future options. Now german and english are supported. The source code was uploaded to Github, check the thread's first post. The ApiWrapper version was changed to a realistic value. :oops:

Edited by Siox
Link to comment
2 hours ago, Siox said:

english are supported

 

Thanks i did wait on that. Now its time to try it out and see if your wrapper might inspire me with ideas for my own similar projekt.  

Link to comment

Currently, I work on a performance boost. With this, I have rewritten the comments in english too. But the boost is: All the communications are asyncronous. The basic I have written with SendDataAsync or GetDataAsync. Now all is async. The result is very simple. The UI App will never sleep, if we wait for an answer from the server. I can see the boost in the CLI app. At least that's what I believe. 

 

I have to check the demo app. But for this evening I have done enough. B)

Link to comment
11 hours ago, Siox said:

All the communications are asyncronous

 

Very wise:) I made this switch in my own application many years ago after experiencing cases where server connection was blocked and was denied further reponse until it timed out.

 

Had some crashes with your demo btw. I have no access to the recordings. It can be due to changes done on the database in the DMS beta version im using, so obviously Im not the most suitable tester. I can access the videos though, but when trying to play one of them the file is not opened with the system default videoplayer, which is my VLC-playerscript for mp4 files. Instead its launched with MediaMonkey.   

Link to comment
vor 3 Stunden schrieb majstang:

Had some crashes with your demo btw. I have no access to the recordings. It can be due to changes done on the database in the DMS beta version im using, so obviously Im not the most suitable tester.  

 

No Access to the recordings... This part uses the recording.html, you can access the data with: http://adminName:Password@YourServerName:8089/api/recordings.html in your Browser. Post the a part of the result here (or send a pm) and I can check it.

vor 3 Stunden schrieb majstang:

I can access the videos though, but when trying to play one of them the file is not opened with the system default videoplayer, which is my VLC-playerscript for mp4 files. Instead its launched with MediaMonkey.   

 

May your mp4 default application is VLC, but the wrapper generates a m3u file and send it directly to the system. And for the m3u file your default application is MediaMonkey.

Process.Start("m3uFile");

 

Link to comment

The changing to a complete asynchronous execution is now completed. The demo app has been updated too. Check the thread's first post for the download.

Edited by Siox
Link to comment
1 hour ago, majstang said:

Maybe something for the DMS

 

Sorry, no. I won't do that. It's just inappropriate to force such a feature in the DMS. It's much better to create an intermediate app for this kind of job. Please remember that the DMS has no UI on its own for known reasons (because it's running in a system account). It always requires an intermediate app for getting in contact with the user sphere. As far as it concerns the web interfaces browsers are playing this part. However, they are not suitable for launching third party apps directly. Something else must take over.

 

Link to comment

Könnt ihr die Dateigröße einer Aufnahme (recording) mit in die API aufnehmen. Also die tatsächliche Größe? Das wäre echt super, so kann man einfach daran erkennen, dass eine Aufnahme fehlgeschlagen ist.

 

Could you save the file size of a recording into the API? Also the actual size? That would be really great. So you can easily see that a recording failed.

Link to comment
vor 2 Stunden schrieb Siox:

Könnt ihr die Dateigröße einer Aufnahme (recording) mit in die API aufnehmen. Also die tatsächliche Größe? Das wäre echt super, so kann man einfach daran erkennen, dass eine Aufnahme fehlgeschlagen ist.

 

Could you save the file size of a recording into the API? Also the actual size? That would be really great. So you can easily see that a recording failed.

 

Du kannst lesend SQL Queries ausführen. Damit kannst du sicher auch die Dateigröße abfragen.

 

Siehe dazu:

http://www.DVBViewer.tv/forum/topic/59621-media-server-2x-api-changes/

  • Added: API: Possibility to get tables from the Media Server databases as XML output by using SQLite queries:

/api/sql.html?[video/audio/photo/rec]=1&query=[SQLite query]

where video=1 (default), audio=1, photo=1 or rec=1 specify the database. The access is restricted to “read only”. You may use the attached database diagrams (see below)  or the SQLiteBrowser to get insight into the database structures.

 

 

 

Link to comment
54 minutes ago, janee said:

Du kannst lesend SQL Queries ausführen. Damit kannst du sicher auch die Dateigröße abfragen.

 

So einfach ist das nicht. Die Dateigröße von Aufnahmen steht in der Video-Tabelle der SvcDatabase.db3 (Size: BIGINT), und die dortigen Einträge werden erst angelegt, wenn man eine Aufnahme abspielt. Irgendwie schlecht organisiert, die Sache. Die Daten der Tabelle müssten eigentlich direkt nach einer Aufnahme erfasst werden. Bestückt wird jedoch nur die Tabelle recordings. Das wartet noch auf eine Überarbeitung.

 

Um die Dateigröße einer einzelnen Aufnahme abzufragen, würde ich deshalb die HTTP HEAD Methode probieren.

 

Link to comment

Danke für deine Antwort. Ich werde das einmal ausprobieren, aber ich vermute das bei mehreren 1000 Aufnahmen der Wrapper da ein Zeit Problem bekommt. ;)

 

Eine andere Frage: Ich arbeite gerade am Teil "getchannelsxml.html". Ihr verwendet das Attribute "flags" im "channel" Element. Was bedeutet dies denn?

Gruß

Link to comment

Danke für die Info. Ich habe trotzdem das Bit 1 (in der Doku als Reserved bezeichnet) bei einigen Sender als gesetzt bemerkt. Im nächsten Code Abschnitt siehst du die Flags als Zahl und wie ich es aus der ChannelFormat.txt übernommen habe, als Text. Es handelt sich um Satellitenempfang.

Kanal: KiKa, ID: 4135457810743889262, Flags: 26, Flags: Reserved, VideoService, AudioService
Kanal: Radio Weser TV, ID: 4135450393335418844, Flags: 122, Flags: Reserved, VideoService, AudioService, Non48KhzSamplerate, Bandstacking

Um was handelt es sich beim Reserved Flag?

 

Gruß

Edited by Siox
Link to comment

Das Bit 1 wird inzwischen wieder verwendet und entspricht normalerweise der Checkbox "Nicht automatisch aktualisieren" im Senderlisten-Editor, mit der man manuell geänderte Senderdaten davor schützen kann, durch den Sender Auto-Update korrigiert zu werden. Speziell bei TS Stream Sendern hat es eine andere Bedeutung und entspricht der Checkbox "PTS-Sprünge ignorieren". Weiterhin entspricht Bit 6 bei TS Stream der Checkbox "PCR entfernen".

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...