You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changes being made:
* Patch a handful of existing bugs present in the previous version of the script
* Prevent the script from generating strm files for deleted items - deleted items will now be ignored.
* Introduce a flag to be able to see realtime updates being pushed to the console (and being able to turn this off)
* Introduce a flag to customise the title of the root directory being created by the script.
* Update readme with the changes being made.
* Additional minor changes to the readme to explain stuff in a more simple manner.
-[Is this script better than the existing add-on?](#is-this-script-better-than-the-existing-add-on)
60
+
-[How does this script work](#how-does-this-script-work)
53
61
-[Advanced Setup](#advanced-setup)
54
62
-[Roadmap](#roadmap)
55
63
-[A list of *possible* improvements;](#a-list-of-possible-improvements)
56
-
-[Contributing](#contributing)
64
+
-[Contributions](#contributions)
57
65
-[License](#license)
58
66
-[Acknowledgements](#acknowledgements)
59
67
-[Just some fun](#just-some-fun)
@@ -65,13 +73,13 @@
65
73
66
74
A simple python script to complement the functionality of [Google Drive AddOn](https://kodi.tv/addon/music-add-ons-picture-add-ons-plugins-video-add-ons/google-drive) for Kodi.
67
75
68
-
For an add-on that [claims to be "*extremely fast*"](https://github.com/cguZZman/plugin.googledrive), I found the add-on to be quite slow (*and unreliable*). It crashes way too frequently, is slow, and gets stuck way too often (this happened frequently enough, to the point I decided to make this project just to solve this problem).
76
+
For an add-on that [claims to be "*extremely fast*"](https://github.com/cguZZman/plugin.googledrive#google-drive-kodi-addon), I found the add-on to be quite slow (*and unreliable*). It crashes way too frequently, is slow, and gets stuck way too often (this happened frequently enough, to the point I decided to make this project just to solve this problem).
69
77
70
78
The main purpose of this project is to generate strm files for media file(s) present in a directory on Google Drive - and achieve this more reliably than the Kodi AddOn.
71
79
72
80
### What is a strm file?
73
81
74
-
In simple terms, *strm* files refer to files having an extension of `.strm`. They usually created and used by multimedia applications (Kodi and Plex being the main examples). They are used to store URL(s).
82
+
In simple terms, *strm* files refer to files having an extension of `.strm`. They usually created and used by multimedia applications (Kodi and Plex being the main examples). They are used to store URL pointing to the actual media file(s) stored on in a remote server/cloud.
75
83
76
84
This URL is then used by the application to stream the actual media file when required.
77
85
@@ -84,30 +92,31 @@ This URL is then used by the application to stream the actual media file when re
84
92
## Setup
85
93
1. Create a [Google Project](http://console.developers.google.com/) and [enable Google Drive API](https://developers.google.com/drive/api/v3/enable-drive-api).
86
94
2. Once you enable the Drive API for your project, setup credentials required to use this API.
87
-
3. Download the credentials as a JSON file and rename the file as `credentials.json`.
88
-
4. Move the `credentials,json` file into the same directory containing the python script.
95
+
3. Download the credentials as a JSON file and rename this file as `credentials.json`.
96
+
4. Move the `credentials.json` file into the same directory containing the python script.
89
97
5. Install the python dependencies.
90
98
<br> `pip install -r requirements.txt`
91
99
6. Install [Kodi AddOn for Google Drive](https://kodi.tv/addon/music-add-ons-picture-add-ons-plugins-video-add-ons/google-drive) in your Kodi installation.
92
100
7. Login to the add-on. Make sure that you use the same Google account while logging into this script and the Google add-on.
93
101
94
102
Alternatively, for the fourth step, you can directly use the `setup.sh` or `setup.bat` scripts and have them create an efficient setup for you.
95
103
96
-
> #### What do the setup scripts do?
97
-
>
98
-
> The setup script will;
99
-
> * Update `pip`
100
-
> * Install `virtualenv`
101
-
> * Create a virtual environment named `.venv`
102
-
> * Install required packages into this virtual environment.
104
+
#### What do the setup scripts do?
103
105
104
-
While anyone is free to use the direct setup files, do note that they are primarily for my use (to quickly setup a system for usage/testing/debugging) - and are not guaranteed to work in your system.
106
+
The setup script will;
107
+
* Update `pip`
108
+
* Install `virtualenv`
109
+
* Create a virtual environment named `.venv`
110
+
* Activate this virtual package
111
+
* Install required python packages into this virtual environment.
112
+
113
+
While anyone is free to use the direct setup files, do note that they are primarily for my use (to quickly setup a system for usage/testing/debugging) - and are *not guaranteed* to work in your system.
105
114
106
115
## Usage
107
116
108
117
Executing the python script directly (without custom arguments) will fetch a list of all teamdrives to which the account has access -- allowing you to select a teamdrive from this list which will then be scanned for media files.
109
118
110
-
Alternatively, you can pass [custom arguments](#custom-arguments) to the script to scan a particular folder, or to modify the directory where the strm files are stored after being generated.
119
+
Alternatively, you can pass [custom arguments](#custom-arguments) to the script to modify the default behaviour.
111
120
112
121
Once the script finishes generating strm files after a scan, add the resulting [directory as a source](https://kodi.wiki/view/Adding_video_sources) in your Kodi installation. From there on, Kodi will treat these `.strm` files as actual media files and will be able to scan/play them normally.
113
122
@@ -121,66 +130,170 @@ Once you're comfortable with the usage of this script, you might want to take a
121
130
122
131
Running the python script without any custom arguments will fetch a list of all team-drives that are connected to the account, selecting a teamdrive from this list will make the script scan the contents of the particular teamdrive.
123
132
124
-
### Where are the strm files stored?
133
+
### Where are the strm files placed?
125
134
126
135
By default, the strm files generated after a scan are stored in the **working directory**. Use `pwd` in Unix-based systems, or `cd` in Windows get the location of current working directory.
127
136
128
-
Look for a directory with the **same name as the source** (the Google folder/teamdrive) scanned.
137
+
By deafult, the strm files are placed inside a directory with the **same name as the source** (the Google folder/teamdrive) scanned.
138
+
139
+
Note: Take a look at the flags for [custom destination directory](#custom-destination-directory) and [custom root directory](#custom-name-for-root-directory) to modify the directory inside which strm files are being generated.
129
140
130
141
## Custom Arguments
131
142
132
-
Using custom arguments, you can control the folder that is being scanned, and/or modify the directory in which the strm files are being placed after a scan.
143
+
Using custom arguments, you can control the folder that is being scanned, modify the directory in which the strm files are being placed after a scan, modify the name of the root directory being used, choose if you want the script to run in silent mode or not and more.
144
+
145
+
Note: These flags can be passed only if the script is being executed from the terminal.
146
+
147
+
#### Scanning Selective Folders
148
+
149
+
**Flag:**`--source=<folder-id>`
150
+
**Value Expected:** ID of an existing folder on Google Drive.
151
+
152
+
By default, the script will prompt you to select a teamdrive as the source - the selected teamdrive will be completely scanned by the script. This might not always be desired.
153
+
154
+
This flag allows you to scan the contents of any particular directory as needed, i.e. with the help of this flag instead of scanning a complete teamdrive (or the main drive), an individual folder can be selectively scanned using its ID.
155
+
156
+
> Note: Check [Getting the Folder ID](#getting-folder-ids) section to get the ID of a folder in Google Drive.
157
+
158
+
Side Note: Drive API treats teamdrives as folders, meaning that this flag can also be used to scan a teamdrive with it's ID.
159
+
160
+
[>> Using this Flag; Example](#scanning-a-folder-selectively)
161
+
162
+
#### Custom Destination Directory
163
+
164
+
**Flag:**`--dest="</path/to/destination>"`
165
+
**Expected Value:** Path to an ***existing*** directory.
133
166
134
-
This enables scanning a particular folder in a teamdrive instead of scanning the entire teamdrive, or to scan the contents of the *My Drive* section.
167
+
This flag is used to decide the destination directory in which the root directory (containing the strm files) will be placed.
135
168
136
-
Note: These flags can only be passed if you execute the script from the terminal.
169
+
[>> Resource: Destination Directory vs Root Directory](#destination-directory-vs-root-directory)
137
170
138
-
### Scanning a particular folder
171
+
Make sure that path supplied as a value with this flag belongs to an **existing directory**. If the path contains spaces, wrap it inside double quotes.
139
172
140
-
Add `--source=<folder-id>` flag while executing the python script to force it to scan a particular directory. [Example](#example-using-custom-arguments)
173
+
[>> Using this Flag; Example](#custom-destination)
141
174
142
-
> Note: Check [Getting the Folder ID](#getting-folder-ids) section to get the folder id for a particular folder in Google Drive.
175
+
#### Realtime Updates
143
176
177
+
**Flag:**`--updates=<value>`
178
+
**Expected Value:**`on` OR `off`
144
179
145
-
### Modifying the directory where strm files are generated
180
+
This is an optional flag to see real-time progress as the script is scanning items from the source. The value of `off` implies no updates are to be printed to the console - effectively running the script silently.
146
181
147
-
Add `--dest=<destination>` flag while executing the python script to store the generated strm files in a particular directory. Make sure that the destination points to an existing directory.
182
+
Having realtime updates might not always be desirable (especially if script is being run in the backgrond - me for one). Setting the value of this flag to `off` will run the script in silent mode - under silent mode, the only time this script will print to the console will be to notify that a scan has completed.
148
183
149
-
Inside the destination directory, this script will make a directory with the same name as the source folder on Google Drive. If the destination contains a space, wrap it inside the double quotes before adding it as a flag.
184
+
By default, the value of this flag is `on`, i.e. realtime progress will be displayed on the console.
185
+
186
+
[>> Using this Flag; Example](#miscellaneous-examples)
187
+
188
+
#### Custom Name for Root Directory
189
+
190
+
**Flag:**`--rootname=<root-directory>`
191
+
**Expected Value:** Name for the root directory
192
+
193
+
Optional flag to modify the name of root directory that is created by this script during runtime.
194
+
195
+
[>> Resource: Destination Directory vs Root Directory](#destination-directory-vs-root-directory)
196
+
197
+
Be default, the name of the teamdrive/folder being scanned will be used as the name of the root directory.
198
+
199
+
Important: If a directory with the same name as the root directory already exists inside destination directory, this script will ***erase the existing root directory***.
200
+
201
+
[>> Using this Flag; Example](#custom-root-directory)
202
+
203
+
## Resources
150
204
151
205
#### Getting Folder ID's
152
206
153
207
You can get the id for a particular folder by opening the folder and copying the id from the url.
154
208
155
209
For example, in the URL `https://drive.google.com/drive/folders/0AOC6NXsE2KJMUk9PTA`, the folder-id is `0AOC6NXsE2KJMUk9PTA`.
156
210
157
-
This method can also be used to get the ID of a particular TeamDrive and use it as a [custom argument](#scanning-a-particular-folder) to directly scan the teamdrive.
211
+
This method can also be used to get the ID of a particular TeamDrive and use it as a [custom argument](#scanning-selective-folders) to directly scan the teamdrive.
212
+
213
+
214
+
#### Destination Directory vs Root Directory
215
+
216
+
In basic terms, when the script scans a folder on drive, it creates a directory which will contain all the strm files being generated.
158
217
159
-
#### Example; Using Custom Arguments
160
-
161
-
Running the following command will scan the folder `0AOC6NXsE2KJMUk9PVA` and generate strm files inside the directory `/home/kodi libraries` instead of resorting to the defaults.
218
+
This directory that has been created by the script, during the runtime is the ***Root Directory***. The parent directory that contains the root directory is termed as the ***Destination Directory***.
The path being used as the parent/destination directory should point to an already existing directory. On the other hand, if a directory with the same name as root directory is already present inside the destination, it will be wiped off.
221
+
222
+
As an example, take a look at this directory structure;
223
+
224
+
```bash
225
+
│── E:
226
+
│ ├── Kodi Library
227
+
│ │ ├── Downloaded Media
228
+
│ │ │ ├── new-file.mp4.strm
229
+
│ │ │ ├── old-file-02.mp4.strm
230
+
│ │ ├── Collection
231
+
│ │ │ ├── movie-file.mkv.strm
232
+
│ ├── STRM Files
233
+
│ │ ├── Content Media
234
+
│ │ │ ├── movie-01.mkv.strm
235
+
│ │ │ ├── movie-02.mp4.strm
236
+
│ │ │ ├── trailer.mkv.strm
237
+
```
238
+
239
+
From above, strm files are present inside three directories, namely, `Downloaded Media`, `Collection` and `Content Media` - these are the *Root Directories*. The directories containing these root directories then become the `Destination Directory`. Meaning that, there are two destination directories, `Kodi Library` and `STRM Files`.
240
+
241
+
242
+
## Examples
243
+
244
+
#### Custom destination
245
+
Running the following command will generate the root directory (containing strm files) at the destination `/home/kodi library`. Make sure that this is a valid path and points to a directory.
Note that since the path contains space, it has been wrapped in double spaces.
250
+
251
+
#### Scanning a folder selectively
252
+
253
+
Running the following command will scan a folder with the ID `0AOC6NXsE2KJMUk9PVA` on Google Drive. Make sure that the account you signed into the script with has access to this folder.
Note the additional destination flag in the command, instead of placing the results in the working directory, the script will now place them inside `/home/kodi library`.
258
+
259
+
#### Custom root directory
260
+
261
+
Running the following command will generate strm files inside a directory named `new root directory`
The strm files will be present in a directory named `new root directory` (this is the root directory). The root directory by itself will be present inside `"/home/kodi library"` (this being the destination directory).
266
+
267
+
### Miscellaneous Examples
268
+
269
+
* Scanning a particular folder on drive, with custom destination and root directories, plus no updates to the console (using all the flags at once).
If you're unsure about using custom arguments, feel free to just replace the values in the command above with **valid** values, and you're good to go!
166
281
167
282
---
168
283
169
-
### How is this script better than the existing add-on?
284
+
##Is this script better than the existing add-on?
170
285
171
-
Based on the tests I have run upto now, this script didn't crash or lag, and was quite a bit faster than the add-on. Honestly, I'm not sure about why this happens. While the add-on is [open source](https://github.com/cguZZman/plugin.googledrive), I'm yet to take a look at the source code and determine why.
286
+
Based on the tests I have run, this script didn't crash or lag, and was quite a bit faster than the add-on. Honestly, I'm not sure why this happens - while the Google Drive add-on is [open source](https://github.com/cguZZman/plugin.googledrive), I'm yet to take a proper look at it.
172
287
173
288
What I do know is, this script is as simple as it can be. There is no clever hack, or any trick present. Yet, all the tests I ran prove that this script is somehow better than the add-on (and no, this is **definitely not** because of any hardware limitation at my end).
174
289
175
290
It is possible that this difference is being caused by Kodi (or the integration between the add-on and Kodi). Regardless, I noticed a flaw, and wrote a simple script to overcome it effectively.
176
291
177
-
## How does this script work
292
+
###How does this script work
178
293
179
294
The basic functioning of this script revolves around traversing a directory on Google Drive, iterating through each file present in this directory and generating an equivalent `.strm` file for every media file. An important part of this is to be able to recognize media files.
180
295
181
-
The most important step while creating a strm file is to ensure that the contents of the file are stored in such a manner that they can be parsed by the Google Drive add-on.
182
-
183
-
The last step above ensures that this script does not need to handle the part of using these strm files to stream the video. Once this script generates the strm files, everything else is being handled by the Kodi add-on, this includes parsing the strm file to get the actual URL, streaming contents from the URL and everything else.
296
+
The most important step while creating a strm file is to ensure that the contents of the file are stored in such a manner that they can be parsed by the Google Drive add-on. This ensures that this script does not need to handle the part of using these strm files to stream the video. Once an strm file has been generated, everything else is being handled by the Kodi add-on, this includes parsing the strm file to get the actual URL and streaming media from the URL.
184
297
185
298
## Advanced Setup
186
299
@@ -194,9 +307,7 @@ Whenever I open up Kodi, it automatically scrapes the new files, and adds them t
194
307
195
308
If needed, the systemd service can be modified to run the script multiple times, scanning different sources each time to be able to scale my current setup to span across multiple teamdrives/folders, all this without requiring any sort of input.
196
309
197
-
Windows users can achieve the same functionality as systemd.service using [Windows Task Scheduler](https://en.wikipedia.org/wiki/Windows_Task_Scheduler).
198
-
199
-
In case someone wants to replicate a similar setup as mine, here are some useful links to help you get started.
310
+
Windows users can achieve the same functionality as systemd.service using [Windows Task Scheduler](https://en.wikipedia.org/wiki/Windows_Task_Scheduler). In case someone wants to replicate a similar setup as mine, here are some useful links to help you get started.
200
311
201
312
-[Creating a systemd.service](https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6)
202
313
-[Using Windows Task Scheduler](https://windowsreport.com/schedule-tasks-windows-10)
@@ -213,10 +324,11 @@ Based on the tests I've run, this script is ~20% faster than the Google Drive Ad
213
324
> *For the curious, yes, I ran the test on the exact same source without any modifications. The results are as accurate as possible.*
214
325
215
326
#### A list of *possible* improvements;
216
-
- Improvement(s) on the GUI - updating progress on the terminal while the script is running.
217
-
- Multithreading (still not sure on this one) - despite GIL, the execution speed can be improved to some extent.
327
+
- Improvement(s) on the GUI - ~~updating progress on the terminal while the script is running~~ added in [e451e08
- Multithreading (still not sure on this one) - despite GIL, the execution speed can be improved to *some* extent.
218
330
219
-
## Contributing
331
+
## Contributions
220
332
221
333
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions made are **extremely appreciated**.
222
334
@@ -230,9 +342,10 @@ Contributions are what make the open source community such an amazing place to l
230
342
Distributed under the MIT License. See [`LICENSE`](./LICENSE). for more information.
231
343
232
344
## Acknowledgements
233
-
*[Img Shields](https://shields.io)
234
-
*[Google API Python Client](https://github.com/googleapis/google-api-python-client)
235
-
*[Coloroma](https://github.com/tartley/colorama)
345
+
*[Img Shields](https://shields.io): for the badges being used in this readme.
346
+
*[Google API Python Client](https://github.com/googleapis/google-api-python-client): a python wrapper to work with Drive API.
347
+
*[Coloroma](https://github.com/tartley/colorama): Used to print the names of teamdrives in separate colors while selecting a source in interactive mode.
348
+
*[Reprint](https://github.com/Yinzo/reprint): Used to provide updates on the console.
236
349
* Special credits to [Satan](https://github.com/not-satan) for being annoying enough to force me to work on this repo as a priority.
237
350
238
351
<br>
@@ -246,4 +359,4 @@ Distributed under the MIT License. See [`LICENSE`](./LICENSE). for more informat
0 commit comments