Skip to content

Commit

Permalink
Migrate from Travis CI to GitHub Actions (#10)
Browse files Browse the repository at this point in the history
* Create ci.yaml

Add example setup from https://github.com/pypa/cibuildwheel#example-setup

* Delete .travis.yml

* Remove shields

* Use reusable workflow

* Delete setup.py

* Create pyproject.toml

* Remove Python 2 classifiers

* `prettier`

* `pyupgrade --py36-plus`

* Require minimum setuptools that supports project key in pyproject.toml

* `prettier`

* Remove six

* Don't specify Python 3 minor versions

* Set black line length to 120

* `black`

* Add direnv

* Add development instructions and remove mention of SoundCloud API

* Install youtube-dl from GitHub

* Enable setuptools-scm

* Add pre-commit hooks for formatting, etc.

* Add lint and test steps

* Replace `pafy` with `youtube-dl`

Since `pafy` is no longer maintained, replace it with calling
`youtube-dl` directly.

* Format

* Add verbose flag

* Expose __version__

* Show info logging during pytest

* Replace soundcloud with sclib

Not working yet but it's a start.

* Add TODO

* Add TODO

* Only test latest push

* Add download limit

* Set minimum Python to 3.8

* Set job name to package name
  • Loading branch information
carlthome authored Jun 25, 2023
1 parent 236dce2 commit aeae33b
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 189 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
layout python
17 changes: 17 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
audioscrape:
uses: carlthome/workflows/.github/workflows/python.yaml@main
with:
package-name: audioscrape
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ ENV/
.idea
*.iml


.direnv
version.py
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/asottile/pyupgrade
rev: v3.7.0
hooks:
- id: pyupgrade
args: [--py310-plus]

- repo: https://github.com/pycqa/autoflake
rev: v2.2.0
hooks:
- id: autoflake

- repo: https://github.com/psf/black
rev: "23.3.0"
hooks:
- id: black
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

49 changes: 35 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
# Audioscrape
[![Build Status](https://travis-ci.org/carlthome/audio-scraper.svg?branch=master)](https://travis-ci.org/carlthome/audio-scraper)
[![PyPI](https://img.shields.io/pypi/v/audioscrape.svg)](https://pypi.python.org/pypi/audioscrape)
[![PyPI](https://img.shields.io/pypi/pyversions/audioscrape.svg)](http://py3readiness.org/)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)

Scrape audio from various websites with a simple command-line interface.

# Install
First make sure Python and pip are installed, then run:
## Usage

First make sure Python is installed, then run:

```sh
pip install audioscrape
```

# Usage
Then you can use the program as:

```sh
audioscrape "acoustic guitar"
```

See `audioscrape --help` for more details.

## Python API
You could also use the scraper directly in Python, as:
### Python API

You can also use the scraper directly in Python, as:

```python
import audioscrape

audioscrape.download(query='Cerulean Crayons',
include=['guitar'],
exclude=['remix'],
audioscrape.download(query="Cerulean Crayons",
include=["guitar"],
exclude=["remix"],
quiet=True)
```

## SoundCloud API key and download limits
This program uses SoundCloud's official Python API which requires a registered API key. SoundCloud says an API key can be used for 15,000 requests per any 24-hour time window, and a key has been included in the program. However, in case the key stops working, register another one [as described by SoundCloud here](https://github.com/soundcloud/soundcloud-python#basic-use), and use the scraper after setting the environment variable `SOUNDCLOUD_API_KEY`, as `SOUNDCLOUD_API_KEY="your_key" audioscrape "piano music"`.
## Develop

First clone the repo and set it as working directory. Then install the package in development mode (preferably within its own virtual environment):

```sh
pip install -e .
```

If you have `direnv` installed, you can run `direnv allow` to automatically create and activate a Python virtual environment when you enter the directory.

### Test

```sh
pytest
```

### Lint

```sh
pre-commit run --all-files
```

Or `pre-commit install` to run automatically on `git commit`.
6 changes: 4 additions & 2 deletions audioscrape/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# coding=utf-8
"""YouTube audio scraper package."""
from .__main__ import download
__all__ = ['download']
from .version import version

__all__ = ["download"]
__version__ = version
66 changes: 24 additions & 42 deletions audioscrape/__main__.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,43 @@
# coding=utf-8
"""Download audio."""
import argparse
import logging
import sys

from . import soundcloud, youtube

logger = logging.getLogger(__name__)

def download(query, include=None, exclude=None, quiet=False, overwrite=False):

def download(query, include, exclude, quiet, verbose, overwrite, limit):
"""Scrape various websites for audio."""
youtube.scrape(query, include, exclude, quiet, overwrite)
soundcloud.scrape(query, include, exclude, quiet, overwrite)
youtube.scrape(query, include, exclude, quiet, verbose, overwrite, limit)
soundcloud.scrape(query, include, exclude, quiet, verbose, overwrite, limit)


def cli(args=None):
"""CLI for scraping audio."""

parser = argparse.ArgumentParser()
parser.add_argument(
'query',
default="Cerulean Crayons",
nargs='?',
help="search terms")
parser.add_argument(
'-i',
'--include',
default=[],
action='append',
help="only download audio with this tag"
)
parser.add_argument(
'-e',
'--exclude',
default=[],
action='append',
help="ignore results with this tag"
)
parser.add_argument(
'-q',
'--quiet',
default=False,
action='store_true',
help="hide progress reporting")
parser.add_argument(
'-o',
'--overwrite',
default=False,
action='store_true',
help="overwrite existing files")
parser.add_argument("query", default="Cerulean Crayons", nargs="?", help="search terms")
parser.add_argument("-i", "--include", default=[], action="append", help="only download audio with this tag")
parser.add_argument("-e", "--exclude", default=[], action="append", help="ignore results with this tag")
parser.add_argument("-q", "--quiet", default=False, action="store_true", help="hide progress reporting")
parser.add_argument("-v", "--verbose", default=False, action="store_true", help="display debug information")
parser.add_argument("-o", "--overwrite", default=False, action="store_true", help="overwrite existing files")
parser.add_argument("-l", "--limit", default=10, type=int, help="limit number of downloads")
args = parser.parse_args()

if not args.quiet:
print('Downloading audio from "{}" videos tagged {} and not {}.'.
format(args.query, args.include, args.exclude))
download(args.query, args.include, args.exclude, args.quiet,
args.overwrite)
if not args.quiet:
print("Finished downloading audio.")
logging.basicConfig(format="[%(name)s] %(message)s")
if args.verbose:
logger.setLevel(logging.DEBUG)
elif args.quiet:
logger.setLevel(logging.ERROR)
else:
logger.setLevel(logging.INFO)

logger.info(f'Downloading audio from "{args.query}" videos tagged {args.include} and not {args.exclude}.')
download(args.query, args.include, args.exclude, args.quiet, args.verbose, args.overwrite, args.limit)
logger.info("Finished downloading audio.")


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions audioscrape/classify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO Add machine listening help functionality to easily categorize downloaded audio.
1 change: 1 addition & 0 deletions audioscrape/freesound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
Loading

0 comments on commit aeae33b

Please sign in to comment.