Use mediafile instead of beets.mediafile

This commit is contained in:
Labrys of Knossos 2022-12-15 19:40:43 -05:00
commit 5c3de926c1
2 changed files with 12 additions and 11 deletions

View file

@ -6,8 +6,8 @@ import shutil
import stat import stat
import time import time
import beets.mediafile
import guessit import guessit
import mediafile
import nzb2media import nzb2media
from nzb2media import extractor from nzb2media import extractor
@ -19,15 +19,15 @@ from nzb2media.utils.paths import get_dir_size
from nzb2media.utils.paths import make_dir from nzb2media.utils.paths import make_dir
def move_file(mediafile, path, link): def move_file(filename, path, link):
logger.debug( logger.debug(
f'Found file {os.path.split(mediafile)[1]} in root directory {path}.', f'Found file {os.path.split(filename)[1]} in root directory {path}.',
) )
new_path = None new_path = None
file_ext = os.path.splitext(mediafile)[1] file_ext = os.path.splitext(filename)[1]
try: try:
if file_ext in nzb2media.AUDIO_CONTAINER: if file_ext in nzb2media.AUDIO_CONTAINER:
f = beets.mediafile.MediaFile(mediafile) f = mediafile.MediaFile(filename)
# get artist and album info # get artist and album info
artist = f.artist artist = f.artist
@ -38,22 +38,22 @@ def move_file(mediafile, path, link):
path, f'{sanitize_name(artist)} - {sanitize_name(album)}', path, f'{sanitize_name(artist)} - {sanitize_name(album)}',
) )
elif file_ext in nzb2media.MEDIA_CONTAINER: elif file_ext in nzb2media.MEDIA_CONTAINER:
f = guessit.guessit(mediafile) f = guessit.guessit(filename)
# get title # get title
title = f.get('series') or f.get('title') title = f.get('series') or f.get('title')
if not title: if not title:
title = os.path.splitext(os.path.basename(mediafile))[0] title = os.path.splitext(os.path.basename(filename))[0]
new_path = os.path.join(path, sanitize_name(title)) new_path = os.path.join(path, sanitize_name(title))
except Exception as e: except Exception as e:
logger.error( logger.error(
f'Exception parsing name for media file: {os.path.split(mediafile)[1]}: {e}', f'Exception parsing name for media file: {os.path.split(filename)[1]}: {e}',
) )
if not new_path: if not new_path:
title = os.path.splitext(os.path.basename(mediafile))[0] title = os.path.splitext(os.path.basename(filename))[0]
new_path = os.path.join(path, sanitize_name(title)) new_path = os.path.join(path, sanitize_name(title))
# # Removed as encoding of directory no-longer required # # Removed as encoding of directory no-longer required
@ -75,7 +75,7 @@ def move_file(mediafile, path, link):
make_dir(new_path) make_dir(new_path)
newfile = os.path.join( newfile = os.path.join(
new_path, sanitize_name(os.path.split(mediafile)[1]), new_path, sanitize_name(os.path.split(filename)[1]),
) )
try: try:
newfile = newfile.encode(nzb2media.SYS_ENCODING) newfile = newfile.encode(nzb2media.SYS_ENCODING)
@ -83,7 +83,7 @@ def move_file(mediafile, path, link):
pass pass
# link file to its new path # link file to its new path
copy_link(mediafile, newfile, link) copy_link(filename, newfile, link)
def is_min_size(input_name, min_size): def is_min_size(input_name, min_size):

View file

@ -5,6 +5,7 @@ deluge-client@git+https://github.com/labrys/deluge.git@master
guessit guessit
jaraco-windows ; sys.platform == 'win32' jaraco-windows ; sys.platform == 'win32'
linktastic linktastic
mediafile
python-qbittorrent python-qbittorrent
pywin32 ; sys.platform == 'win32' pywin32 ; sys.platform == 'win32'
pyxdg pyxdg