diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..4d308d1
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..a157278
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..2ff871d
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/tswift.iml b/.idea/tswift.iml
new file mode 100644
index 0000000..c299a89
--- /dev/null
+++ b/.idea/tswift.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index bf4bf74..98f9335 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,3 +4,5 @@ requests>=2.7.0
twine>=1.5.0
wheel>=0.24.0
google>=1.9.1
+setuptools~=50.3.2
+fpdf~=1.7.2
\ No newline at end of file
diff --git a/tswift.py b/tswift.py
index 977df12..feedd7f 100755
--- a/tswift.py
+++ b/tswift.py
@@ -16,7 +16,7 @@
import re
import random
import sys
-
+from fpdf import FPDF
ARTIST_URL = "https://www.metrolyrics.com/{artist}-alpage-{n}.html"
SONG_URL = "https://www.metrolyrics.com/{title}-lyrics-{artist}.html"
@@ -84,6 +84,19 @@ def load(self):
return self
+ def printf(self):
+ """Print the lyrics to pdf file in current working directory"""
+ pdf = FPDF()
+ pdf.add_page()
+ pdf.set_font("Helvetica", size=12)
+ lines = self.format().split("\n")
+ for line in lines:
+ # deal with western european letters
+ line = line.encode(encoding='cp1252')
+ line = line.decode(encoding='latin-1', errors='replace')
+ pdf.cell(200, 5, txt=line, ln=1)
+ pdf.output(slugify(self.title) + '_' + slugify(self.artist) + '.pdf')
+
@property
def lyrics(self):
if self._lyrics is None:
@@ -190,6 +203,12 @@ def main():
help='Search for song by lyrics',
required=False,
)
+ parser.add_argument(
+ '-f', '--to_pdf',
+ help='Print lyrics to pdf in current working directory',
+ action='store_true',
+ required=False
+ )
args = parser.parse_args()
if args.lyrics:
@@ -209,6 +228,9 @@ def main():
.format(args.artist))
sys.exit(1)
+ if song and args.to_pdf:
+ song.printf()
+
print(song.format())