Skip to content

Commit

Permalink
Merge pull request #2 from JounQin/master
Browse files Browse the repository at this point in the history
chore(release): 0.1.1
  • Loading branch information
JounQin committed Jul 22, 2019
2 parents fbd3fe6 + 98dfb46 commit 3cf348f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 97 deletions.
5 changes: 5 additions & 0 deletions .versionrc
@@ -0,0 +1,5 @@
{
"skip": {
"bump": true
}
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 0.1.0 (2019-07-20)


### Features

* first blood, cli + js API support ([66fe30c](https://github.com/JounQin/aerial-links/commit/66fe30c))
3 changes: 2 additions & 1 deletion README.md
@@ -1,6 +1,6 @@
# aerial-links

[![Travis](https://img.shields.io/travis/JounQin/aerial-links.svg)](https://travis-ci.com/JounQin/aerial-links)
[![Travis](https://img.shields.io/travis/com/JounQin/aerial-links.svg)](https://travis-ci.com/JounQin/aerial-links)
[![David](https://img.shields.io/david/JounQin/aerial-links.svg)](https://david-dm.org/JounQin/aerial-links)
[![David Dev](https://img.shields.io/david/dev/JounQin/aerial-links.svg)](https://david-dm.org/JounQin/aerial-links?type=dev)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
Expand Down Expand Up @@ -30,6 +30,7 @@ Options:
-t, --type <type> export video type, valid types: all, url-1080-H264, url-1080-HDR, url-1080-SDR, url-4K-HDR, url-4K-SDR (default: "all")
-j, --json output json format
-n, --no-copy do not copy to clipboard
-p, --cache-path custom aerial cache path to read `entries.json`
-f, --file <path> filename to export the content, default to print directly
-h, --help output usage information
```
Expand Down
11 changes: 3 additions & 8 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "aerial-links",
"version": "0.1.0",
"version": "0.1.1",
"description": "Get all Aerial video links automatically from its `entries.json`.",
"repository": "git@github.com:JounQin/aerial-links.git",
"author": "JounQin <admin@1stg.me>",
Expand All @@ -26,18 +26,13 @@
"@types/debug": "^4.1.4",
"@types/node": "^12.6.8",
"commitlint": "^8.1.0",
"eslint": "^6.0.1",
"eslint-config-1stg": "^5.3.0",
"eslint": "^6.1.0",
"eslint-config-1stg": "^5.3.1",
"husky": "^3.0.1",
"lint-staged": "^9.2.0",
"prettier": "^1.18.2",
"standard-version": "^6.0.1",
"ts-node": "^8.3.0",
"typescript": "^3.5.3"
},
"standard-version": {
"skip": {
"bump": true
}
}
}
16 changes: 7 additions & 9 deletions src/bin.ts
Expand Up @@ -8,8 +8,8 @@ import { write } from 'clipboardy'
import _program, { CommanderStatic } from 'commander'

import {
Options,
VALID_TYPES_TIP,
ExportType,
debug,
debugNs,
forceDebug,
Expand All @@ -21,18 +21,16 @@ import _debug from 'debug'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require('../package.json')

export interface Options {
export interface CliOptions extends Options {
debug?: boolean
exclude?: boolean
file?: string
json?: boolean
noCopy?: boolean
type?: ExportType
}

const writeFile = promisify(fs.writeFile)
const copy = promisify(write)
const program: CommanderStatic & Options = _program
const program: CommanderStatic & CliOptions = _program

program
.version(version)
Expand All @@ -41,23 +39,23 @@ program
.option('-t, --type <type>', VALID_TYPES_TIP, 'all')
.option('-j, --json', 'output json format')
.option('-n, --no-copy', 'do not copy to clipboard')
.option('-p, --cache-path', 'custom aerial cache path to read `entries.json`')
.option(
'-f, --file <path>',
'filename to export the content, default to print directly',
)

program.parse(process.argv)
.parse(process.argv)

if (program.debug) {
_debug.enable(debugNs)
}

export const newLine = (content: string) => '\n' + content

const { exclude, file, json, noCopy, type } = program
const { exclude, file, json, noCopy, type, cachePath } = program

const main = async () => {
const links = await getAerialLinks(type, exclude)
const links = await getAerialLinks({ type, exclude, cachePath })

const plainOutput = links.join('\n')
const output = json ? JSON.stringify(json) : plainOutput
Expand Down
52 changes: 40 additions & 12 deletions src/index.ts
Expand Up @@ -12,7 +12,10 @@ const readDir = promisify(fs.readdir)
const readFile = promisify(fs.readFile)

const USER_NAME = userInfo().username
const CACHE_PATH = `/Users/${USER_NAME}/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Library/Application Support/Aerial`
const CACHE_PATHS = [
`/Users/${USER_NAME}/Library/Application Support/Aerial`,
`/Users/${USER_NAME}/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Library/Application Support/Aerial`,
]
const ENTRIES_JSON = 'entries.json'

export const EXPORT_TYPES = [
Expand Down Expand Up @@ -59,15 +62,40 @@ export const forceDebug: Debugger = (...args) => {
}
}

export async function getAerialLinks(
exportType: ExportType = 'all',
export interface Options {
type?: ExportType
exclude?: boolean
cachePath?: string
}

export async function getAerialLinks({
type = 'all',
exclude = false,
) {
const filePath = path.join(CACHE_PATH, ENTRIES_JSON)
cachePath,
}: Options) {
let filePath!: string

if (cachePath) {
try {
filePath = path.join(cachePath, ENTRIES_JSON)
await access(filePath)
} catch (e) {
cachePath = ''
}
}

for (const p of CACHE_PATHS) {
filePath = path.join(p, ENTRIES_JSON)
try {
await access(filePath)
cachePath = p
break
} catch (e) {
continue
}
}

try {
await access(filePath)
} catch (e) {
if (!cachePath) {
forceDebug(
'warning: %s',
'Please make sure Aerial has been installed correctly, you can try `brew cask install jounqin/x/aerial-beta`',
Expand All @@ -76,10 +104,10 @@ export async function getAerialLinks(
}

const { assets }: Entries = JSON.parse((await readFile(filePath)).toString())
const files = exclude ? await readDir(CACHE_PATH) : []
const files = exclude ? await readDir(cachePath) : []
return assets.reduce<string[]>((links, asset) => {
let toAddLinks: string[]
switch (exportType) {
switch (type) {
case 'all':
toAddLinks = [
asset['url-1080-H264'],
Expand All @@ -90,8 +118,8 @@ export async function getAerialLinks(
]
break
default: {
if (exportType && exportType in asset) {
toAddLinks = [asset[exportType]]
if (type && type in asset) {
toAddLinks = [asset[type]]
} else {
throw new TypeError(INVALID_TYPES_TIP)
}
Expand Down

0 comments on commit 3cf348f

Please sign in to comment.