Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle config.yaml and acrcloudscan cli #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ $ python3 -m pip install -r requirements.txt
```


4. Copy `config.yaml.example` and save as `config.yaml`. Change the content of `config.yaml`, fill in your host, access_key and access_secret.
4. Copy `config.yaml.example` and save as `config.yaml`. Change the content of `config.yaml`, fill in your host, access_key and access_secret. You can save on ̣̣`~/.acrcloudscan/config.yaml` or `/etc/acrcloud/scan/config.yaml`


5. Run the script to scan your audio/video files:
```bash
$ python main.py -t ~/test/test.mp4
$ acrscancloud -t ~/test/test.mp4
```
## Usage

Expand Down Expand Up @@ -97,12 +97,12 @@ Options:
- with played duration:

```bash
$ python main.py -t ~/test/test.mp4 -w
$ acrcloudscan -t ~/test/test.mp4 -w
```
- with played duration and filter results

```bash
$ python main.py -t ~/test/test.mp4 -w --filter-results
$ acrcloudscan -t ~/test/test.mp4 -w --filter-results
```

## Using Docker
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
102 changes: 102 additions & 0 deletions acrcloudscan/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from .acrscan.lib_downloader import download_lib, current_platform

try:
from .acrscan.acrscan import ACRCloudScan
except ImportError:
download_lib()
from .acrscan.acrscan import ACRCloudScan
import logging
import yaml
import click
import sys
import os

CONFIGS_FILES = ['config.yaml', "~/.acrcloudscan/config.yaml", "/etc/acrcloud/scan/config.yaml"]

config_file = None
for conf in CONFIGS_FILES:
conf_path = os.path.expanduser(conf)
if os.path.exists(conf_path):
config_file = conf_path
break

if config_file is None:
logging.error("Please make sure you fill the config.yaml in some of the following paths: {}".format(CONFIGS_FILES))
raise ValueError()

with open(config_file, 'r') as f:
try:
config_dict = yaml.safe_load(f)
except yaml.YAMLError as exc:
logging.error(exc)

acrcloud_config = config_dict.get('acrcloud')

if acrcloud_config.get('debug'):
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)


class OptionRequiredIf(click.Option):

def full_process_value(self, ctx, value):
value = super(OptionRequiredIf, self).full_process_value(ctx, value)
if not ctx.params.get('with_duration') and value:
msg = 'Required --with-duration, if you want filter pls add --with-duration'
raise click.MissingParameter(ctx=ctx, param=self, message=msg)
return value


@click.command()
@click.option('--target', '-t',
help='The target need to scan (a folder or a file).', required=True)
@click.option('--output', '-o', default='',
help='Output result to this folder. (Must be a folder path)')
@click.option('--format', 'output_format', type=click.Choice(['csv', 'json']),
help='output format.(csv or json)')
@click.option('--with-duration/--no-duration', '-w', default=False,
help='Add played duration to the result')
@click.option('--filter-results/--no-filter', default=False,
help='Enable filter.(It must be used when the with-duration option is on)', cls=OptionRequiredIf)
@click.option('--split-results/--no-split', '-p', default=False,
help='Each audio/video file generate a report')
@click.option('--scan-type', '-c', type=click.Choice(['music', 'custom', 'both']), default='both',
help='scan type')
@click.option('--start-time-ms', '-s', default=0,
help='scan start time')
@click.option('--end-time-ms', '-e', default=0,
help='scan end time')
@click.option('--is-fp/--not-fp', '-f', default=False,
help='scan fingerprint')
@click.option('--interval', '-i', default=10,
help='interval')
def main(target, output, output_format, with_duration, filter_results, split_results, scan_type, start_time_ms,
end_time_ms, is_fp, interval):
ctx = click.get_current_context()
if not any(v for v in ctx.params.values()):
click.echo(ctx.get_help())
ctx.exit()

platform = current_platform()
fp_support_platforms = ['linux_64', 'mac']
if is_fp and platform not in fp_support_platforms:
print('Your system not support scan fingerprint')
sys.exit()
acr = ACRCloudScan(acrcloud_config)
acr.with_duration = with_duration
acr.filter_results = filter_results
acr.split_results = split_results
acr.scan_type = scan_type
acr.start_time_ms = start_time_ms * 1000
acr.end_time_ms = end_time_ms * 1000
acr.is_fingerprint = is_fp
acr.interval_length_ms = interval * 1000
acr.scan_main(target, output, output_format)


if __name__ == '__main__':
main()
10 changes: 9 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
import yaml
import click
import sys
import os

with open('config.yaml', 'r') as f:
CONFIGS_FILES = ["~/.acrcloud/config.yaml" , 'config.yaml']

for conf in CONFIGS_FILES:
if os.path.exists(conf):
config_file = conf
break

with open(config_file, 'r') as f:
try:
config_dict = yaml.safe_load(f)
except yaml.YAMLError as exc:
Expand Down
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "acrcloudscan"
version = "0.0.1"
dependencies = [
"retrying",
"click",
"python-dateutil",
"tqdm",
"fuzzywuzzy",
"ffmpeg-python",
"PyYAML",
"urllib3"
]

[project.scripts]
acrcloudscan = "acrcloudscan.main:main"