Skip to content

Commit

Permalink
パッケージ版のエラー対応
Browse files Browse the repository at this point in the history
  • Loading branch information
soramugi committed Apr 20, 2020
1 parent d38731d commit 862a229
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 60 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,22 @@
ポッドキャスト取得クライアントに貼り付けてコンテンツのダウンロードが行える

Mac、iPhoneであれば `Apple Podcast`
Androidであれば `Podcast Addict`
Androidであれば `Podcast Addict` (ファイル名によっては取得に失敗します)

で取得が可能

## 開発環境
配信クライアントPCは固定IPにしておく事をお勧めします。

## 今後の開発予定項目

- [ ] Android版での取得失敗原因調査
- [ ] Windows環境の実行
- [ ] Linux環境での実行
- [ ] ファイルの再生時間をfeedに追加
- [ ] travisでの自動ビルドに対応
- [ ] IP直アクセスを回避できないか?

## 開発環境構築

> An electron-vue project
Expand Down
8 changes: 8 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { app, BrowserWindow, clipboard, dialog, nativeImage, Menu, Tray } from 'electron'
import Store from 'electron-store'
import log from 'electron-log'
import ip from 'ip'
import path from 'path'
import QRCode from 'qrcode'
Expand Down Expand Up @@ -117,6 +118,13 @@ app.on('activate', () => {
}
})

process.on('uncaughtException', function (err) {
log.error('electron:event:uncaughtException')
log.error(err)
log.error(err.stack)
app.quit()
})

/**
* Auto Updater
*
Expand Down
126 changes: 68 additions & 58 deletions src/main/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Podcast from 'podcast'
import path from 'path'
import util from 'util'
import Store from 'electron-store'
import log from 'electron-log'
import fs from 'fs'
import { getAudioDurationInSeconds } from 'get-audio-duration'
// import { getAudioDurationInSeconds } from 'get-audio-duration'

const glob = util.promisify(require('glob'))

Expand All @@ -15,72 +16,81 @@ app.use('/static', express.static(__static))
app.use('/media', express.static(store.get('media.path')))

app.get('/rss.xml', async function (req, res) {
res.set('Content-Type', 'text/xml; charset=utf-8')
try {
res.set('Content-Type', 'text/xml; charset=utf-8')

// 音声ファイルの取得パス作成、store.get('media.path')は可変なのでrss取得時に再設定
app.use('/media', express.static(store.get('media.path')))
// 音声ファイルの取得パス作成、store.get('media.path')は可変なのでrss取得時に再設定
app.use('/media', express.static(store.get('media.path')))

const imageUrl = __url + '/static/feed_icon.png'
const feed = new Podcast({
title: 'yotaka',
description: '家庭内Podcast配信サーバー',
site_url: 'https://github.com/soramugi/yotaka',
image_url: imageUrl,
docs: 'https://github.com/soramugi/yotaka',
author: 'yotaka',
// pubDate: 'May 20, 2012 04:00:00 GMT',
itunesImage: imageUrl,
itunesSummary: '',
itunesAuthor: 'yotaka'
})
const imageUrl = __url + '/static/feed_icon.png'
const feed = new Podcast({
title: 'yotaka',
description: '家庭内Podcast配信サーバー',
site_url: 'https://github.com/soramugi/yotaka',
image_url: imageUrl,
docs: 'https://github.com/soramugi/yotaka',
author: 'yotaka',
// pubDate: 'May 20, 2012 04:00:00 GMT',
itunesImage: imageUrl,
itunesSummary: '',
itunesAuthor: 'yotaka'
})

const files = await glob(path.join(store.get('media.path'), '*.*'))
const files = await glob(path.join(store.get('media.path'), '*.*'))

const list = []
for (const file of files) {
const extname = path.extname(file)
const list = []
for (const file of files) {
const extname = path.extname(file)

// 対応音声ファイル: M4A, MP3, MOV, MP4, M4V
if (!extname.match(/\.m4a|\.mp3|\.mov|\.mp4|\.m4v/i)) {
continue
// 対応音声ファイル: M4A, MP3, MOV, MP4, M4V
if (!extname.match(/\.m4a|\.mp3|\.mov|\.mp4|\.m4v/i)) {
continue
}
const title = path.basename(file, extname)
const stats = fs.statSync(file)
const date = stats.atime
const url = __url + '/media/' + path.basename(file)
// TODO パッケージ作成するとspawnエラーが出るので対応
// const duration = await getAudioDurationInSeconds(file)
const duration = ''
list.push({
file,
date,
title,
url,
duration
})
}
const title = path.basename(file, extname)
const stats = fs.statSync(file)
const date = stats.atime
const url = __url + '/media/' + path.basename(file)
const duration = await getAudioDurationInSeconds(file)
list.push({
file,
date,
title,
url,
duration
})
}
// 並び順をファイルの作成日時順(降順)に
list.sort((a, b) => b.date - a.date)
// 並び順をファイルの作成日時順(降順)に
list.sort((a, b) => b.date - a.date)

for (const data of list) {
const file = data.file
const date = data.date
const title = data.title
const url = data.url
const duration = data.duration
feed.addItem({
title,
url,
description: title,
date,
enclosure: {
for (const data of list) {
const file = data.file
const date = data.date
const title = data.title
const url = data.url
const duration = data.duration
feed.addItem({
title,
url,
file
},
itunesSubtitle: title,
itunesDuration: duration
})
}
description: title,
date,
enclosure: {
url,
file
},
itunesSubtitle: title,
itunesDuration: duration
})
}

res.send(feed.buildXml(' '))
res.send(feed.buildXml(' '))
} catch (e) {
log.error('express')
log.error(e)
log.error(e.stack)
res.send(e)
}
})

app.listen(__port, () => console.log('App listening on port ' + __port + '!'))

0 comments on commit 862a229

Please sign in to comment.