1
0
Fork 0

included move feature in gdrive

This commit is contained in:
xeviff 2023-05-11 14:35:43 +02:00
parent aa7c331728
commit f8757b1206
5 changed files with 25 additions and 7 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
/target/ /target/
.DS_Store .DS_Store
/MangranaCommons.iml /MangranaCommons.iml
/tokens/
/src/main/resources/credentials.json

View File

@ -6,7 +6,7 @@
<groupId>tv.mangrana</groupId> <groupId>tv.mangrana</groupId>
<artifactId>mangrana-commons</artifactId> <artifactId>mangrana-commons</artifactId>
<version>4.1.0</version> <version>4.1.3</version>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>

View File

@ -114,15 +114,26 @@ public class GoogleDriveApiGateway {
.execute(); .execute();
} }
public void moveFile(File file, String destinationFolderId, String newName) throws IOException { public void moveFile(File file, String destinationFolderId, String newFileName) throws IOException {
String parentId = getParent(file.getId());
File newFileReference = new File(); File newFileReference = new File();
newFileReference.setName(newName); newFileReference.setName(newFileName);
service.files() service.files()
.update(file.getId(), newFileReference) .update(file.getId(), newFileReference)
.setSupportsTeamDrives(true)
.setAddParents(destinationFolderId) .setAddParents(destinationFolderId)
.setRemoveParents(file.getParents().get(0)) .setRemoveParents(parentId)
.setFields("id, name, parents")
.execute();
}
private String getParent(String fileId) throws IOException {
File file = service.files()
.get(fileId)
.setFields("parents")
.setSupportsTeamDrives(true) .setSupportsTeamDrives(true)
.execute(); .execute();
return file.getParents().get(0);
} }
public File createFolder(String name, String parentFolderId) throws IOException { public File createFolder(String name, String parentFolderId) throws IOException {

View File

@ -95,7 +95,12 @@ public class PlexCommandLauncher {
private String getPlexRefreshURL(String fullDestinationPath, String plexMountPath) { private String getPlexRefreshURL(String fullDestinationPath, String plexMountPath) {
try { try {
String sectionId = sectionResolver.resolveSectionByPath(fullDestinationPath, plexMountPath); String sectionId = sectionResolver.resolveSectionByPath(fullDestinationPath, plexMountPath);
if (sectionId==null) return null; if (sectionId==null) {
log("Could not resolve the section of the element in plex for "+fullDestinationPath);
return null;
} else {
log("Captured section <{0}> of the element in plex for {1}", sectionId, fullDestinationPath);
}
String host = config.getConfig(PLEX_HOST); String host = config.getConfig(PLEX_HOST);
String uriFormat = config.getConfig(PLEX_SECTION_REFRESH_URI); String uriFormat = config.getConfig(PLEX_SECTION_REFRESH_URI);
String uri = uriFormat.replaceFirst("\\{section_id}", sectionId); String uri = uriFormat.replaceFirst("\\{section_id}", sectionId);

View File

@ -36,7 +36,7 @@ public class PlexLibrarySectionsResolver {
String directoryNodeOfLocation = getDirectoryKeyValue(sectionsInfo, xPath, startingLocationText); String directoryNodeOfLocation = getDirectoryKeyValue(sectionsInfo, xPath, startingLocationText);
if (directoryNodeOfLocation == null) { if (directoryNodeOfLocation == null) {
startingLocationText = plexMountPath.concat("/").concat(keyFolder); startingLocationText = plexMountPath.concat("/").concat(keyFolder);
Output.log("but going to retry with {0}", startingLocationText); //Output.log("but going to retry with {0}", startingLocationText);
return getDirectoryKeyValue(sectionsInfo, xPath, startingLocationText); return getDirectoryKeyValue(sectionsInfo, xPath, startingLocationText);
} else } else
return directoryNodeOfLocation; return directoryNodeOfLocation;
@ -49,7 +49,7 @@ public class PlexLibrarySectionsResolver {
Node directoryNodeOfLocation = candidatesNodes.item(0).getParentNode(); Node directoryNodeOfLocation = candidatesNodes.item(0).getParentNode();
return ((DeferredElementImpl) directoryNodeOfLocation).getAttribute("key"); return ((DeferredElementImpl) directoryNodeOfLocation).getAttribute("key");
} catch (XPathExpressionException | NullPointerException e) { } catch (XPathExpressionException | NullPointerException e) {
Output.log("could not resolve the section of the element in plex "+startingLocationText); //Output.log("could not resolve the section of the element in plex "+startingLocationText);
} }
return null; return null;
} }