Skip to content

Instantly share code, notes, and snippets.

@akamhy
Last active June 3, 2023 04:59
Show Gist options
  • Save akamhy/7d7f50b1d2b9c66679e7fe16adb52c15 to your computer and use it in GitHub Desktop.
Save akamhy/7d7f50b1d2b9c66679e7fe16adb52c15 to your computer and use it in GitHub Desktop.
VideoHash CLI interface
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
#
# In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from videohash import VideoHash
import click
import sys
import os
@click.command()
@click.option("--path", default=None, help="Absolute path of the video file.")
@click.option(
"--url",
default=None,
help="URL of the video file. Every URL that is supported by the yt-dlp package can be used.",
)
@click.option(
"--storage-path",
default=None,
help="If you want to provide a storage path for the files created/downloaded by the instance, pass the absolute path to that directory.",
)
@click.option(
"--download-worst",
is_flag=True,
help="Download the worst quality video if possible.",
)
def main(path, url, storage_path, download_worst):
_storage_path = None
if storage_path:
_storage_path = storage_path.strip()
if not _storage_path.endswith(os.path.sep):
_storage_path = _storage_path + os.path.sep
click.echo(
VideoHash(
path=path, url=url, download_worst=download_worst, storage_path=_storage_path
).hash
)
if __name__ == "__main__":
try:
sys.exit(main())
except Exception as e:
click.echo(e)
sys.exit(-1)
@akamhy
Copy link
Author

akamhy commented Nov 12, 2021

Install videohash and click then
Try:
python3 cli.py --path /home/akamhy/Downloads/rockets.mkv

or:
python cli.py --url https://www.youtube.com/watch?v=PapBjpzRhnA

help:
python cli.py --help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment