Init commit with beta of the season Mover script.
This commit is contained in:
102
.gitignore
vendored
Normal file
102
.gitignore
vendored
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
.hypothesis/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# celery beat schedule file
|
||||||
|
celerybeat-schedule
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017 Kevin
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
86
seasonMover.py
Executable file
86
seasonMover.py
Executable file
@@ -0,0 +1,86 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Author: KevinMidboe
|
||||||
|
# @Date: 2017-07-11 19:16:23
|
||||||
|
# @Last Modified by: kevinmidboe
|
||||||
|
# @Last Modified time: 2017-08-05 16:47:03
|
||||||
|
|
||||||
|
import fire, re, os
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
class seasonMover(object):
|
||||||
|
''' Moving multiple files to multiple folders with
|
||||||
|
identifer '''
|
||||||
|
workingDir = os.getcwd()
|
||||||
|
mediaExt = ['mkv', 'mp4']
|
||||||
|
subExt = ['srt']
|
||||||
|
|
||||||
|
def create(self, name, interval):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def move(self, fileSyntax, folderName):
|
||||||
|
episodeRange = self.findInterval(fileSyntax)
|
||||||
|
episodeList = self.getFiles()
|
||||||
|
|
||||||
|
self.motherMover(fileSyntax, folderName, episodeRange)
|
||||||
|
|
||||||
|
|
||||||
|
def getFiles(self):
|
||||||
|
epDir = os.path.join(self.workingDir)
|
||||||
|
dirContent = os.listDir(epDir)
|
||||||
|
fileList = sorted(dirContent)
|
||||||
|
return fileList
|
||||||
|
|
||||||
|
def getEpisodeNumber(self):
|
||||||
|
m = re.search('[eE][0-9]{1,2}', self.parent)
|
||||||
|
if m:
|
||||||
|
return re.sub('[eE]', '', m.group(0))
|
||||||
|
|
||||||
|
def findInterval(self, item):
|
||||||
|
if (re.search(r'\((.*)\)', item) is None):
|
||||||
|
raise ValueError('Need to declare an identifier e.g. (1..3) in: \n\t' + item)
|
||||||
|
|
||||||
|
start = int(re.search('\((\d+)\.\.', item).group(1))
|
||||||
|
end = int(re.search('\.\.(\d+)\)', item).group(1))
|
||||||
|
|
||||||
|
return list(range(start, end+1))
|
||||||
|
|
||||||
|
def removeUploadSign(self, file):
|
||||||
|
match = re.search('-[a-zA-Z\[\]\-]*.[a-z]{3}', file)
|
||||||
|
if match:
|
||||||
|
uploader = match.group(0)[:-4]
|
||||||
|
return re.sub(uploader, '', file)
|
||||||
|
|
||||||
|
return file
|
||||||
|
|
||||||
|
def motherMover(self, fileSyntax, folderName, episodeRange):
|
||||||
|
# Call for sub of fileList
|
||||||
|
# TODO check if range is same as folderContent
|
||||||
|
# print(fileSyntax, folderName, episodeRange)
|
||||||
|
mediaFiles = []
|
||||||
|
subtitleFiles = []
|
||||||
|
seasonDirectory = sorted(os.listdir(os.path.join(self.workingDir)))
|
||||||
|
|
||||||
|
for file in seasonDirectory:
|
||||||
|
if file[-3:] in self.mediaExt:
|
||||||
|
mediaFiles.append(file)
|
||||||
|
elif file[-3:] in self.subExt:
|
||||||
|
subtitleFiles.append(file)
|
||||||
|
|
||||||
|
if (len(mediaFiles) is not len(episodeRange)):
|
||||||
|
raise ValueError('Range defined does not match directory file content')
|
||||||
|
|
||||||
|
for epMedia, epNum in zip(mediaFiles, episodeRange):
|
||||||
|
leadingZeroNumber = "%02d" % epNum
|
||||||
|
fileName = re.sub(r'\((.*)\)', leadingZeroNumber, fileSyntax)
|
||||||
|
oldPath = os.path.join(self.workingDir, epMedia)
|
||||||
|
newFolder = os.path.join(self.workingDir, folderName + leadingZeroNumber)
|
||||||
|
newPath = os.path.join(newFolder, self.removeUploadSign(fileName))
|
||||||
|
|
||||||
|
# os.makedirs(newFolder)
|
||||||
|
# os.rename(oldPath, newPath)
|
||||||
|
print(oldPath + ' --> ' + newPath)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
fire.Fire(seasonMover)
|
||||||
Reference in New Issue
Block a user