Skip to content
Snippets Groups Projects
Commit ed9aad40 authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

DPSounds fixes.

- Tags in attributes
- Duration in attributes
- Attributes actually work now
- Audio samples
- Downloadable files
parent 476bb948
No related branches found
No related tags found
No related merge requests found
Pipeline #44 passed with stage
in 2 minutes and 1 second
...@@ -18,6 +18,7 @@ setup( ...@@ -18,6 +18,7 @@ setup(
install_requires=[ install_requires=[
'awesome-slugify==1.6.5', 'awesome-slugify==1.6.5',
'lxml==3.7.0', 'lxml==3.7.0',
'phpserialize==1.3',
], ],
entry_points=''' entry_points='''
[console_scripts] [console_scripts]
......
...@@ -8,7 +8,7 @@ Usage: {0} adapter input_file ...@@ -8,7 +8,7 @@ Usage: {0} adapter input_file
adapter: an import adapter adapter: an import adapter
input_file: the source file you want to convert input_file: the source file you want to convert
Available import adapters: ecwid Available import adapters: ecwid, dpsounds
Output will be written to: Output will be written to:
......
import csv import csv
import json import json
import hashlib import hashlib
import phpserialize
from .adapter import Adapter as BaseAdapter from .adapter import Adapter as BaseAdapter
from ..constants import (ALLOWED_HTML_TAGS, HTML_FIELDS, from ..constants import (ALLOWED_HTML_TAGS, HTML_FIELDS,
WOO_IMP_EXP_PRODUCT_FIELDS) WOO_IMP_EXP_PRODUCT_FIELDS)
DP_TRACK_URL_BASE = 'https://ant.sr/dpsounds-audio' DP_TRACK_URL_BASE = 'https://dpsounds.com/wp-content/uploads/tracks'
DP_SAMPLE_URL_BASE = 'https://dpsounds.com/wp-content/uploads/samples'
DP_TRACK_CATEGORIES = json.dumps([{'name': 'Music', 'slug': 'music'}]) DP_TRACK_CATEGORIES = json.dumps([{'name': 'Music', 'slug': 'music'}])
DP_TRACK_ATTRIBUTES = ['Time', 'Origin'] DP_TRACK_ATTRIBUTES = ['Duration', 'Time', 'Origin', 'Tags']
WP_ATTRS = {
'Duration': 'pa_duration',
'Time': 'pa_time',
'Origin': 'pa_origin',
'Tags': 'pa_tags',
}
DP_TRACK_PRICE = 1 DP_TRACK_PRICE = 1
...@@ -17,7 +25,7 @@ class DpsoundsAdapter(BaseAdapter): ...@@ -17,7 +25,7 @@ class DpsoundsAdapter(BaseAdapter):
Headers: Headers:
"Source Part","Source Track","Track", "Source Part","Source Track","Track",
"Title","Time","Origin","Tags", "Title","Time","Origin","Tags",
"Alternative Takes","Compilation". "Alternative Takes","Compilation","Duration".
""" """
def parse(self, filename): def parse(self, filename):
...@@ -28,38 +36,64 @@ class DpsoundsAdapter(BaseAdapter): ...@@ -28,38 +36,64 @@ class DpsoundsAdapter(BaseAdapter):
name = "Track {}".format(r['Track']) name = "Track {}".format(r['Track'])
if r['Title']: if r['Title']:
name += " - {}".format(r['Title']) name += " - {}".format(r['Title'])
tags = ','.join([t.strip() for t in r['Tags'].split(',')]) r['Tags'] = ','.join([t.strip() for t in r['Tags'].split(',')])
file_url = "{url_base}/{part}-{track:02d}.mp3".format( file_url = "{url_base}/{part}-{track:02d}.mp3".format(
url_base=DP_TRACK_URL_BASE, url_base=DP_TRACK_URL_BASE,
part=r['Source Part'], part=r['Source Part'],
track=int(r['Source Track'])) track=int(r['Source Track']))
filehash = hashlib.md5(file_url.encode('utf-8')).hexdigest() filehash = hashlib.md5(file_url.encode('utf-8')).hexdigest()
files = json.dumps({ files = {filehash: {'name': name, 'file': file_url}}
filehash: {'name': name, 'file': file_url}})
# TODO: alternative takes # TODO: alternative takes
# TODO: compilation (album) # TODO: compilation (album)
# TODO: Description text to include attributes.
attributes = [{ attributes = [{
'name': attr, 'name': WP_ATTRS[attr],
'value': r[attr], 'value': r[attr],
'position': idx, 'position': str(idx),
'is_visible': '1', 'is_visible': 1,
'is_variation': '0', 'is_variation': 0,
'is_taxonomy': '0' 'is_taxonomy': 1,
} for idx, attr in enumerate(DP_TRACK_ATTRIBUTES)] } for idx, attr in enumerate(DP_TRACK_ATTRIBUTES)]
sample = [{
'name': name,
'path': "{url_base}/sample-{part}-{track:02d}.mp3".format(
url_base=DP_SAMPLE_URL_BASE,
part=r['Source Part'],
track=int(r['Source Track']))
}]
custom_fields = {
'_jplayer_sample_file': [
phpserialize.dumps(sample)],
'_downloadable': ['yes'],
'_downloadable_files': [
phpserialize.dumps(files)],
'_product_attributes': [
phpserialize.dumps({
a['name']: a for a in attributes})],
}
product = dict(WOO_IMP_EXP_PRODUCT_FIELDS) product = dict(WOO_IMP_EXP_PRODUCT_FIELDS)
wtf_attributes = [
{k: str(a[k]).replace('"', '``').replace(',', '~||~')
for k in a}
for a in attributes]
wtf_attributes = (
json.dumps(wtf_attributes)
.replace(',', '||')
.replace('~||~', ','))
product.update({ product.update({
"Product Name": name, "Product Name": name,
"Tags": tags, "Tags": r['Tags'],
"Categories": DP_TRACK_CATEGORIES, "Categories": DP_TRACK_CATEGORIES,
"Downloadable": 'yes', "Downloadable": 'yes',
"Virtual": 'yes', "Virtual": 'yes',
"Sold Individually": 'yes', "Sold Individually": 'yes',
"Downloadable Files": files, "Downloadable Files": (phpserialize.dumps(files)
.decode('utf-8')),
"Download Type": "music", "Download Type": "music",
"Price": DP_TRACK_PRICE, "Price": DP_TRACK_PRICE,
"Regular Price": DP_TRACK_PRICE, "Regular Price": DP_TRACK_PRICE,
"Attributes": json.dumps(attributes) "Attributes": wtf_attributes,
"Custom Fields": (phpserialize.dumps(custom_fields)
.decode('utf-8')),
}) })
return product return product
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment