Skip to content

Commit

Permalink
docs: improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
3h4x committed Jul 17, 2022
1 parent 63e4d80 commit a6aa7ec
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 70 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

*.mkv
*.mp4
*.ini
.google-cookie
**/*.pyc
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,33 @@

## What it does

## Getting Started
Running `./organizer.py` will show possible commands and flags:
```
Usage: organizer.py [OPTIONS] COMMAND [ARGS]...
### Prerequisites
What things you need to run the program:
- At least Python 3.8
- Install requirements `pip install -r requirements.txt`
Rename Media Files
Options:
--help Show this message and exit.
Commands:
movies Rename Movies
series Rename TV Series
```
Currently renaming movies and series is supported.

Help for series:
```
Usage: organizer.py series [OPTIONS]
Rename TV Series
Options:
-p, --path TEXT Path
-f, --force Automatically rename
--help Show this message and exit.
```

### Features
- Movies are renamed and organized in format:
```
<Movie_name> (<year>)/<Movie_name> (<year>)
Expand All @@ -28,13 +47,20 @@ What things you need to run the program:
<TV_Series_name>/S<Season_number>/S<Season_number>E<Episode_Number>
```

## Getting Started

### Prerequisites
What things you need to run the program:
- At least Python 3.8
- Install requirements `pip install -r requirements.txt`

### Development

- `pre-commit install --hook-type commit-msg`

<p align="center">
Made with ❤️ by <a href="https://github.com/3h4x">3h4x</a>
Based on work of <a href="https://github.com/bearlike">bearlike</a>
Made with ❤️ by <a href="https://github.com/3h4x">3h4x</a></br>
Loosely based on work of <a href="https://github.com/bearlike">bearlike</a>
</p>

![wave](http://cdn.thekrishna.in/img/common/border.png)
8 changes: 4 additions & 4 deletions src/main.py → src/organizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ def main(ctx):
@main.command(help="Rename Movies")
@click.option("--path", "-p", help="Path", default=".")
@click.option(
"--default", help="Should default answer for renaming be True",
default=True
"--default", help="Should default answer for renaming be True", default=True
)
def movies(path, default):
rename_movies(path, default)


@main.command(help="Rename TV Series")
@click.option("--path", "-p", help="Path", default=".")
def series(path):
rename_series(path)
@click.option("--force", "-f", help="Automatically rename", is_flag=True, default=False)
def series(path, force):
rename_series(path, force)


if __name__ == "__main__":
Expand Down
114 changes: 58 additions & 56 deletions src/rename_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,63 +84,65 @@ def AddZero(inputString):
return inputString


def rename_series(path):
def rename_series(path, force):
click.echo("Reading Files....")

for (dirpath, _, _) in os.walk(path):
files = os.listdir(dirpath)
for file in files:
_, file = os.path.split(file)
file_name, extension = os.path.splitext(file)

if extension not in [".mp4", ".mkv", ".srt", ".avi", ".wmv"]:
continue

unwanted_stuff = [
".1080p",
".720p",
"HDTV",
"x264",
"AAC",
"E-Subs",
"ESubs",
"WEBRip",
"WEB",
"BluRay",
"Bluray",
]
for stuff in unwanted_stuff:
file_name = file_name.replace(stuff, "")
file_name = file_name.replace(".", " ")

season, episode = get_season_episode(file_name)
if not (season and episode):
click.secho(f'No Season/Episode found in "{file_name}"', fg="red")
continue

file_name = sanitize_name(file_name)
series = main_imdb(file_name)
if not series:
click.secho(f'Couldnt find imdb series for "{file_name}"', fg="yellow")
continue

file_name = find_most_apt(file_name, series)
file_name = removeIllegal(file_name).strip()
Final = f"SE{season}EP{episode} - {file_name}{extension}"

path_output = os.path.join(file_name, f"Season {season}") # type: ignore

subprocess.check_call(f'mkdir -p "{path_output}"', cwd=path, shell=True)

try:
if click.confirm(f'Rename "{file}" to "{Final}"?', default=True):
# cross device mv
subprocess.check_call(
f'mv "{file}" "{os.path.join(path_output, Final)}"',
cwd=path,
shell=True,
)
except FileExistsError:
print(f"Error - File Already Exist: {Final}")
files = os.listdir(path)
for file in files:
_, file = os.path.split(file)
file_name, extension = os.path.splitext(file)

if extension not in [".mp4", ".mkv", ".srt", ".avi", ".wmv"]:
continue

unwanted_stuff = [
".1080p",
".720p",
"HDTV",
"x264",
"AAC",
"E-Subs",
"ESubs",
"WEBRip",
"WEB",
"BluRay",
"Bluray",
]
for stuff in unwanted_stuff:
file_name = file_name.replace(stuff, "")
file_name = file_name.replace(".", " ")

season, episode = get_season_episode(file_name)
if not (season and episode):
click.secho(f'No Season/Episode found in "{file_name}"', fg="red")
continue

file_name = sanitize_name(file_name)
import ipdb

ipdb.set_trace()
series = main_imdb(file_name)
if not series:
click.secho(f'Couldnt find imdb series for "{file_name}"', fg="yellow")
continue

file_name = find_most_apt(file_name, series)
file_name = removeIllegal(file_name).strip()
Final = f"SE{season}EP{episode} - {file_name}{extension}"

path_output = os.path.join(file_name, f"Season {season}") # type: ignore

subprocess.check_call(f'mkdir -p "{path_output}"', cwd=path, shell=True)

try:
if force or click.confirm(f'Rename "{file}" to "{Final}"?', default=True):
# cross device mv
subprocess.check_call(
f'mv "{file}" "{os.path.join(path_output, Final)}"',
cwd=path,
shell=True,
)
except FileExistsError:
print(f"Error - File Already Exist: {Final}")

click.echo("All Files Processed...")

0 comments on commit a6aa7ec

Please sign in to comment.