예제 #1
0
def _cache_albums_async(app, refresh_thumbnails=False, refresh_dates=False):
    with app.app_context():
        album_manager = GPhotosAlbum(service)
        current_ids = list()
        for a in album_manager.list():
            album = Album.query.filter_by(gphotos_id=a.get("id")).first()
            if not album:
                album = Album()
            album.gphotos_id = a.get("id")
            if not album.end_date or refresh_dates:
                start_date, end_date = _get_album_date_range(album.gphotos_id)
                album.start_date = start_date
                album.end_date = end_date
            current_ids.append(a.get("id"))
            album.title = a.get("title")
            album.url_title = normalize_for_url(a.get("title"))
            album.items_count = a.get("mediaItemsCount")
            db.session.add(album)
            thumbnail = os.path.join(app.config["ALBUM_THUMB_PATH"],
                                     a.get("id") + ".jpg")
            if not os.path.exists(thumbnail) or refresh_thumbnails:
                urllib.request.urlretrieve(
                    a.get("coverPhotoBaseUrl") + "=w300-h200-c",
                    os.path.join(app.config["ALBUM_THUMB_PATH"],
                                 a.get("id") + ".jpg"),
                )
            db.session.commit()

        # delete from db albums no longer in google photos
        stmt = delete(Album).where(
            Album.gphotos_id.notin_(current_ids)).execution_options(
                synchronize_session="fetch")
        db.session.execute(stmt)
        db.session.commit()
예제 #2
0
파일: main.py 프로젝트: Pirnazar/gphoto
def create_album(title):
    from gphotospy import authorize
    from gphotospy.media import Media
    from gphotospy.album import Album
    CLIENT_SECRET_FILE = "gphoto_oauth.json"
    service = authorize.init(CLIENT_SECRET_FILE)
    album_manager = Album(service)

    new_album = album_manager.create(title)
    id_album = new_album.get("id")
    return id_album
예제 #3
0
파일: main.py 프로젝트: Pirnazar/gphoto
def gphoto_upload(album_id, file):
    from gphotospy import authorize
    from gphotospy.media import Media
    from gphotospy.album import Album
    CLIENT_SECRET_FILE = "gphoto_oauth.json"
    service = authorize.init(CLIENT_SECRET_FILE)
    album_manager = Album(service)
    media_manager = Media(service)
    media_manager.stage_media(file)
    media_manager.batchCreate(album_id=album_id)
예제 #4
0
# Loop first 3 elements
for _ in range(3):
    try:
        # Print only albums's title (if present, otherwise None)
        print(next(album_iterator).get("title"))
    except (StopIteration, TypeError) as e:
        # Handle exception if there are no media left
        print("No (more) shared albums.")
        break

# Create a test album and share it
# create and share
print("Create and share a new album")

album_manager = Album(service)
created_album = album_manager.create('test shared album')
id_album = created_album.get("id")
share_info = album_manager.share(id_album)
token = share_info.get('shareToken')

# Using get() for info retrieval on the shared album
print("Getting album's info")
print(sharing_manager.get(token))

# Trying to join the shared album
print("Trying to join it")
try:
    sharing_manager.join(token)
except HttpError as e:
    print("Can't join albums already joined\n{}".format(e))
예제 #5
0
search_iterator = media_manager.search(filter=[
    FEATUREFILTER.NONE,  # This is default, didn't need be specified
    CONTENTFILTER.TRAVEL,
    CONTENTFILTER.SELFIES,
    MEDIAFILTER.ALL_MEDIA,  # This too is default...
    date(2020, 4, 24),
    date_range(start_date=date(2020, 4, 19), end_date=date(2020, 4, 21))
])
try:
    print(next(search_iterator))
except (StopIteration, TypeError) as e:
    print("No media found :-(")

# Search for media in album
print("Search media in album")
# get an album's id
album_manager = Album(service)
album_iterator = album_manager.list()
album = next(album_iterator)
album_id = album.get("id")
album_title = album.get("title")
print("Album title: {}".format(album_title))
# search in album
search_iterator = media_manager.search_album(album_id)
try:
    for _ in range(3):
        print(next(search_iterator).get("filename"))
except (StopIteration, TypeError) as e:
    print("No (more) media in album {}.".format(album_title))
예제 #6
0
import os
from tkinter import filedialog
from tkinter import *
from gphotospy import authorize
from gphotospy.media import Media
from gphotospy.album import Album

# Select secrets file
CLIENT_SECRET_FILE = "gphoto_oauth.json"

# Get authorization and return a service object
service = authorize.init(CLIENT_SECRET_FILE)

# Init the album and media manager
album_manager = Album(service)
media_manager = Media(service)

# FIle dialog to select media to upload
root = Tk()
curr_dir = os.getcwd()
filetypes = [("JPEG files", "*.jpg *.jpeg"), ("PNG files", "*.png"),
             ("BMP files", "*.bmp"), ("GIF files", "*.gif"),
             ("HEIC files", "*.heic"), ("ICO files", "*.ico"),
             ("TIFF files", "*.tiff *.tif"), ("WEBP files", "*.webp"),
             ("3GP files", "*.3gp"), ("3G2 files", "*.3g2"),
             ("ASF files", "*.asf"), ("AVI files", "*.avi"),
             ("DIVX files", "*.dvx"), ("M2T files", "*.m2t"),
             ("M2TS files", "*.m2ts"), ("M4V files", "*.m4v"),
             ("MMV files", "*.mmv"), ("MOD files", "*.mod"),
             ("MOV files", "*.mov"), ("MP4 files", "*.mp4"),
             ("MPG files", "*.mpg *.mpeg"), ("MTS files", "*.mts"),
예제 #7
0
from gphotospy import authorize
from gphotospy.album import Album
from googleapiclient.errors import HttpError

# Select secrets file
CLIENT_SECRET_FILE = "gphoto_oauth.json"

# Get authorization and return a service object
service = authorize.init(CLIENT_SECRET_FILE)

# Init the album manager
album_manager = Album(service)

# Set default behaviors
album_manager.set_collaborative_share(False)
album_manager.set_commentable_share(True)

# Get iterator over the list of albums
print("Getting a list of albums...")
album_iterator = album_manager.list()

# Loop first 3 elements
for _ in range(3):
    try:
        # Print only album's title (if present, otherwise None)
        print(next(album_iterator).get("title"))
    except (StopIteration, TypeError) as e:
        # Handle exception if there are no albums left
        print("No (more) albums.")
        break