GithubHelp home page GithubHelp logo

vpistis / organizemediafiles Goto Github PK

View Code? Open in Web Editor NEW
30.0 2.0 2.0 102 KB

a collection of Python scripts that help you organize media files into a directory tree "year/month" based on metadata , using exiftool

License: MIT License

Python 100.00%
nextcloud exiftool video python-script sort-media-files sort-images sort-photos sort-videos organize-media-files python

organizemediafiles's Introduction

OrganizeMediaFiles Alpha

This project is a collection of Python scripts that help to organize media files into a directory tree "year/month" based on file metadata, using exiftool

Used by me into my personal Nextcloud installation to organize unsorted files. Strongly inspired by: https://github.com/OneLogicalMyth/Random-Scripts/blob/master/NextCloud/SortPictures.py

Tested with Linux/Debian and MacOS python 2 and 3

ATTENTION alpha version backup your files before use!

This picture describe the final result: final result

Features

  • manages duplicate files due to milliseconds difference (the new file uses the same old name).
  • support all file types supported by exiftool
  • proccess video and photo at same time (see config.json)
  • if exists, add sub second time original (fraction of seconds) to file name

Getting OrganizeMediaFiles:

Clone the repository: git clone https://github.com/vpistis/OrganizeMediaFiles.git. Alternatively download tarball or zip. There haven't been any releases yet.

Installation

No installation required, it's a simple python script :) It run in python.

Requirements

In order to use the script, is necessary install at least exiftool. Also install all requirements.txt

Debian based

sudo apt-get install exiftool

MacOS

brew install exiftool

Usage

Step 1: configuration

Configure using config.json

Step 2: run

python organize_media_files.py

Configuration

Important: process only photo/video files with specified extensions. Use the config.json to change paths and other stuff.

All paths are intended without any escaping char,like backslashes

LOG_LEVEL

Default: "LOG_LEVEL": "INFO" Log files are in the source directory

LOG_PATH

Default: "LOG_DIR": "/tmp". If not specified use this directory. If you cannot write into this path, maybe the best choice is to use /tmp

RENAME_SORTED_FILES

Default: "RENAME_SORTED_FILES": false. If true rename sorted files according to metadata creation time. See DATE_FORMAT_OUTPUT for the name of new file.

REMOVE_OLD_FILES

Default: "REMOVE_OLD_FILES": false. If true delete old file after creation of new processed file.

APPEND_ORIG_FILENAME

Default: "APPEND_ORIG_FILENAME": false. If true append the original file name at the end of new created file.

REMOVE_SPACE_FROM_FILENAME

Default: "REMOVE_SPACE_FROM_FILENAME": true. Sometimes some space remains into filename, i want to replace it with underscores: _

DATE_FORMAT_OUTPUT

Default: "DATE_FORMAT_OUTPUT": "%Y%m%d_%H%M%S". The date output string in python used to name the new created file. Used only if RENAME_SORTED_FILE=true.

PROCESS_IMAGES

Default: "PROCESS_IMAGES": true. If true process image files according to the IMAGE_FILES_EXTENSIONS.

IMAGE_FILENAME_SUFFIX

Default: "IMAGE_FILENAME_SUFFIX": "IMG_". Prepend this string to the new created file name.

IMAGES_SOURCE_PATH

Default: "IMAGES_SOURCE_PATH": "/media/drivemount/user/files/FilesToSort". The path where original image files are stored.

IMAGES_DESTINATION_PATH

Default: "IMAGES_DESTINATION_PATH": "/media/drivemount/user/files/FilesSorted". The root path where store the new organized image files.

IMAGE_FILES_EXTENSIONS

Default: "IMAGE_FILES_EXTENSIONS": [".jpg",".gif",".tiff"]. Files with these extensions are processed as images (NOTE: exiftool support internally many file types, and the command used in this script is the same for images/videos)

PROCESS_VIDEOS

Default: "PROCESS_VIDEOS": false. If true process video files according to the VIDEO_FILES_EXTENSIONS.

VIDEO_FILENAME_SUFFIX

Default: "VIDEO_FILENAME_SUFFIX": "VID_". Prepend this string to the new created file name.

VIDEOS_SOURCE_PATH

Default: "VIDEOS_SOURCE_PATH": "/media/drivemount/user/files/FilesToSort" The path where original video files are stored.

VIDEOS_DESTINATION_PATH

Default: "VIDEOS_DESTINATION_PATH": "/media/drivemount/user/files/FilesSorted". The root path where store the new organized video files.

VIDEO_FILES_EXTENSIONS

Default: "VIDEO_FILES_EXTENSIONS": [".mp4",".3gp"]. Files with these extensions are processed as videos see IMAGE_FILES_EXTENSIONS note.

NEXTCLOUD

Default: "NEXTCLOUD": false. If true exec nextcloud command to rescan data directory for new files.

NEXTCLOUD_PATH

Default: "NEXTCLOUD_PATH": "/var/www/html/nextcloud". The path of nextcloud installation.

NEXTCLOUD_USER

Default: "NEXTCLOUD_USER": "www-data" Launch nextcloud scan command as a "NEXTCLOUD_USER".

LICENSE

MIT License

Copyright (c) 2017-2023 Valentino Pistis

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.

organizemediafiles's People

Contributors

eyvpistis avatar vpistis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rosbeef vspaziani

organizemediafiles's Issues

Error on Start

  1. i am logged in as root (sudo) (ubuntu 20.04)
  2. all files are located at: /root/scripts/OrganizeMediaFiles/src
  3. I've modified the config as suggested

`{
"LOG_FILE": "/root/scripts/OrganizeMediaFiles/src/log.log",
"RENAME_SORTED_FILES": true,
"REMOVE_OLD_FILES": false,
"APPEND_ORIG_FILENAME": false,
"DATE_FORMAT_OUTPUT": "%Y%m%d_%H%M%S",

"PROCESS_IMAGES": true,
"IMAGE_FILENAME_SUFFIX": "IMG_",
"IMAGES_SOURCE_PATH": "/mnt/Data1/Photos",
"IMAGES_DESTINATION_PATH": "/mnt/Data1/Images",
"IMAGE_FILES_EXTENSIONS": [
".jpg",
".gif",
".tiff",
".jpeg",
".png"
],

"PROCESS_VIDEOS": false,
"VIDEO_FILENAME_SUFFIX": "VID_",
"VIDEOS_SOURCE_PATH": "/media/drivemount/user/files/FilesToSort",
"VIDEOS_DESTINATION_PATH": "/media/drivemount/user/files/FilesSorted",
"VIDEO_FILES_EXTENSIONS": [
".mp4",
".3gp"
],

"NEXTCLOUD": false,
"NEXTCLOUD_PATH": "/var/www/html/nextcloud",
"NEXTCLOUD_USER": "www-data"
}`

  1. when I start the script as follows: python organize_media_files.py

I receive the following error:

BASE DIR: /root/scripts/OrganizeMediaFiles/src Traceback (most recent call last): File "organize_media_files.py", line 24, in <module> sys.stdout = Logger() File "/root/scripts/OrganizeMediaFiles/src/utils.py", line 64, in __init__ self.log = open(get_setting("LOG_FILE"), "a") File "/root/scripts/OrganizeMediaFiles/src/utils.py", line 28, in get_setting raise Exception("Some error occurred: ", e) Exception: ('Some error occurred: ', IOError(2, 'No such file or directory'))

I am a bit confused as all path are existing.

Do you have any idea?

error in config.json.example

Thanks so much for putting this together. I cloned your repository but noticed that there is an error in the config.json.example

Line 7: "REMOVE_SPACE_FROM_FILENAME": true is missing a comma after it. I modified my copy and it ran successfully afterward.

multi source path and multi destination path

Add the possibility to process files stored into different paths and then organize it into a specific destination, example: process files from SRC_1 and organize to DEST_1, process files from SRC_2 and organize to DEST_2...

Ubuntu 16.04 Server with Nextcloud

Hey,

I want to sort my Media Files with your script, but I get an Traceback:
Python: 3.5.2

Traceback (most recent call last):
File "/home/dennis/OrganizeMediaFiles/src/organize_media_files.py", line 24, in
sys.stdout = Logger()
File "/home/dennis/OrganizeMediaFiles/src/utils.py", line 62, in init
self.log = open(get_setting("LOG_FILE"), "a")
File "/home/dennis/OrganizeMediaFiles/src/utils.py", line 20, in get_setting
config_json = json.loads(f.read())
File "/usr/lib/python3.5/json/init.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 10 column 72 (char 311)

I run it with root: 'python3 organize_media_files.py'
Sorry, but I'm a noob in python!

create configuration file

Create config file:

  • to store video and audio variables
  • to manage differents source and destination folders for photo and video
  • to configure process photo and video at same time

multi source path

add the possibility to write more than one source path into config file. The script search into these paths, process images and move theme into destination path

relative import

solve the relative import error for utils:

from .utils import Logger, get_setting, which
SystemError: Parent module '' not loaded, cannot perform relative import

ValueError: Attempted relative import in non-package

Getting this error when running organize_media_files.py with python on both Debian 10 and macOS 10.15

Traceback (most recent call last): File "organize_media_files.py", line 22, in <module> from .utils import Logger, get_setting, which ValueError: Attempted relative import in non-package

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.