Commit 4604b4da authored by Genar Trias Ortiz's avatar Genar Trias Ortiz 🎉

Successfully importing M3U files

parent cfa94baa
# .editorconfig
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
trim_trailing_whitespace = true
charset = utf-8
indent_size = 2
import React, { Component } from 'react';
import parsers from 'playlist-parser'
import saveCollectionItems from '../db/collection-store'
const getAsText = (readFile) => {
var reader = new FileReader()
......@@ -25,16 +27,11 @@ const updateProgress = (evt) => {
const loaded = (evt) => {
// Obtain the read file data
var fileString = evt.target.result;
console.log(fileString)
// Handle UTF-16 file dump
// if(utils.regexp.isChinese(fileString)) {
//Chinese Characters + Name validation
// }
// else {
// run other charset test
// }
// xhr.send(fileString)
const fileString = evt.target.result
const M3U = parsers.M3U
const playlist = M3U.parse(fileString)
saveCollectionItems(playlist)
console.log(playlist)
}
const errorHandler = (evt) => {
......@@ -52,7 +49,7 @@ export default class Importer extends Component {
}
startImport() {
const file = this.fileInput.current[0]
const file = this.fileInput.current.files[0]
if (file) {
getAsText(file)
}
......
38410
\ No newline at end of file
import PouchDB from 'pouchdb'
import md5 from 'md5'
// Save playlist items to collection
const saveCollectionItems = (playlist) => {
const db = new PouchDB('collection')
const bulkItems = []
playlist.forEach((plItem) => {
plItem._id = md5(plItem.file)
bulkItems.push(plItem)
})
db.bulkDocs(bulkItems)
.then(() => {
console.log('Collection saved!')
})
.catch((e) => {
console.error('%j error occurred', e)
})
}
export default saveCollectionItems
......@@ -1402,6 +1402,10 @@ chardet@^0.4.0:
version "0.4.2"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
charenc@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
chokidar@^1.6.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
......@@ -1750,6 +1754,10 @@ cross-spawn@5.1.0, cross-spawn@^5.0.1, cross-spawn@^5.1.0:
shebang-command "^1.2.0"
which "^1.2.9"
crypt@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
cryptiles@3.x.x:
version "3.1.2"
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-3.1.2.tgz#a89fbb220f5ce25ec56e8c4aa8a4fd7b5b0d29fe"
......@@ -3566,7 +3574,7 @@ is-binary-path@^1.0.0:
dependencies:
binary-extensions "^1.0.0"
is-buffer@^1.1.5:
is-buffer@^1.1.5, is-buffer@~1.1.1:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
......@@ -4666,6 +4674,14 @@ md5.js@^1.3.4:
hash-base "^3.0.0"
inherits "^2.0.1"
md5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9"
dependencies:
charenc "~0.0.1"
crypt "~0.0.1"
is-buffer "~1.1.1"
media-typer@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment