-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
65 lines (49 loc) · 1.8 KB
/
app.py
File metadata and controls
65 lines (49 loc) · 1.8 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
import logging
import os
import sys
from time import sleep
import schedule
from dotenv import load_dotenv
from builders.movie_path_builder import MoviePathBuilder
from builders.path_builder_factory import PathBuilderFactory
from builders.tv_show_path_builder import TvShowPathBuilder
from clients.qbittorrent_client import QBitTorrentClient
from clients.torrent_client_factory import TorrentClientFactory
from constants import Constants
load_dotenv()
def configLogging():
import time
logging.getLogger().setLevel(logging.INFO)
logging.getLogger('requests').setLevel(logging.WARNING)
logging.basicConfig(format='{}: GMT: %(asctime)s %(levelname)s %(message)s'.format(os.path.split(sys.argv[0])[1]))
logging.Formatter.converter = time.gmtime
def main():
configLogging()
constants = Constants()
logging.info('Started moving files...')
client = TorrentClientFactory.create(constants, constants.TORRENT_CLIENT_NAME)
if not client:
return
torrents = client.getTorrentsByCategory(constants.TV_SHOWS_CATEGORY) + \
client.getTorrentsByCategory(constants.MOVIES_CATEGORY)
# move torrents
hasMoved = False
for torrent in torrents:
newPath = PathBuilderFactory.create(constants, torrent)
if not newPath:
continue
if torrent.currentPath != newPath:
hasMoved = True
logging.info(
'Changing location of torrent {} from {} to {}'.format(torrent.name, torrent.currentPath, newPath)
)
client.changeLocation(torrent.id, newPath)
if hasMoved:
logging.info('Moving files done.')
else:
logging.info('Nothing to move.')
if __name__ == '__main__':
schedule.every(1).minutes.do(main)
while True:
schedule.run_pending()
sleep(1)