-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sync-missing-metadata command with docs, resolves #25
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# TubeSync | ||
|
||
## Advanced usage guide - creating missing metadata | ||
|
||
This is a new feature in v0.9 of TubeSync and later. It allows you to create or | ||
re-create missing metadata in your TubeSync download directories for missing `nfo` | ||
files and thumbnails. | ||
|
||
If you add a source with "write NFO files" or "copy thumbnails" disabled, download | ||
some media and then update the source to write NFO files or copy thumbnails then | ||
TubeSync will not automatically retroactively attempt to copy or create your missing | ||
metadata files. You can use a special one-off command to manually write missing | ||
metadata files to the correct locations. | ||
|
||
## Requirements | ||
|
||
You have added a source without metadata writing enabled, downloaded some media, then | ||
updated the source to enable metadata writing. | ||
|
||
## Steps | ||
|
||
### 1. Run the batch metadata sync command | ||
|
||
Execute the following Django command: | ||
|
||
`./manage.py sync-missing-metadata` | ||
|
||
When deploying TubeSync inside a container, you can execute this with: | ||
|
||
`docker exec -ti tubesync python3 /app/manage.py sync-missing-metadata` | ||
|
||
This command will log what its doing to the terminal when you run it. | ||
|
||
Internally, this command loops over all your sources which have been saved with | ||
"write NFO files" or "copy thumbnails" enabled. Then, loops over all media saved to | ||
that source and confirms that the appropriate thumbnail files have been copied over and | ||
the NFO file has been written if enabled. |
34 changes: 34 additions & 0 deletions
34
tubesync/sync/management/commands/sync-missing-metadata.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
from shutil import copyfile | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.db.models import Q | ||
from common.logger import log | ||
from sync.models import Source, Media | ||
from sync.utils import write_text_file | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
help = 'Syncs missing metadata (such as nfo files) if source settings are updated' | ||
|
||
def handle(self, *args, **options): | ||
log.info('Syncing missing metadata...') | ||
sources = Source.objects.filter(Q(copy_thumbnails=True) | Q(write_nfo=True)) | ||
for source in sources.order_by('name'): | ||
log.info(f'Finding media for source: {source}') | ||
for item in Media.objects.filter(source=source, downloaded=True): | ||
log.info(f'Checking media for missing metadata: {source} / {item}') | ||
thumbpath = item.thumbpath | ||
if not thumbpath.is_file(): | ||
if item.thumb: | ||
log.info(f'Copying missing thumbnail from: {item.thumb.path} ' | ||
f'to: {thumbpath}') | ||
copyfile(item.thumb.path, thumbpath) | ||
else: | ||
log.error(f'Tried to copy missing thumbnail for {item} but ' | ||
f'the thumbnail has not been downloaded') | ||
nfopath = item.nfopath | ||
if not nfopath.is_file(): | ||
log.info(f'Writing missing NFO file: {nfopath}') | ||
write_text_file(nfopath, item.nfoxml) | ||
log.info('Done') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters