mirror of
https://github.com/jellyfin/jellyfin-plugin-bookshelf.git
synced 2024-11-23 21:59:53 +00:00
fix google drive folder paths
This commit is contained in:
parent
387cb1806d
commit
b2ba697dd0
@ -34,7 +34,7 @@
|
||||
html += '<p>Click to configure how GameBrowser deals with online image & data sources</p>';
|
||||
html += '<a data-role="button" data-icon="arrow-r" data-iconpos="right" href="' + metaHref + '">Metadata & Art Configuration</a>';
|
||||
html += '<h2>GameBrowser help</h2>';
|
||||
html += '<a data-role="button" data-icon="arrow-r" data-iconpos="right" href="http://mediabrowser3.com/community/index.php?/topic/855-gamebrowser-iii-support/" target="_blank">Gamebrowser on the Media Browser forum</a>';
|
||||
html += '<a data-role="button" data-icon="arrow-r" data-iconpos="right" href="http://mediabrowser3.com/community/index.php?/topic/855-gamebrowser-iii-support/" target="_blank">Gamebrowser on the Emby forum</a>';
|
||||
|
||||
$('#configPageContent', page).html(html).trigger('create');
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Adult DVD Empire Provider")]
|
||||
[assembly: AssemblyCopyright("Copyright © Media Browser 2013")]
|
||||
[assembly: AssemblyCopyright("Copyright © Emby 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
@ -7,9 +7,9 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyTitle("MediaBrowser.Plugins.ArgusTV")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Media Browser Team")]
|
||||
[assembly: AssemblyCompany("Emby Team")]
|
||||
[assembly: AssemblyProduct("MediaBrowser.Plugins.ArgusTV")]
|
||||
[assembly: AssemblyCopyright("Copyright © Media Browser Team 2013")]
|
||||
[assembly: AssemblyCopyright("Copyright © Emby Team 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
get
|
||||
{
|
||||
var version = _applicationHost.ApplicationVersion.ToString();
|
||||
return string.Format("Media Browser/{0} +http://mediabrowser.tv/", version);
|
||||
return string.Format("Emby/{0} +http://emby.media/", version);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,8 @@
|
||||
<div><b>6.</b> Click "Create Client Id".</div>
|
||||
<div><b>7.</b> You'll be returned to the main screen, where your Client Id and Client Secret will be displayed. Copy these values.</div>
|
||||
<div><b>8.</b> In the left sidebar, click "APIs" under "APIs & Auth". In the API list, click Drive API and enable it.</div>
|
||||
<div><b>9.</b> Enter the Client Id and Client Secret values here and click Save.</div>
|
||||
<div><b>10.</b> Add one or more google drive accounts using the form below.</div>
|
||||
<br />
|
||||
</div>
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Controller.Sync;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using MediaBrowser.Model.Sync;
|
||||
using MediaBrowser.Plugins.GoogleDrive.Configuration;
|
||||
@ -15,11 +16,13 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
{
|
||||
private readonly IConfigurationRetriever _configurationRetriever;
|
||||
private readonly IGoogleDriveService _googleDriveService;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GoogleDriveServerSyncProvider(IConfigurationRetriever configurationRetriever, IGoogleDriveService googleDriveService)
|
||||
public GoogleDriveServerSyncProvider(IConfigurationRetriever configurationRetriever, IGoogleDriveService googleDriveService, ILogManager logManager)
|
||||
{
|
||||
_configurationRetriever = configurationRetriever;
|
||||
_googleDriveService = googleDriveService;
|
||||
_logger = logManager.GetLogger("GoogleDrive");
|
||||
}
|
||||
|
||||
public string Name
|
||||
@ -39,6 +42,8 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
|
||||
public async Task<SyncedFileInfo> SendFile(Stream stream, string remotePath, SyncTarget target, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.Debug("Sending file {0} to {1}", remotePath, target.Name);
|
||||
|
||||
var file = CreateGoogleDriveFile(remotePath, target);
|
||||
var googleCredentials = GetGoogleCredentials(target);
|
||||
|
||||
@ -53,6 +58,8 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
|
||||
public async Task<SyncedFileInfo> GetSyncedFileInfo(string remotePath, SyncTarget target, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.Debug("Getting synced file info for {0} from {1}", remotePath, target.Name);
|
||||
|
||||
var file = CreateGoogleDriveFile(remotePath, target);
|
||||
var googleCredentials = GetGoogleCredentials(target);
|
||||
|
||||
@ -125,24 +132,5 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
GoogleDriveFolderId = syncAccount.FolderId
|
||||
};
|
||||
}
|
||||
|
||||
private DeviceFileInfo CreateDeviceFileInfo(GoogleDriveFile file)
|
||||
{
|
||||
return new DeviceFileInfo
|
||||
{
|
||||
Name = file.Name,
|
||||
Path = GetGoogleDriveFilePath(file)
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetGoogleDriveFilePath(GoogleDriveFile file)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(file.FolderPath))
|
||||
{
|
||||
return Path.Combine(file.FolderPath, file.Name);
|
||||
}
|
||||
|
||||
return file.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,38 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
private const string SyncFolderPropertyValue = "ba460da6-2cdf-43d8-98fc-ecda617ff1db";
|
||||
private const string PathPropertyKey = "Path";
|
||||
|
||||
private async Task<string> GetOrCreateParent(GoogleCredentials googleCredentials, string path, string rootParentId, CancellationToken cancellationToken)
|
||||
{
|
||||
var parts = path.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
|
||||
string currentPath = null;
|
||||
string currentparentId = rootParentId;
|
||||
|
||||
foreach (var part in parts)
|
||||
{
|
||||
if (currentPath == null)
|
||||
{
|
||||
currentPath = part;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPath = Path.Combine(currentPath, part);
|
||||
}
|
||||
|
||||
currentparentId = await GetOrCreateFolder(part, currentparentId, googleCredentials, cancellationToken);
|
||||
}
|
||||
|
||||
return currentparentId;
|
||||
}
|
||||
|
||||
public async Task<string> UploadFile(Stream stream, GoogleDriveFile googleDriveFile, GoogleCredentials googleCredentials, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var fullDriveService = CreateDriveServiceAndCredentials(googleCredentials);
|
||||
var driveService = fullDriveService.Item1;
|
||||
|
||||
var parentId = await GetOrCreateParent(googleCredentials, googleDriveFile.FolderPath, googleDriveFile.GoogleDriveFolderId, cancellationToken);
|
||||
googleDriveFile.GoogleDriveFolderId = parentId;
|
||||
|
||||
await TryDeleteFile(googleDriveFile, googleCredentials, cancellationToken);
|
||||
|
||||
var file = CreateFileToUpload(googleDriveFile);
|
||||
@ -43,18 +70,18 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
return uploadedFile.DownloadUrl + "&access_token=" + fullDriveService.Item2.Token.AccessToken;
|
||||
}
|
||||
|
||||
public async Task<string> GetOrCreateFolder(string name, GoogleCredentials googleCredentials, CancellationToken cancellationToken)
|
||||
public async Task<string> GetOrCreateFolder(string name, string parentId, GoogleCredentials googleCredentials, CancellationToken cancellationToken)
|
||||
{
|
||||
var driveService = CreateDriveService(googleCredentials);
|
||||
|
||||
var folder = await FindFolder(name, driveService, cancellationToken);
|
||||
var folder = await FindFolder(name, parentId, driveService, cancellationToken);
|
||||
|
||||
if (folder != null)
|
||||
{
|
||||
return folder.Id;
|
||||
}
|
||||
|
||||
return await CreateFolder(name, cancellationToken, driveService);
|
||||
return await CreateFolder(name, parentId, cancellationToken, driveService);
|
||||
}
|
||||
|
||||
public async Task DeleteFile(GoogleDriveFile googleDriveFile, GoogleCredentials googleCredentials, CancellationToken cancellationToken)
|
||||
@ -88,9 +115,20 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
.Select(CreateGoogleDriveFile);
|
||||
}
|
||||
|
||||
public async Task<File> FindFileId(GoogleDriveFile googleDriveFile, DriveService driveService, CancellationToken cancellationToken)
|
||||
public Task<File> FindFileId(GoogleDriveFile googleDriveFile, DriveService driveService, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = string.Format("'{0}' in parents and title = '{1}'", googleDriveFile.GoogleDriveFolderId, googleDriveFile.Name);
|
||||
return FindFileId(googleDriveFile, false, driveService, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<File> FindFileId(GoogleDriveFile googleDriveFile, bool isFolder, DriveService driveService, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = string.Format("title = '{0}'", googleDriveFile.Name);
|
||||
|
||||
if (isFolder)
|
||||
{
|
||||
query += " and mimeType = 'application/vnd.google-apps.folder'";
|
||||
}
|
||||
|
||||
var matchingFiles = await GetFiles(query, driveService, cancellationToken);
|
||||
|
||||
var file = matchingFiles.FirstOrDefault(f => FileIsInPath(f, googleDriveFile.FolderPath));
|
||||
@ -161,7 +199,7 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
|
||||
var initializer = new BaseClientService.Initializer
|
||||
{
|
||||
ApplicationName = "Media Browser",
|
||||
ApplicationName = "Emby",
|
||||
HttpClientInitializer = credentials
|
||||
};
|
||||
|
||||
@ -189,7 +227,7 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
|
||||
var initializer = new BaseClientService.Initializer
|
||||
{
|
||||
ApplicationName = "Media Browser",
|
||||
ApplicationName = "Emby",
|
||||
HttpClientInitializer = credentials
|
||||
};
|
||||
|
||||
@ -244,17 +282,22 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
return pathProperty.Value;
|
||||
}
|
||||
|
||||
private async Task<File> FindFolder(string name, DriveService driveService, CancellationToken cancellationToken)
|
||||
private async Task<File> FindFolder(string name, string parentId, DriveService driveService, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = string.Format(@"title = '{0}' and properties has {{ key='{1}' and value='{2}' and visibility='PRIVATE' }}", name, SyncFolderPropertyKey, SyncFolderPropertyValue);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(parentId))
|
||||
{
|
||||
query += string.Format(" and '{0}' in parents", parentId);
|
||||
}
|
||||
var matchingFolders = await GetFiles(query, driveService, cancellationToken);
|
||||
|
||||
return matchingFolders.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static async Task<string> CreateFolder(string name, CancellationToken cancellationToken, DriveService driveService)
|
||||
private static async Task<string> CreateFolder(string name, string parentId, CancellationToken cancellationToken, DriveService driveService)
|
||||
{
|
||||
var file = CreateFolderToUpload(name);
|
||||
var file = CreateFolderToUpload(name, parentId);
|
||||
|
||||
var request = driveService.Files.Insert(file);
|
||||
var newFolder = await request.ExecuteAsync(cancellationToken);
|
||||
@ -262,7 +305,7 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
return newFolder.Id;
|
||||
}
|
||||
|
||||
private static File CreateFolderToUpload(string name)
|
||||
private static File CreateFolderToUpload(string name, string parentId)
|
||||
{
|
||||
var property = new Property
|
||||
{
|
||||
@ -271,12 +314,25 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
Visibility = "PRIVATE"
|
||||
};
|
||||
|
||||
return new File
|
||||
File file = new File
|
||||
{
|
||||
Title = name,
|
||||
MimeType = "application/vnd.google-apps.folder",
|
||||
Properties = new List<Property> { property }
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(parentId))
|
||||
{
|
||||
file.Parents = new List<ParentReference>
|
||||
{
|
||||
new ParentReference
|
||||
{
|
||||
Id = parentId
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace MediaBrowser.Plugins.GoogleDrive
|
||||
public interface IGoogleDriveService
|
||||
{
|
||||
Task<string> UploadFile(Stream stream, GoogleDriveFile googleDriveFile, GoogleCredentials googleCredentials, IProgress<double> progress, CancellationToken cancellationToken);
|
||||
Task<string> GetOrCreateFolder(string name, GoogleCredentials googleCredentials, CancellationToken cancellationToken);
|
||||
Task<string> GetOrCreateFolder(string name, string parentId, GoogleCredentials googleCredentials, CancellationToken cancellationToken);
|
||||
Task DeleteFile(GoogleDriveFile googleDriveFile, GoogleCredentials googleCredentials, CancellationToken cancellationToken);
|
||||
Task<Stream> GetFile(GoogleDriveFile googleDriveFile, GoogleCredentials googleCredentials, CancellationToken cancellationToken);
|
||||
Task<IEnumerable<GoogleDriveFile>> GetFilesListing(string googleDrivefolder, string parentFolderId, GoogleCredentials googleCredentials, CancellationToken cancellationToken);
|
||||
|
@ -82,7 +82,7 @@ namespace MediaBrowser.Plugins.GoogleDrive.RestServices
|
||||
RefreshToken = refreshToken
|
||||
};
|
||||
|
||||
return await _googleDriveService.GetOrCreateFolder(Constants.GoogleDriveFolderName, googleCredentials, CancellationToken.None);
|
||||
return await _googleDriveService.GetOrCreateFolder(Constants.GoogleDriveFolderName, null, googleCredentials, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace MediaBrowser.Plugins.NotifyMyAndroidNotifications.Api
|
||||
{"apikey", options.Token},
|
||||
{"event", "Test Notification"},
|
||||
{"description", "This is a test notification from MediaBrowser"},
|
||||
{"application", "Media Browser"}
|
||||
{"application", "Emby"}
|
||||
};
|
||||
|
||||
_logger.Debug("NotifyMyAndroid <TEST> to {0}", options.Token);
|
||||
|
@ -47,7 +47,7 @@ namespace MediaBrowser.Plugins.NotifyMyAndroidNotifications
|
||||
var parameters = new Dictionary<string, string>
|
||||
{
|
||||
{"apikey", options.Token},
|
||||
{"application", "Media Browser"}
|
||||
{"application", "Emby"}
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(request.Description))
|
||||
|
@ -43,7 +43,7 @@ namespace MediaBrowser.Plugins.ProwlNotifications.Api
|
||||
{"apikey", options.Token},
|
||||
{"event", "Test Notification"},
|
||||
{"description", "This is a test notification from MediaBrowser"},
|
||||
{"application", "Media Browser"}
|
||||
{"application", "Emby"}
|
||||
};
|
||||
|
||||
_logger.Debug("Prowl <TEST> to {0}", options.Token);
|
||||
|
@ -47,7 +47,7 @@ namespace MediaBrowser.Plugins.ProwlNotifications
|
||||
var parameters = new Dictionary<string, string>
|
||||
{
|
||||
{"apikey", options.Token},
|
||||
{"application", "Media Browser"}
|
||||
{"application", "Emby"}
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(request.Description))
|
||||
|
@ -37,7 +37,7 @@ namespace MediaBrowser.Plugins.SmtpNotifications.Api
|
||||
|
||||
var mail = new MailMessage(options.EmailFrom, options.EmailTo)
|
||||
{
|
||||
Subject = "Media Browser: Test Notification",
|
||||
Subject = "Emby: Test Notification",
|
||||
Body = "This is a test notification from MediaBrowser"
|
||||
};
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace MediaBrowser.Plugins.SmtpNotifications
|
||||
|
||||
var mail = new MailMessage(options.EmailFrom, options.EmailTo)
|
||||
{
|
||||
Subject = "Media Browser: " + request.Name,
|
||||
Subject = "Emby: " + request.Name,
|
||||
Body = request.Description
|
||||
};
|
||||
|
||||
|
@ -7,9 +7,9 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyTitle("MediaBrowser.Plugins.StudioCleaner")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Media Browser Team")]
|
||||
[assembly: AssemblyCompany("Emby Team")]
|
||||
[assembly: AssemblyProduct("MediaBrowser.Plugins.StudioCleaner")]
|
||||
[assembly: AssemblyCopyright("Copyright © Media Browser Team 2013")]
|
||||
[assembly: AssemblyCopyright("Copyright © Emby Team 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user