Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added rip and transcode functions using MakeMKV and HandBrake respect…

…ively
  • Loading branch information...
commit 6ab2746b4971c07f38f9f2d6741958453da0c205 1 parent 7a80a6b
@beatgammit authored
Showing with 40 additions and 69 deletions.
  1. +1 −5 README.md
  2. +39 −64 rip.py
View
6 README.md
@@ -4,8 +4,4 @@ AutoMovieArchive
![Alt text](images/PertChart.png "Pert Chart")
-WMI support
------------
-
-WMI support is enabled by default on most recent versions of Windows. To get support in Python, install the [wrapper library](http://timgolden.me.uk/python/wmi/index.html).
-After that, *detector.py* should work as expected: run *detector.py* then insert or remove a drive.
+All python code included is designed to work with IronPython on Windows.
View
103 rip.py
@@ -1,65 +1,40 @@
-#!/usr/bin/env python
-import subprocess
-import sys
-import re
-
-def parseMetadata(devicePath):
- args = ['HandBrakeCLI', '-i', devicePath, '-t', '0']
- print("Running:" + ' '.join(args))
- p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-# p = subprocess.Popen(['HandBrakeCLI', '-i', '/dev/sr0', '-o', 'strange--brew.mp4', '-f', 'mp4', '-e', 'x264'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-
- def byline():
- while p.poll() is None:
- yield p.stdout.readline().decode('utf-8')
-
- redvdtitle = re.compile('DVD Title: ([A-Z_]+)')
- retitle = re.compile('^\+ title (\d+):')
- reduration = re.compile('^\s+\+ duration: (\d+):(\d+):(\d+)')
-
-
- dvdtitle = None
- for line in byline():
- m = redvdtitle.search(line)
- if m:
- dvdtitle = m.group(1)
- break
-
- titles = list()
- tTitle = None
- for line in byline():
- if lookingForTitle:
- m = retitle.search(line)
- if m:
- tTitle = {'title': m.group(1)}
- lookingForTitle = False
- lookingForDuration = True
- continue
-
- if lookingForDuration:
- m = reduration.search(line)
- if m:
- hours, minutes, seconds = [int(x, 10) for x in m.group(1, 2, 3)]
- tTitle['duration'] = hours*3600 + minutes*60 + seconds
- titles.append(tTitle)
- lookingForDuration = False
- lookingForTitle = True
- continue
-
- feature = max(titles, key=lambda x: x['duration'])
-
- return dvdtitle, feature['title']
-
-def rip(out, src, track=1):
- ret = subprocess.call(['HandBrakeCLI', '-i', src, '-o', out, '-f', 'mp4', '-e', 'x264', '-t', str(track)], stdout=sys.stdout, stderr=sys.stderr)
- if ret != 0:
- print("Error ripping DVD")
+from System.Diagnostics import Process
+from System.IO import Path, Directory
+
+def transcode(mkvFile, movieName):
+ p = Process()
+ p.StartInfo.UseShellExecute = False
+ #p.StartInfo.RedirectStandardOutput = True
+ p.StartInfo.FileName = "HandBrakeCLI"
+ p.StartInfo.Arguments = "-i %s -o %s.mp4 -f mp4 -e x264" % (mkvFile, movieName)
+ if p.Start():
+ print("Transcoding")
+ p.WaitForExit()
+ if p.ExitCode == 0:
+ print("Successfully transcoded %s" % movieName)
+ else:
+ print("Error: %d" % p.ExitCode)
else:
- print("Done!")
-
-print('Getting info from disk')
-title, track = parseMetadata('/dev/sr0')
-
-title = title.replace("_", " ").title()
-print("Ripping %s. This may take a while:" % title)
-rip(title+".mp4", '/dev/sr0', track)
+ print("Error transcoding, quitting")
+
+def rip(driveLetter, movieName):
+ out = Path.Combine(Path.GetTempPath(), movieName)
+ p = Process()
+ p.StartInfo.UseShellExecute = False
+ #p.StartInfo.RedirectStandardOutput = True
+ p.StartInfo.FileName = "makemkvcon"
+ p.StartInfo.Arguments = "--minlength=300 mkv disc:0 all %s" % out
+ print("Saving to:", out)
+ print(p.StartInfo.Arguments)
+ if p.Start():
+ print("Ripping")
+ p.WaitForExit()
+ if p.ExitCode == 0:
+ print("Successfully ripped %s" % movieName)
+
+ movieMkv = Directory.GetFiles(out)[0]
+ transcode(movieMkv, movieName)
+ else:
+ print("Error: %d" % p.ExitCode)
+ else:
+ print("Error ripping, quitting")
Please sign in to comment.
Something went wrong with that request. Please try again.