-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpwebConvertor.py
79 lines (58 loc) · 2.32 KB
/
vpwebConvertor.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'kovtash'
import ffmpegConvertor,glob,os,sys,AtomicParsley
if sys.platform == 'darwin':
SOURCE_DIR = '/Users/kovtash/vpweb/complete'
ENCODED_DIR = '/Users/kovtash/vpweb/encoded'
TAGGED_DIR = '/Users/kovtash/vpweb/tagged'
elif sys.platform == 'linux2':
SOURCE_DIR = '/hd0/ds0/Library/vpweb/complete'
ENCODED_DIR = '/hd0/ds0/Library/vpweb/encoded'
TAGGED_DIR = '/hd0/ds0/iTunes Media/Automatically Add to iTunes.localized'
class vpwebConvertor():
def __init__(self,sourceDir,encodedDir,taggedDir):
self._sourceDir=sourceDir
self._encodedDir=encodedDir
self._taggedDir=taggedDir
#init working directories
if not os.path.exists(self._encodedDir):
os.makedirs(self._encodedDir)
if not os.path.exists(self._taggedDir):
os.makedirs(self._taggedDir)
@property
def filesForConvert(self):
return glob.glob(os.path.join(self._sourceDir,'*'))
@property
def filesForSetTags(self):
return glob.glob(os.path.join(self._encodedDir,'*'))
def convertVideo(self,sourcePath):
filename=os.path.splitext(os.path.basename(sourcePath))[0]+"."+ffmpegConvertor.ITUNES_MEDIA_PRESET.format
destinationPath=os.path.join(self._encodedDir,filename)
result = ffmpegConvertor.videoConvert(sourcePath,ffmpegConvertor.ITUNES_MEDIA_PRESET,destination=destinationPath)
if result:
os.remove(sourcePath)
def setVideoTags(self,sourcePath):
destinationPath=os.path.join(self._taggedDir,os.path.basename(sourcePath))
tags=AtomicParsley.AtomicParsley(sourcePath)
result = tags.setTags()
if result:
os.rename(sourcePath,destinationPath)
def process(self):
for file in self.filesForConvert:
self.convertVideo(file)
for file in self.filesForSetTags:
self.setVideoTags(file)
if __name__ == "__main__":
try:
import socket
s = socket.socket()
host = socket.gethostname()
port = 35637 #make sure this port is not used on this system
s.bind((host, port))
except:
#pass
print "Already running. Exiting."
sys.exit(0)
test = vpwebConvertor(SOURCE_DIR,ENCODED_DIR,TAGGED_DIR)
test.process()