Seite 1 von 1

Probleme mit process.run

Verfasst: Samstag 11. November 2017, 17:09
von Angrydad
Hallo zusammen!

Bin ganz neu hier und auch im Umgang mit Python - bin eigentlich Elektriker.
(Kurze Vorstellung, Bin 32j aus Ösiland und werke Hobbymäßig viel mit ESXi,)

Hab mir vorgenommen einen Raspberry zu basteln der meine DVD sammlung automatisch rippt.
Im nachhinein villeicht ein wenig zu viel für den Anfang. :(

Zum Problem:

Code: Alles auswählen

from tkinter import *
import os.path
import os
import time
import re
import subprocess
from subprocess import Popen
import sys


def get_dvd_title():
    vols = os.listdir('/media/pi')
    candidates = list()
    for vol in vols:
        if vol.startswith('.'):
            continue
        candidates.append(vol)
    if len(candidates) > 0:
        for vol in candidates:
            dirs = os.listdir('/media/pi/' + vol)
            if 'VIDEO_TS' in dirs:
                return vol


dvd_title=get_dvd_title()
out_dir='/home/pi/Downloads/download'
infile='/dev/dvd'
outfile= '%s/%s.mkv' % (out_dir, dvd_title)

subprocess.run(["/home/pi/handbrake/HandBrake-1.0.2/build/HandBrakeCLI", '-i', infile, '-o', outfile, '-X 1920', '-e x264', '-b 2048', '-audio-lang-list deu,ger', '--all-audio', '--subtitle-lang-list deu,ger', '--all-subtitle', '-E ac3', '-B 320', '-s 1', '-m', '-O'])
wenn ich das so ausführe bekomme ich keine Fehlermeldung, aber machen tut er auch nichts.

Ziel soll sein das eben durch den subprocess hanbrake mit den argumenten gestartet wird und die ausgabe von handbrake (also die letzte zeile) als label am display angezeit wird.

Kann mir da jemand helfen?

Besten Dank im vorraus!

Re: Probleme mit process.run

Verfasst: Samstag 11. November 2017, 17:57
von Sirius3
@Angrydad: was heißt, »tut nichts«? Wie startest Du das Skript? Gibt per print den HandBrake-Befehl aus und prüfe, ob der so richtig ist. Übrigens müssen bei Subprocess alle Parameter einzeln angegeben werden, also statt '-e x264', zwei Elemente '-e', 'x264'.

Re: Probleme mit process.run

Verfasst: Samstag 11. November 2017, 18:30
von Angrydad
Hallo Sirius3!

Schonmal danke für den Tip - hab das gleich mal geändert, mit dem aufteilen.

Mit tut nichts - mein ich, es kommt weder eine Ausgabe, Fehlermeldung in der Konsole, noch wird die .mkv erstellt.
Mit Print kommt das in der Konsole raus:

Code: Alles auswählen

['/home/pi/handbrake/HandBrake-1.0.2/build/HandBrakeCLI', '-i', '/dev/dvd', '-o', '/home/pi/Downloads/download/JARHEAD.mkv', '-X', '1920', '-e', 'x264', '-b', '2048', '-audio-lang-list', 'deu,ger', '--all-audio', '--subtitle-lang-list', 'deu,ger', '--all-subtitle', '-E', 'ac3', '-B', '320', '-s', '1', '-m', '-O']
Mal das ganze Werk: (nicht lachen!)

Code: Alles auswählen

from tkinter import *
import os.path
import os
import time
import re
import subprocess
from subprocess import Popen
import sys

fenster = Tk()
fenster.title("Jack the Ripper :-)")
fenster.geometry("1920x1080")



    
def get_dvd_title():
    vols = os.listdir('/media/pi')
    candidates = list()
    for vol in vols:
        if vol.startswith('.'):
            continue
        candidates.append(vol)
    if len(candidates) > 0:
        for vol in candidates:
            dirs = os.listdir('/media/pi/' + vol)
            if 'VIDEO_TS' in dirs:
                return vol

title=get_dvd_title()
dvd_title=get_dvd_title()
out_dir='/home/pi/Downloads/download'
HANDBRAKE='/home/pi/handbrake/HandBrake-1.0.2/build/HandBrakeCLI'
    

#input und autput für Handbrake

#infile='/media/pi/%s' % (dvd_title)
infile='/dev/dvd'
outfile= '%s/%s.mkv' % (out_dir, dvd_title)



def start():
    text= open('/home/pi/movie.txt').read()
    my_regex=r'^.*' + re.escape(dvd_title) + '.*$'
    if re.search(get_dvd_title(), text, re.I):

        
        dvdtext = Text(fenster, height=1, width=35,bg="lightgrey", fg="red")
        dvdtext.pack()
        dvdtext.insert(END, re.findall(my_regex,text,re.I|re.M))
        dvdtext.place(x=50, y=250)
        dvdtext.config(font=("Arial", 80))

        
        T = Text(fenster, height=1, width=35,bg="lightgrey", fg="red")
        T.pack()
        T.insert(END, "Ist das der Film?")
        T.place(x=50, y=50)
        T.config(font=("Arial", 60))

        knopf3 = Button(fenster, text="Ja", height=3, width=15, bd=9, fg="green", activeforeground="green", command=nextdvd)
        knopf3.place(x=50, y=550)
        knopf3.config(font=("Arial", 60))

        knopf4 = Button(fenster, text="Nein", height=3, width=15, bd=9, fg="green", activeforeground="green", command=rip)
        knopf4.place(x=1050, y=550)
        knopf4.config(font=("Arial", 60))

        


    else:
        rip()


def druck():
    print (infile)

def rip():
    T = Text(fenster, height=1, width=35,bg="lightgrey", fg="green")
    T.pack()
    T.insert(END, "Film wird gerippt")
    T.place(x=50, y=50)
    T.config(font=("Arial", 60))
    subprocess.run(["/home/pi/handbrake/HandBrake-1.0.2/build/HandBrakeCLI", '-i', infile, '-o', outfile, '-X', '1920', '-e', 'x264', '-b', '2048', '-audio-lang-list', 'deu,ger', '--all-audio', '--subtitle-lang-list', 'deu,ger', '--all-subtitle', '-E', 'ac3', '-B', '320', '-s', '1', '-m', '-O']) 




 

def nextdvd():


    T = Text(fenster, height=1, width=35,bg="lightgrey", fg="red")
    T.pack()
    T.insert(END, "Film vorhanden, Nächste DVD einlegen")
    T.place(x=50, y=50)
    T.config(font=("Arial", 60))

    knopf1 = Button(fenster, text="START", height=3, width=15, bd=9, fg="green", activeforeground="green", command=start)
    knopf1.place(x=50, y=550)
    knopf1.config(font=("Arial", 60))

    knopf2 = Button(fenster, text="Connect", height=3, width=15, bd=9, fg="green", activeforeground="green", command=connect)
    knopf2.place(x=1050, y=550)
    knopf2.config(font=("Arial", 60))

          
        

    
def connect():
    subprocess.run("/home/pi/mount.sh")
    time.sleep(5)
    if os.path.isfile ("/home/pi/Downloads/download/Connected.txt") & os.path.isdir ("/home/pi/Downloads/nas/Serien"):
        T = Text(fenster, height=1, width=35,bg="lightgrey", fg="green")
        T.pack()
        T.insert(END, "Mit Server verbunden")
        T.place(x=50, y=50)
        T.config(font=("Arial", 60))
        f = open ("/home/pi/movie.txt", "w")
        for subdir, dirs, files in os.walk("/home/pi/Downloads/nas/"):
            for file in files:
                    f.write(file + '\n')





knopf1 = Button(fenster, text="START", height=3, width=15, bd=9, fg="green", activeforeground="green", command=start)
knopf1.place(x=50, y=550)
knopf1.config(font=("Arial", 60))

knopf2 = Button(fenster, text="Connect", height=3, width=15, bd=9, fg="green", activeforeground="green", command=connect)
knopf2.place(x=1050, y=550)
knopf2.config(font=("Arial", 60))


                
                     
if os.path.isfile ("/home/pi/Downloads/download/Connected.txt")& os.path.isdir ("/home/pi/Downloads/nas/Serien"):
    T = Text(fenster, height=1, width=18,bg="lightgrey", fg="green")
    T.pack()
    T.insert(END, "Mit Server verbunden")
    T.place(x=50, y=50)
    T.config(font=("Arial", 60))
    f = open ("/home/pi/movie.txt", "w")
    for subdir, dirs, files in os.walk("/home/pi/Downloads/nas/"):
        for file in files:
                f.write(file + '\n')
    
else:
    T = Text(fenster, height=1, width=18,bg="lightgrey", fg="red")
    T.pack()
    T.insert(END, "Mit Server Verbinden")
    T.place(x=50, y=50)
    T.config(font=("Arial", 60))



Wenn ich die Zeile im Terminal eingebe, ohne die ' dann funktionierts.
Also:

Code: Alles auswählen

/home/pi/handbrake/HandBrake-1.0.2/build/HandBrakeCLI -i /dev/dvd -o /home/pi/Downloads/download/JARHEAD.mkv -X 1920 -x264 -b 2048 -audio-lang-list deu,ger --all-audio --subtitle-lang-list deu,ger --all-subtitle -E ac3 -B 320 -s 1 -m -O

SORRY! - - Ich habs!

Hab mich bei den Optionen verhauen "--audio-lang-list" nicht "-audio-lang-list" und das -s 1 musste raus.

Jetzt wärs noch prima wenn mir wer erklären könnte wie ich die ausgaben vom subprocess "handbrake" in das textfeld "dvdtext" bekomme.

Danke!

Re: Probleme mit process.run

Verfasst: Samstag 11. November 2017, 19:54
von Sirius3
@Angrydad: Du mischst Funktionsdefinitionen mit ausführbarem Code. Das macht das Programm schwer lesbar. Eingentlich sollte auf oberster Ebene gar kein Code stehen und alls in einer Funktions namens »main« stehen, die Du ganz unten einfach aufrufst. *-Importe vermeiden, da Du nicht kontrollieren kannst, was da alles in Deinen Namensraum geladen wird. Bei tkinter werden die Namen üblicherweise über »tk.« angesprochen: »import tkinter as tk«. »os.path« muß man nicht explizit importieren, das macht »os« schon für Dich. Warum machst Du die VIDEO_TS-Prüfung in »get_dvd_title« in zwei Schleifen? Das geht übersichtlicher in einer.

Statt mit place ständig neue Text-Felder übereinander zu zeichnen, solltest Du das Fenster einmal aufbauen, (nicht mit place sonder mit grid oder pack) und den Inhalt bei Bedarf später anpassen.

Um zwei Wahrheitswerte zu verknüpfen benutzt man »and« und nicht »&«. Dann sind da noch ein paar Zeilen einfach kopiert, statt eine Funktion zu schreiben. Dateien die man öffnet sollte man auch wieder schließen, vor allem, wenn Du etwas hineinschreibst.

Re: Probleme mit process.run

Verfasst: Sonntag 12. November 2017, 16:50
von Angrydad
Hallo!

@Sirius3

Hab mich heute nochmal hingesetzt und versucht das nach deinen Vorschlägen schöner zu machen.

Jetzt hab ich immer noch das Problem das beim ausführen von "rip" mein script steht und ich die ausgabe da nicht raus bekomme.

Kannst du mir da bitte helfen?
Besten dank!


Code: Alles auswählen

import os
import tkinter as tk
import re
import subprocess
import sys


def main():

    root = tk.Tk()
    root.title("Jack the Ripper ;-)")
    root.geometry("1920x1080")

    ausgabeo = tk.Label(root)
    ausgabeo.place(x=50, y=50)
    ausgabeo.config(font=("Arial", 60))

    ausgabeu = tk.Label(root)
    ausgabeu.place(x=50, y=250)
    ausgabeu.config(font=("Arial", 80))

    buttonl = tk.Button(root, height=3, width=15, bd=9, fg="green", activeforeground="green",)
    buttonl.config(font=("Arial", 60))
    buttonl.place(x=50, y=550)

    buttonr = tk.Button(root, height=3, width=15, bd=9, fg="green", activeforeground="green",)
    buttonr.config(font=("Arial", 60))
    buttonr.place(x=1050, y=550)


    def get_dvd_title():
        vols = os.listdir('/media/pi')
        candidates = list()
        for vol in vols:
            if vol.startswith('.'):
                continue
            candidates.append(vol)
        if len(candidates) > 0:
            for vol in candidates:
                dirs = os.listdir('/media/pi/' + vol)
                if 'VIDEO_TS' in dirs:
                    return vol

    def next_dvd():
        ausgabeo.config(text="Bitte nächste DVD einlegen", fg="green")
        buttonl.config(text="START", command=start)
        buttonr.config(text="Verbinden", command=vh)



    def rip():
        outfile= '%s/%s.mkv' % ('/home/pi/Downloads/download', get_dvd_title())
        ausgabeo.config(text="Film wird gerippt", fg="green")
        subprocess.call(["/home/pi/handbrake/HandBrake-1.0.2/build/HandBrakeCLI", '-i', '/dev/dvd', '-o', outfile, '-X', '1920', '-e', 'x264', '-b', '2048', '--audio-lang-list', 'deu,ger', '--all-audio', '--subtitle-lang-list', 'deu,ger', '--all-subtitle', '-E', 'ac3', '-B', '320', '-m', '-O'])
        next_dvd()

    


    
    def start():
        text= open('/home/pi/movie.txt').read()
        my_regex=r'^.*' + re.escape (get_dvd_title()) + '.*$'
        if re.search(get_dvd_title(), text, re.I):
            ausgabeu.config(text=re.findall(my_regex,text,re.I|re.M), fg="red")
            ausgabeo.config(text="Ist das der Film?", fg="red")
            buttonl.config(text="Ja", command=next_dvd)
            buttonr.config(text="Nein", command=rip)

    buttonl.config(text="START", command=start)

    


    def vh(): # ordner mounten, prüfen, und vorhandene Filme einlesen
        subprocess.run("/home/pi/mount.sh")
        if os.path.isfile ("/home/pi/Downloads/download/Connected.txt") and os.path.isdir ("/home/pi/Downloads/nas/Serien"):
            ausgabeo.config(text="Mit Server verbunden", fg="green")
            f = open ("/home/pi/movie.txt", "w")
            for subdir, dirs, files in os.walk("/home/pi/Downloads/nas/"):
                for file in files:
                    f.write(file + '\n')
            f.close()


    buttonr.config(text="Verbinden", command=vh)




        #prüfen ob ein und ausgabe Ordner vorhanden sind
    if os.path.isfile ("/home/pi/Downloads/download/Connected.txt") and os.path.isdir ("/home/pi/Downloads/nas/Serien"):
        ausgabeo.config(text="Mit Server verbunden", fg="green")
    else:
        ausgabeo.config(text="Mit Server verbinden", fg="red")


main()