summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosias <me@josias.dev>2021-07-22 08:08:13 -0700
committerJosias <me@josias.dev>2021-07-22 10:01:28 -0700
commit029a8d0c075308b9c74ffa73919653bab9f1b7e0 (patch)
treeaa6f0b8a7eaa870d2d6f9149408db0a0259c84bf
Add initial version
Includes a basic downloader and parser into plaintext
-rw-r--r--.gitignore2
-rw-r--r--LICENSE14
-rw-r--r--README.md23
-rw-r--r--__init__.py0
-rw-r--r--setup.py14
-rwxr-xr-xugcli.py47
6 files changed, 100 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ca6e549
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+__pycache__/
+ugcli.egg-info/
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..4496372
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,14 @@
+Copyright 2021 Josias
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer, and the following Bible verse(s).
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer, and the following Bible verse(s) in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+BIBLE VERSES:
+The multitude of those who believed were of one heart and soul. Not one of them claimed that anything of the things which he possessed was his own, but they had all things common. - Acts 4:32
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..8b99870
--- /dev/null
+++ b/README.md
@@ -0,0 +1,23 @@
+# Ultimate Downloader
+
+A downloader for Ultimate Guitar tabs. It scrapes a publicly-available page and extracts the lyrics and chords.
+
+## Installation and Usage
+
+```
+$ pip install git+https://codeberg.org/josias/ugcli
+$ ugcli <song-url>
+```
+
+## Possibilities
+
+- Conversion to PDF
+- Support for [Tabdown](https://github.com/Ultimate-Guitar/Tabdown)
+
+## License
+
+You may use, modify, and redistribute this software under the terms listed in the [LICENSE file](LICENSE).
+
+You may optionally redistribute it instead under the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
+
+In short: you may either include a Bible verse in your modified version, or release the source code of your modifications.
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/__init__.py
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..a6023a8
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+
+from distutils.core import setup
+
+setup(name='ugcli',
+ version='0.1.0',
+ description='Ultimate Guitar CLI',
+ author='Josias',
+ author_email='me@josisa.dev',
+ url='https://codeberg.org/josias/ugcli',
+ py_modules=['ugcli'],
+ entry_points={
+ 'console_scripts': ['ugcli = ugcli:main'],
+ })
diff --git a/ugcli.py b/ugcli.py
new file mode 100755
index 0000000..428a010
--- /dev/null
+++ b/ugcli.py
@@ -0,0 +1,47 @@
+"""
+ug-cli is an unofficial tool for accessing Ultimate Guitar and converting songs into more readable formats
+"""
+
+import json
+import sys
+import urllib.request, urllib.error, urllib.parse
+
+try:
+ from BeautifulSoup import BeautifulSoup
+except ImportError:
+ from bs4 import BeautifulSoup
+
+"""
+Parses the Ultimate Guitar song webpage and extracts the song text
+"""
+def extract_song(text):
+ soup = BeautifulSoup(text, "lxml")
+ element = soup.find_all("div", {"class": "js-store"})[0]
+ data = json.loads(element.get("data-content"))
+ return data["store"]["page"]["data"]["tab_view"]["wiki_tab"]["content"]
+
+"""
+Parses Ultimate Guitar's song format into plaintext by removing excess syntax
+"""
+def parse_song(text):
+ n = text
+ n = n.replace("[tab]", "")
+ n = n.replace("[/tab]", "")
+ n = n.replace("[ch]", "")
+ n = n.replace("[/ch]", "")
+ return n
+
+def main():
+ if len(sys.argv) == 1:
+ print("Not enough arguments")
+ exit()
+
+ url = sys.argv[1]
+
+ response = urllib.request.urlopen(url)
+ content = response.read()
+
+ print(parse_song(extract_song(content)))
+
+if __name__ == "__main__":
+ main()