Code Monkey home page Code Monkey logo

get-google-drive-streams's Introduction

Get Google Drive Streams

A simple tool that traverses a Google Drive, finds all files of mimeType containing 'video', and outputs .strm files that direct the Kodi GDrive Addon (https://forum.kodi.tv/showthread.php?tid=177557) to play them.

The script works from the Google drive Changes API method, so it remembers the last files it has processed, and subsequent executions only track changes from that point forward.

Dependencies

To use the Python script directly

  • Python 3.5+
  • package google-api-python-client
    run pip install --upgrade google-api-python-client to install

How-to

Download getstreams.py, place it in an empty local folder, and run it from command line.

By default, on first execution, getstreams starts from the inception of your Google Drive, finds all video files, prints their full path, then outputs a hierarchy of .strm files, each containing a link of the format plugin://plugin.video.gdrive/?mode=video&filename=abc&title=xyz.

Google authorization

The first time you run getstreams, you will be prompted with a Google authorization page asking you for permission to view and manage your Google Drive files. Once authorized, a credential file will be saved in .credentials\get-google-drive-streams.json under your home directory. You don't need to manually authorize getstreams again until you delete this credential file or revoke permission on your Google account page.
You can specify a custom location for the credential file by using the command line option --credfile. This is helpful if you're using multiple Google accounts with getstreams.

page_token file

getstreams finds video files by scanning through your Google Drive activity history. On first run, it must start from the very beginning to ensure no files are missed, so it might take some time. After first run, getstreams saves a file named page_token in its own parent folder. This file contains a single number indicating an appropriate starting position in your Google Drive activity history for future scans, so they can be much faster than the first one. Each run of getstreams updates page_token as appropriate.
You can specify a custom location or name for the page_token file by using the command line option --ptokenfile.

More options

More command line options are available. You can read about them by running getstreams --help.

usage: getstreams.py [-h] [-v] [-q] [-t SECS] [-m] [--noprogress] [--nopath]
                     [--logfile PATH] [--ptokenfile PATH] [--streampath PATH]
                     [--credfile PATH]

optional arguments:
  -h, --help            show this help message and exit
  -v, --view            Only view which files are to be parsed without
                        creating files
  -q, --quiet           Quiet mode. Only show file count.
  -t SECS, --timeout SECS
                        Specify timeout period in seconds. Default is 300
  --noprogress          Don't show scanning progress. Useful when directing
                        output to files.
  --nopath              Do not parse full path for files, but store them flat.
                        Faster, but messy.
  --logfile PATH        Path to log file. Default is no logs
  --ptokenfile PATH     Path to page token file. Default is "page_token" in
                        getstreams.py's parent folder
  --streampath PATH     Path to stream output directory. Default is
                        strm/ in getstreams.py's parent folder.
  --credfile PATH       Path to OAuth2Credentials file. Default is
                        ~/.credentials/get-google-drive-streams.json

Credit

All the heavy lifting here was stolen shamelessly from Chenfeng Bao's Google Drive Trash Cleaner. The original idea for that script's working mechanism is borrowed from this Stack Overflow question. This is all just a tiny remora stuck to the side of the GDrive Kodi Addon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.