Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to skip photos #392

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/gphotos_sync/BaseMedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def is_video(self) -> bool:
return False
return self.mime_type.startswith("video")

@property
def is_photo(self) -> bool:
if not self.mime_type:
return False
return self.mime_type.startswith("image")

@property
def duplicate_number(self) -> int:
return self._duplicate_number
Expand Down
4 changes: 4 additions & 0 deletions src/gphotos_sync/GoogleAlbumsSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
self.use_start_date = settings.use_start_date
self.favourites = settings.favourites_only
self.include_video = settings.include_video
self.include_photo = settings.include_photo
self._use_flat_path = settings.use_flat_path
self._omit_album_date = settings.omit_album_date
self._album_invert = settings.album_invert
Expand Down Expand Up @@ -98,6 +99,9 @@ def fetch_album_contents(
if (not self.include_video) and media_item.is_video:
log.debug("---- skipping %s (--skip-video)", media_item.filename)
continue
elif (not self.include_photo) and media_item.is_photo:
log.debug("---- skipping %s (--skip-photo)", media_item.filename)
continue

log.debug("----%s", media_item.filename)
self._db.put_album_file(album_id, media_item.id, position)
Expand Down
11 changes: 9 additions & 2 deletions src/gphotos_sync/GooglePhotosIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
self.start_date: datetime = settings.start_date
self.end_date: datetime = settings.end_date
self.include_video: bool = settings.include_video
self.include_photo: bool = settings.include_photo
self.rescan: bool = settings.rescan
self.favourites = settings.favourites_only
self.case_insensitive_fs: bool = settings.case_insensitive_fs
Expand Down Expand Up @@ -77,6 +78,7 @@ def search_media(
start_date: Optional[datetime] = None,
end_date: Optional[datetime] = None,
do_video: bool = False,
do_photo: bool = False,
favourites: bool = False,
) -> dict:
class Y:
Expand All @@ -98,19 +100,22 @@ def to_dict(self):
end = Y(end_date.year, end_date.month, end_date.day)
if not do_video:
type_list = ["PHOTO"]
if not do_photo:
type_list = ["VIDEO"]
if favourites:
feature = "FAVORITES"
else:
feature = "NONE"

if not page_token:
log.info(
"searching for media start=%s, end=%s, videos=%s",
"searching for media start=%s, end=%s, videos=%s, photos=%s",
start_date,
end_date,
do_video,
do_photo,
)
if not start_date and not end_date and do_video and not favourites:
if not start_date and not end_date and do_video and not favourites and not do_photo:
# no search criteria so do a list of the entire library
log.debug("mediaItems.list ...")
return self._api.mediaItems.list.execute( # type: ignore
Expand Down Expand Up @@ -149,6 +154,7 @@ def index_photos_media(self) -> int:
start_date=start_date,
end_date=self.end_date,
do_video=self.include_video,
do_photo=self.include_photo,
favourites=self.favourites,
)

Expand Down Expand Up @@ -213,6 +219,7 @@ def index_photos_media(self) -> int:
start_date=start_date,
end_date=self.end_date,
do_video=self.include_video,
do_photo=self.include_photo,
favourites=self.favourites,
)
else:
Expand Down
8 changes: 7 additions & 1 deletion src/gphotos_sync/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def __init__(self):
parser.add_argument(
"--skip-video", action="store_true", help="skip video types in sync"
)
parser.add_argument(
"--skip-photo", action="store_true", help="skip photo types in sync"
)
parser.add_argument(
"--skip-shared-albums",
action="store_true",
Expand Down Expand Up @@ -312,7 +315,6 @@ def setup(self, args: Namespace, db_path: Path):
if args.compare_folder:
compare_folder = Path(args.compare_folder).absolute()
app_dirs = AppDirs(APP_NAME)

self.data_store = LocalData(db_path, args.flush_index)

credentials_file = db_path / ".gphotos.token"
Expand Down Expand Up @@ -352,6 +354,7 @@ def setup(self, args: Namespace, db_path: Path):
retry_download=args.retry_download,
case_insensitive_fs=args.case_insensitive_fs,
include_video=not args.skip_video,
include_photo=not args.skip_photo,
rescan=args.rescan,
archived=args.archived,
photos_path=Path(args.photos_path),
Expand Down Expand Up @@ -458,6 +461,9 @@ def main(self, test_args: dict = None):
if args.version:
print(__version__)
exit(0)
elif args.skip_video and args.skip_photo:
print("--skip-video and --skip-photo can not be combined")
exit(0)
else:
if args.root_folder is None:
self.parser.print_help()
Expand Down
1 change: 1 addition & 0 deletions src/gphotos_sync/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Settings:

favourites_only: bool
include_video: bool
include_photo: bool
archived: bool
use_hardlinks: bool

Expand Down