From d0a03e3e77ca8f079941969f1245c2064b24ec51 Mon Sep 17 00:00:00 2001 From: Dan O'Meara Date: Wed, 18 Nov 2020 14:18:53 -0800 Subject: [PATCH] docs: add samples from video/cloud-client/shotchange (#72) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adds tutorials using Cloud Client [(#930)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/930) * Adds tutorials. * Removes unused enumerate * Adds one more tutorial as well as fixes some copy/paste typos. [(#933)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/933) * Adds new examples, replaces markdown with restructured text [(#945)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/945) * Adds new examples, replaces markdown with restructured text * Address review feedback * Use videos from pubilc bucket, update to new client library. * Style nit * Updates requirements [(#952)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/952) * Fix README rst links [(#962)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/962) * Fix README rst links * Update all READMEs * change the usage file sample [(#958)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/958) since the file does not exist. Propose to use the same one as the tutorial: demomaker/gbikes_dinosaur.mp4 * Updates examples for video [(#968)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/968) * Auto-update dependencies. [(#1093)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1093) * Auto-update dependencies. * Fix storage notification poll sample Change-Id: I6afbc79d15e050531555e4c8e51066996717a0f3 * Fix spanner samples Change-Id: I40069222c60d57e8f3d3878167591af9130895cb * Drop coverage because it's not useful Change-Id: Iae399a7083d7866c3c7b9162d0de244fbff8b522 * Try again to fix flaky logging test Change-Id: I6225c074701970c17c426677ef1935bb6d7e36b4 * Update all generated readme auth instructions [(#1121)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1121) Change-Id: I03b5eaef8b17ac3dc3c0339fd2c7447bd3e11bd2 * Auto-update dependencies. [(#1123)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1123) * Video v1beta2 [(#1088)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1088) * update analyze_safe_search * update analyze_shots * update explicit_content_detection and test * update fece detection * update label detection (path) * update label detection (file) * flake * safe search --> explicit content * update faces tutorial * update client library quickstart * update shotchange tutorial * update labels tutorial * correct spelling * correction start_time_offset * import order * rebased * Added Link to Python Setup Guide [(#1158)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1158) * Update Readme.rst to add Python setup guide As requested in b/64770713. This sample is linked in documentation https://cloud.google.com/bigtable/docs/scaling, and it would make more sense to update the guide here than in the documentation. * Update README.rst * Update README.rst * Update README.rst * Update README.rst * Update README.rst * Update install_deps.tmpl.rst * Updated readmegen scripts and re-generated related README files * Fixed the lint error * Tweak doc/help strings for sample tools [(#1160)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1160) * Corrected copy-paste on doc string * Updated doc/help string to be more specific to labels tool * Made shotchange doc/help string more specific * Tweaked doc/help string to indicate no arg expected * Adjusted import order to satisfy flake8 * Wrapped doc string to 79 chars to flake8 correctly * Adjusted import order to pass flake8 test * Auto-update dependencies. [(#1186)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1186) * update samples to v1 [(#1221)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1221) * update samples to v1 * replace while loop with operation.result(timeout) * addressing review comments * flake * flake * Added "Open in Cloud Shell" buttons to README files [(#1254)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1254) * Auto-update dependencies. [(#1377)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1377) * Auto-update dependencies. * Update requirements.txt * Auto-update dependencies. * Regenerate the README files and fix the Open in Cloud Shell link for some samples [(#1441)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1441) * Update READMEs to fix numbering and add git clone [(#1464)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1464) * Video Intelligence region tag update [(#1639)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1639) * Auto-update dependencies. [(#1658)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1658) * Auto-update dependencies. * Rollback appengine/standard/bigquery/. * Rollback appengine/standard/iap/. * Rollback bigtable/metricscaler. * Rolledback appengine/flexible/datastore. * Rollback dataproc/ * Rollback jobs/api_client * Rollback vision/cloud-client. * Rollback functions/ocr/app. * Rollback iot/api-client/end_to_end_example. * Rollback storage/cloud-client. * Rollback kms/api-client. * Rollback dlp/ * Rollback bigquery/cloud-client. * Rollback iot/api-client/manager. * Rollback appengine/flexible/cloudsql_postgresql. * Use explicit URIs for Video Intelligence sample tests [(#1743)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1743) * Auto-update dependencies. [(#1846)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1846) ACK, merging. * Longer timeouts to address intermittent failures [(#1871)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1871) * Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1980) * Auto-update dependencies. * Update requirements.txt * Update requirements.txt * replace demomaker with cloud-samples-data/video for video intelligenc… [(#2162)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2162) * replace demomaker with cloud-samples-data/video for video intelligence samples * flake * Adds updates for samples profiler ... vision [(#2439)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2439) * Auto-update dependencies. [(#2005)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2005) * Auto-update dependencies. * Revert update of appengine/flexible/datastore. * revert update of appengine/flexible/scipy * revert update of bigquery/bqml * revert update of bigquery/cloud-client * revert update of bigquery/datalab-migration * revert update of bigtable/quickstart * revert update of compute/api * revert update of container_registry/container_analysis * revert update of dataflow/run_template * revert update of datastore/cloud-ndb * revert update of dialogflow/cloud-client * revert update of dlp * revert update of functions/imagemagick * revert update of functions/ocr/app * revert update of healthcare/api-client/fhir * revert update of iam/api-client * revert update of iot/api-client/gcs_file_to_device * revert update of iot/api-client/mqtt_example * revert update of language/automl * revert update of run/image-processing * revert update of vision/automl * revert update testing/requirements.txt * revert update of vision/cloud-client/detect * revert update of vision/cloud-client/product_search * revert update of jobs/v2/api_client * revert update of jobs/v3/api_client * revert update of opencensus * revert update of translate/cloud-client * revert update to speech/cloud-client Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Co-authored-by: Doug Mahugh * chore(deps): update dependency google-cloud-videointelligence to v1.14.0 [(#3169)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3169) * Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2806) * chore(deps): update dependency requests to v2.23.0 * Simplify noxfile and add version control. * Configure appengine/standard to only test Python 2.7. * Update Kokokro configs to match noxfile. * Add requirements-test to each folder. * Remove Py2 versions from everything execept appengine/standard. * Remove conftest.py. * Remove appengine/standard/conftest.py * Remove 'no-sucess-flaky-report' from pytest.ini. * Add GAE SDK back to appengine/standard tests. * Fix typo. * Roll pytest to python 2 version. * Add a bunch of testing requirements. * Remove typo. * Add appengine lib directory back in. * Add some additional requirements. * Fix issue with flake8 args. * Even more requirements. * Readd appengine conftest.py. * Add a few more requirements. * Even more Appengine requirements. * Add webtest for appengine/standard/mailgun. * Add some additional requirements. * Add workaround for issue with mailjet-rest. * Add responses for appengine/standard/mailjet. Co-authored-by: Renovate Bot * fix: changes positional to named pararameters in Video samples [(#4017)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4017) Changes calls to `VideoClient.annotate_video()` so that GCS URIs are provided as named parameters. Example: ``` operation = video_client.annotate_video(path, features=features) ``` Becomes: ``` operation = video_client.annotate_video(input_uri=path, features=features) ``` * Update dependency google-cloud-videointelligence to v1.15.0 [(#4041)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4041) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-cloud-videointelligence](https://togithub.com/googleapis/python-videointelligence) | minor | `==1.14.0` -> `==1.15.0` | --- ### Release Notes
googleapis/python-videointelligence ### [`v1.15.0`](https://togithub.com/googleapis/python-videointelligence/blob/master/CHANGELOG.md#​1150-httpswwwgithubcomgoogleapispython-videointelligencecomparev1140v1150-2020-06-09) [Compare Source](https://togithub.com/googleapis/python-videointelligence/compare/v1.14.0...v1.15.0) ##### Features - add support for streaming automl action recognition in v1p3beta1; make 'features' a positional param for annotate_video in betas ([#​31](https://www.github.com/googleapis/python-videointelligence/issues/31)) ([586f920](https://www.github.com/googleapis/python-videointelligence/commit/586f920a1932e1a813adfed500502fba0ff5edb7)), closes [#​517](https://www.github.com/googleapis/python-videointelligence/issues/517) [#​538](https://www.github.com/googleapis/python-videointelligence/issues/538) [#​565](https://www.github.com/googleapis/python-videointelligence/issues/565) [#​576](https://www.github.com/googleapis/python-videointelligence/issues/576) [#​506](https://www.github.com/googleapis/python-videointelligence/issues/506) [#​586](https://www.github.com/googleapis/python-videointelligence/issues/586) [#​585](https://www.github.com/googleapis/python-videointelligence/issues/585)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). * chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4279) * chore(deps): update dependency pytest to v5.4.3 * specify pytest for python 2 in appengine Co-authored-by: Leah Cole * Update dependency pytest to v6 [(#4390)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4390) * chore: pin sphinx * chore: adds samples templates * chore: temporarily pins sphinx * chore: blacken noxfile * chore: lints * chore(deps): update dependency google-cloud-videointelligence to v1.16.0 [(#4798)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4798) * chore: fixes flaky tests * chore(deps): update dependency pytest to v6.1.1 [(#4761)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4761) * chore(deps): update dependency pytest to v6.1.2 [(#4921)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4921) Co-authored-by: Charles Engelke * chore: updates samples templates * chore: cleans up merge conflicts * chore: blacken Co-authored-by: Gus Class Co-authored-by: Bill Prin Co-authored-by: florencep Co-authored-by: DPE bot Co-authored-by: Jon Wayne Parrott Co-authored-by: Yu-Han Liu Co-authored-by: michaelawyu Co-authored-by: Perry Stoll Co-authored-by: Frank Natividad Co-authored-by: michaelawyu Co-authored-by: Alix Hamilton Co-authored-by: Charles Engelke Co-authored-by: Yu-Han Liu Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Co-authored-by: Doug Mahugh Co-authored-by: WhiteSource Renovate Co-authored-by: Eric Schmidt Co-authored-by: Leah Cole Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com> Co-authored-by: Charles Engelke --- samples/analyze/README.rst | 27 +-- samples/quickstart/noxfile.py | 34 ++-- samples/shotchange/README.rst | 134 ++++++++++++ samples/shotchange/README.rst.in | 22 ++ samples/shotchange/noxfile.py | 246 +++++++++++++++++++++++ samples/shotchange/requirements-test.txt | 1 + samples/shotchange/requirements.txt | 1 + samples/shotchange/shotchange.py | 71 +++++++ samples/shotchange/shotchange_test.py | 27 +++ synth.metadata | 13 +- 10 files changed, 530 insertions(+), 46 deletions(-) create mode 100644 samples/shotchange/README.rst create mode 100644 samples/shotchange/README.rst.in create mode 100644 samples/shotchange/noxfile.py create mode 100644 samples/shotchange/requirements-test.txt create mode 100644 samples/shotchange/requirements.txt create mode 100644 samples/shotchange/shotchange.py create mode 100644 samples/shotchange/shotchange_test.py diff --git a/samples/analyze/README.rst b/samples/analyze/README.rst index ef0b7ed5..05a1557c 100644 --- a/samples/analyze/README.rst +++ b/samples/analyze/README.rst @@ -1,4 +1,3 @@ - .. This file is automatically generated. Do not edit this file directly. Google Cloud Video Intelligence API Python Samples @@ -16,11 +15,13 @@ This directory contains samples for Google Cloud Video Intelligence API. `Google .. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/docs + + + Setup ------------------------------------------------------------------------------- - Authentication ++++++++++++++ @@ -31,9 +32,6 @@ credentials for applications. .. _Authentication Getting Started Guide: https://cloud.google.com/docs/authentication/getting-started - - - Install Dependencies ++++++++++++++++++++ @@ -48,7 +46,7 @@ Install Dependencies .. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup -#. Create a virtualenv. Samples are compatible with Python 3.6+. +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. .. code-block:: bash @@ -64,15 +62,9 @@ Install Dependencies .. _pip: https://pip.pypa.io/ .. _virtualenv: https://virtualenv.pypa.io/ - - - - - Samples ------------------------------------------------------------------------------- - analyze +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -88,7 +80,6 @@ To run this sample: $ python analyze.py - usage: analyze.py [-h] {labels,labels_file,explicit_content,shots,transcribe,text_gcs,text_file,objects_gcs,objects_file} ... @@ -124,8 +115,6 @@ To run this sample: - - beta samples +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -141,7 +130,6 @@ To run this sample: $ python beta_snippets.py - usage: beta_snippets.py [-h] {transcription,video-text-gcs,video-text,track-objects-gcs,track-objects,streaming-labels,streaming-shot-change,streaming-objects,streaming-explicit-content,streaming-annotation-storage,streaming-automl-classification} ... @@ -189,10 +177,6 @@ To run this sample: - - - - The client library ------------------------------------------------------------------------------- @@ -208,5 +192,4 @@ to `browse the source`_ and `report issues`_. https://github.com/GoogleCloudPlatform/google-cloud-python/issues - -.. _Google Cloud SDK: https://cloud.google.com/sdk/ +.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file diff --git a/samples/quickstart/noxfile.py b/samples/quickstart/noxfile.py index ab2c4922..b90eef00 100644 --- a/samples/quickstart/noxfile.py +++ b/samples/quickstart/noxfile.py @@ -37,25 +37,28 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - "ignored_versions": ["2.7"], + 'ignored_versions': ["2.7"], + # Old samples are opted out of enforcing Python type hints # All new samples should feature them - "enforce_type_hints": False, + 'enforce_type_hints': False, + # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. - "envs": {}, + 'envs': {}, } try: # Ensure we can import noxfile_config in the project's directory. - sys.path.append(".") + sys.path.append('.') from noxfile_config import TEST_CONFIG_OVERRIDE except ImportError as e: print("No user noxfile_config found: detail: {}".format(e)) @@ -70,12 +73,12 @@ def get_pytest_env_vars(): ret = {} # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG["gcloud_project_env"] + env_key = TEST_CONFIG['gcloud_project_env'] # This should error out if not set. - ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] # Apply user supplied envs. - ret.update(TEST_CONFIG["envs"]) + ret.update(TEST_CONFIG['envs']) return ret @@ -84,7 +87,7 @@ def get_pytest_env_vars(): ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] # Any default versions that should be ignored. -IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) @@ -133,7 +136,7 @@ def _determine_local_import_names(start_dir): @nox.session def lint(session): - if not TEST_CONFIG["enforce_type_hints"]: + if not TEST_CONFIG['enforce_type_hints']: session.install("flake8", "flake8-import-order") else: session.install("flake8", "flake8-import-order", "flake8-annotations") @@ -142,11 +145,9 @@ def lint(session): args = FLAKE8_COMMON_ARGS + [ "--application-import-names", ",".join(local_names), - ".", + "." ] session.run("flake8", *args) - - # # Black # @@ -159,7 +160,6 @@ def blacken(session): session.run("black", *python_files) - # # Sample Tests # @@ -199,9 +199,9 @@ def py(session): if session.python in TESTED_VERSIONS: _session_tests(session) else: - session.skip( - "SKIPPED: {} tests are disabled for this sample.".format(session.python) - ) + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) # diff --git a/samples/shotchange/README.rst b/samples/shotchange/README.rst new file mode 100644 index 00000000..dea14f6e --- /dev/null +++ b/samples/shotchange/README.rst @@ -0,0 +1,134 @@ + +.. This file is automatically generated. Do not edit this file directly. + +Google Cloud Video Intelligence API Python Samples +=============================================================================== + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=video/cloud-client/shotchange/README.rst + + +This directory contains samples for Google Cloud Video Intelligence API. `Google Cloud Video Intelligence API`_ allows developers to easily integrate feature detection in video. + + + + +.. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/docs + + +Setup +------------------------------------------------------------------------------- + + + +Authentication +++++++++++++++ + +This sample requires you to have authentication setup. Refer to the +`Authentication Getting Started Guide`_ for instructions on setting up +credentials for applications. + +.. _Authentication Getting Started Guide: + https://cloud.google.com/docs/authentication/getting-started + + + + +Install Dependencies +++++++++++++++++++++ + +#. Clone python-docs-samples and change directory to the sample directory you want to use. + + .. code-block:: bash + + $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + +#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions. + + .. _Python Development Environment Setup Guide: + https://cloud.google.com/python/setup + +#. Create a virtualenv. Samples are compatible with Python 3.6+. + + .. code-block:: bash + + $ virtualenv env + $ source env/bin/activate + +#. Install the dependencies needed to run the samples. + + .. code-block:: bash + + $ pip install -r requirements.txt + +.. _pip: https://pip.pypa.io/ +.. _virtualenv: https://virtualenv.pypa.io/ + + + + + + +Samples +------------------------------------------------------------------------------- + + +Shot Change Detection ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +.. image:: https://gstatic.com/cloudssh/images/open-btn.png + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=video/cloud-client/shotchange/shotchange.py,video/cloud-client/shotchange/README.rst + + + + +To run this sample: + +.. code-block:: bash + + $ python shotchange.py + + + usage: shotchange.py [-h] path + + This application demonstrates how to identify all different shots + in a video using the Google Cloud Video Intelligence API. + + For more information, check out the documentation at + https://cloud.google.com/videointelligence/docs. + + Example Usage: + + python shotchange.py gs://cloud-samples-data/video/gbikes_dinosaur.mp4 + + positional arguments: + path GCS path for shot change detection. + + optional arguments: + -h, --help show this help message and exit + + + + + + + + + +The client library +------------------------------------------------------------------------------- + +This sample uses the `Google Cloud Client Library for Python`_. +You can read the documentation for more details on API usage and use GitHub +to `browse the source`_ and `report issues`_. + +.. _Google Cloud Client Library for Python: + https://googlecloudplatform.github.io/google-cloud-python/ +.. _browse the source: + https://github.com/GoogleCloudPlatform/google-cloud-python +.. _report issues: + https://github.com/GoogleCloudPlatform/google-cloud-python/issues + + + +.. _Google Cloud SDK: https://cloud.google.com/sdk/ diff --git a/samples/shotchange/README.rst.in b/samples/shotchange/README.rst.in new file mode 100644 index 00000000..6463d192 --- /dev/null +++ b/samples/shotchange/README.rst.in @@ -0,0 +1,22 @@ +# This file is used to generate README.rst + +product: + name: Google Cloud Video Intelligence API + short_name: Cloud Video Intelligence API + url: https://cloud.google.com/video-intelligence/docs + description: > + `Google Cloud Video Intelligence API`_ allows developers to easily + integrate feature detection in video. + +setup: +- auth +- install_deps + +samples: +- name: Shot Change Detection + file: shotchange.py + show_help: True + +cloud_client_library: true + +folder: video/cloud-client/shotchange \ No newline at end of file diff --git a/samples/shotchange/noxfile.py b/samples/shotchange/noxfile.py new file mode 100644 index 00000000..b90eef00 --- /dev/null +++ b/samples/shotchange/noxfile.py @@ -0,0 +1,246 @@ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function + +import os +from pathlib import Path +import sys + +import nox + + +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING +# DO NOT EDIT THIS FILE EVER! +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING + +# Copy `noxfile_config.py` to your directory and modify it instead. + + +# `TEST_CONFIG` dict is a configuration hook that allows users to +# modify the test configurations. The values here should be in sync +# with `noxfile_config.py`. Users will copy `noxfile_config.py` into +# their directory and modify it. + +TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + 'enforce_type_hints': False, + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} + + +try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append('.') + from noxfile_config import TEST_CONFIG_OVERRIDE +except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + +# Update the TEST_CONFIG with the user supplied values. +TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + + +def get_pytest_env_vars(): + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG['gcloud_project_env'] + # This should error out if not set. + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG['envs']) + return ret + + +# DO NOT EDIT - automatically generated. +# All versions used to tested samples. +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] + +# Any default versions that should be ignored. +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] + +TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) + +INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +# +# Style Checks +# + + +def _determine_local_import_names(start_dir): + """Determines all import names that should be considered "local". + + This is used when running the linter to insure that import order is + properly checked. + """ + file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] + return [ + basename + for basename, extension in file_ext_pairs + if extension == ".py" + or os.path.isdir(os.path.join(start_dir, basename)) + and basename not in ("__pycache__") + ] + + +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] +FLAKE8_COMMON_ARGS = [ + "--show-source", + "--builtin=gettext", + "--max-complexity=20", + "--import-order-style=google", + "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", + "--max-line-length=88", +] + + +@nox.session +def lint(session): + if not TEST_CONFIG['enforce_type_hints']: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") + + local_names = _determine_local_import_names(".") + args = FLAKE8_COMMON_ARGS + [ + "--application-import-names", + ",".join(local_names), + "." + ] + session.run("flake8", *args) +# +# Black +# + + +@nox.session +def blacken(session): + session.install("black") + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + +# +# Sample Tests +# + + +PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] + + +def _session_tests(session, post_install=None): + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars() + ) + + +@nox.session(python=ALL_VERSIONS) +def py(session): + """Runs py.test for a sample using the specified version of Python.""" + if session.python in TESTED_VERSIONS: + _session_tests(session) + else: + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) + + +# +# Readmegen +# + + +def _get_repo_root(): + """ Returns the root folder of the project. """ + # Get root of this repository. Assume we don't have directories nested deeper than 10 items. + p = Path(os.getcwd()) + for i in range(10): + if p is None: + break + if Path(p / ".git").exists(): + return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) + p = p.parent + raise Exception("Unable to detect repository root.") + + +GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) + + +@nox.session +@nox.parametrize("path", GENERATED_READMES) +def readmegen(session, path): + """(Re-)generates the readme for a sample.""" + session.install("jinja2", "pyyaml") + dir_ = os.path.dirname(path) + + if os.path.exists(os.path.join(dir_, "requirements.txt")): + session.install("-r", os.path.join(dir_, "requirements.txt")) + + in_file = os.path.join(dir_, "README.rst.in") + session.run( + "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file + ) diff --git a/samples/shotchange/requirements-test.txt b/samples/shotchange/requirements-test.txt new file mode 100644 index 00000000..b54b1d6f --- /dev/null +++ b/samples/shotchange/requirements-test.txt @@ -0,0 +1 @@ +pytest==6.1.2 diff --git a/samples/shotchange/requirements.txt b/samples/shotchange/requirements.txt new file mode 100644 index 00000000..85909592 --- /dev/null +++ b/samples/shotchange/requirements.txt @@ -0,0 +1 @@ +google-cloud-videointelligence==1.16.0 diff --git a/samples/shotchange/shotchange.py b/samples/shotchange/shotchange.py new file mode 100644 index 00000000..40edf001 --- /dev/null +++ b/samples/shotchange/shotchange.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python + +# Copyright 2017 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This application demonstrates how to identify all different shots +in a video using the Google Cloud Video Intelligence API. + +For more information, check out the documentation at +https://cloud.google.com/videointelligence/docs. + +Example Usage: + + python shotchange.py gs://cloud-samples-data/video/gbikes_dinosaur.mp4 + +""" + +# [START video_shot_tutorial] +# [START video_shot_tutorial_imports] +import argparse + +from google.cloud import videointelligence +# [END video_shot_tutorial_imports] + + +def analyze_shots(path): + """ Detects camera shot changes. """ + # [START video_shot_tutorial_construct_request] + video_client = videointelligence.VideoIntelligenceServiceClient() + features = [videointelligence.enums.Feature.SHOT_CHANGE_DETECTION] + operation = video_client.annotate_video(input_uri=path, features=features) + # [END video_shot_tutorial_construct_request] + print('\nProcessing video for shot change annotations:') + + # [START video_shot_tutorial_check_operation] + result = operation.result(timeout=120) + print('\nFinished processing.') + # [END video_shot_tutorial_check_operation] + + # [START video_shot_tutorial_parse_response] + for i, shot in enumerate(result.annotation_results[0].shot_annotations): + start_time = (shot.start_time_offset.seconds + + shot.start_time_offset.nanos / 1e9) + end_time = (shot.end_time_offset.seconds + + shot.end_time_offset.nanos / 1e9) + print('\tShot {}: {} to {}'.format(i, start_time, end_time)) + # [END video_shot_tutorial_parse_response] + + +if __name__ == '__main__': + # [START video_shot_tutorial_run_application] + parser = argparse.ArgumentParser( + description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('path', help='GCS path for shot change detection.') + args = parser.parse_args() + + analyze_shots(args.path) + # [END video_shot_tutorial_run_application] +# [END video_shot_tutorial] diff --git a/samples/shotchange/shotchange_test.py b/samples/shotchange/shotchange_test.py new file mode 100644 index 00000000..0722e0c6 --- /dev/null +++ b/samples/shotchange/shotchange_test.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +# Copyright 2017 Google, Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import pytest + +import shotchange + + +@pytest.mark.slow +def test_shots_dino(capsys): + shotchange.analyze_shots( + 'gs://cloud-samples-data/video/gbikes_dinosaur.mp4') + out, _ = capsys.readouterr() + assert 'Shot 1:' in out diff --git a/synth.metadata b/synth.metadata index 8156811d..8791655f 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,31 +3,30 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-videointelligence.git", - "sha": "2d3b73496f1a50122b7a9bfbfa1d5e13bb2e06ff" + "remote": "git@github.com:googleapis/python-videointelligence.git", + "sha": "8ecf08ee0310d149f83c6496b7fa78f603122d8a" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "20b11dfe4538cd5da7b4c3dd7d2bf5b9922ff3ed", - "internalRef": "338646463" + "sha": "6a69c750c3f01a69017662395f90515bbf1fe1ff", + "internalRef": "342721036" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "9b0da5204ab90bcc36f8cd4e5689eff1a54cc3e4" + "sha": "d5fc0bcf9ea9789c5b0e3154a9e3b29e5cea6116" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "9b0da5204ab90bcc36f8cd4e5689eff1a54cc3e4" - + "sha": "d5fc0bcf9ea9789c5b0e3154a9e3b29e5cea6116" } } ],