-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedia_work_queue.py
More file actions
166 lines (134 loc) · 4.76 KB
/
Copy pathmedia_work_queue.py
File metadata and controls
166 lines (134 loc) · 4.76 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import sys
import os
import subprocess
import shutil
import logging
from pushbullet import Pushbullet
import media_work_queue_enums as enums
import config_helper as config
import convertMKV
import zip_files
##############################
# Logging
##############################
logger = logging.getLogger('media_work_queue')
logger.setLevel(logging.DEBUG)
# Formatter
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s: %(message)s')
# File Handler
file_handler = logging.FileHandler(config.ConfigSectionMap("LOGGER")['logfile'])
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
# Console Handler
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(console_handler)
##############################
# Pushbullet
##############################
message_title = config.ConfigSectionMap("PUSHBULLET")['defaultmessagetitle']
api_key = config.ConfigSectionMap("PUSHBULLET")['apikey']
push_bullet = None
if config.ConfigSectionMap("PUSHBULLET")['enabled'] == 'true':
push_bullet = Pushbullet(api_key)
##############################
# Enums
##############################
VideoType = enums.VideoType
##############################
# Helpers
##############################
TV = VideoType.tv
MOVIE = VideoType.movie
failures = ''
def add_failure(message):
global failures
failures = '{} \n - {}'.format(failures, message)
def convert_and_zip(type, name, path):
try:
description = 'convert {} and zip'.format(name)
logger.info('Starting: {}'.format(description))
convert(type, name, path)
zip(name, path)
logger.info('Finished: {}'.format(description))
except Exception as e:
logger.error('Failed to {}. Failed with Error: {}'.format(description, e))
def unzip_and_convert(type, name, path):
try:
description = 'unzip {} and convert'.format(name)
logger.info('Starting: {}'.format(description))
unzip(name, path)
convert(type, name, path)
logger.info('Finished: {}'.format(description))
except Exception as e:
logger.error('Failed to {}. Failed with Error: {}'.format(description, e))
def convert(type, name, path):
try:
description = 'convert {}'.format(name)
logger.info('Starting: {}'.format(description))
convertMKV.convert(type, path)
logger.info('Finished: {}'.format(description))
except Exception as e:
add_failure(description)
logger.error('Failed to {}. Failed with Error: {}'.format(description, e))
def zip(name, path):
try:
description = 'zip {}'.format(name)
logger.info('Starting: {}'.format(description))
zip_files.zip(path)
logger.info('Finished: {}'.format(description))
except Exception as e:
add_failure(description)
logger.error('Failed to {}. Failed with Error: {}'.format(description, e))
def unzip(name, path):
try:
description = 'unzip {}'.format(name)
logger.info('Starting: {}'.format(description))
zip_files.unzip(path)
logger.info('Finished: {}'.format(description))
except Exception as e:
add_failure(description)
logger.error('Failed to {}. Failed with Error: {}'.format(description, e))
def unzip_rar(type, name, path):
try:
description = 'unzipping rar {}'.format(name)
logger.info('Starting: {}'.format(description))
zip_files.unzip_rar(type, path)
logger.info('Finished: {}'.format(description))
except Exception as e:
add_failure(description)
logger.error('Failed to {}. Failed with Error: {}'.format(description, e))
def push_note(title, body):
if push_bullet is not None:
push_bullet.push_note(title, body)
##############################
# Start Here
##############################
push_note(message_title, "Starting Queue")
convert_and_zip(MOVIE, 'The Jungle Book', 'G:\Media\Movies\The Jungle Book')
convert_and_zip(MOVIE, 'The Legend of Tarzan', 'G:\Media\Movies\The Legend of Tarzan')
convert_and_zip(MOVIE, 'X-Men Apocalypse', 'G:\Media\Movies\X-Men Apocalypse')
convert_and_zip(TV, 'Downton Abbey', 'G:\Media\TV\Downton Abbey')
convert_and_zip(TV, 'Firefly', 'G:\Media\TV\Firefly')
convert_and_zip(TV, 'Moonlight', 'G:\Media\TV\Moonlight')
convert_and_zip(TV, 'Wonderfalls', 'G:\Media\TV\Wonderfalls')
name = "3rd Rock from the Sun"
path = 'G:\Media\TV\3rd Rock from the Sun'
convert(TV, name, path)
name = "Doctor Who"
path = 'G:\Media\TV\Doctor Who'
unzip_and_convert(TV, name, path)
name = 'Rar_unzip Farscape'
path = 'G:\Media\TV\Farscape\Farscape'
rar_unzip(TV, name, path)
##############################
# Log Failures
##############################
if failures == '':
push_note(message_title, "Queue completed successfully!")
logger.info("Queue completed successfully.")
else:
push_note(message_title, "Queue completed with errors.")
logger.info("Queue completed with errors. The following jobs did not complete successfully: {}".format(failures))