From cd2419d7522ed088e8ce1ebea1000c16bb5b0f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 2 May 2019 20:42:50 +0000 Subject: [PATCH 1/5] Add LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e423a52 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Tomáš Mládek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 4ac19409b580f8b9e947dd5843c80b54639098d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Fri, 3 May 2019 11:38:22 +0200 Subject: [PATCH 2/5] whoops; title is not 'title' (fix files not getting tagged) --- delojza.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/delojza.py b/delojza.py index 33354a7..9e4ddcf 100755 --- a/delojza.py +++ b/delojza.py @@ -123,7 +123,7 @@ class DelojzaBot: title = split[1] source = "fallback (artist - title)" - if title is None and title in info: + if title is None and 'title' in info: title = info['title'] source = "full title fallback" From 56635b60f1d8815fcaef91d3a5c308d94e1bcbb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Fri, 3 May 2019 11:41:54 +0200 Subject: [PATCH 3/5] remove hardcoded /var/tmp --- delojza.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/delojza.py b/delojza.py index 9e4ddcf..1789482 100755 --- a/delojza.py +++ b/delojza.py @@ -6,6 +6,7 @@ import os import re import shutil import sys +import tempfile from configparser import ConfigParser from datetime import datetime from glob import glob @@ -39,12 +40,12 @@ def datestr(date): class DelojzaBot: - def __init__(self, tg_api_key, out_dir, tmp_dir='/var/tmp', acoustid_key=None, tumblr_keys=None, markov=None): + def __init__(self, tg_api_key, out_dir, tmp_dir=None, acoustid_key=None, tumblr_keys=None, markov=None): self.logger = logging.getLogger("delojza") self.out_dir = out_dir self.logger.debug('OUT_DIR: ' + out_dir) - self.tmp_dir = tmp_dir + self.tmp_dir = tmp_dir if tmp_dir else tempfile.gettempdir() self.logger.debug('TMP_DIR: ' + tmp_dir) self.markov = markov @@ -474,7 +475,7 @@ if __name__ == '__main__': delojza = DelojzaBot(config.get('delojza', 'tg_api_key'), config.get('delojza', 'OUT_DIR', fallback=os.path.join(_DIR_, "out")), - tmp_dir=config.get('delojza', 'tmp_dir', fallback="/var/tmp"), + tmp_dir=config.get('delojza', 'tmp_dir', fallback=tempfile.gettempdir()), acoustid_key=config.get('delojza', 'acoustid_api_key'), tumblr_keys=(config.get('tumblr', 'consumer_key'), config.get('tumblr', 'consumer_secret'), From 9471aad4baa503c0dfd4f40d9ef7d7bc9f7ceeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Fri, 3 May 2019 11:45:46 +0200 Subject: [PATCH 4/5] don't try to tag unnecessarily --- delojza.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/delojza.py b/delojza.py index 1789482..1be6575 100755 --- a/delojza.py +++ b/delojza.py @@ -208,7 +208,13 @@ class DelojzaBot: filenames.append(final_filename) if audio and is_mp3: - self.tag_file(final_filename, message) + try: + id3 = mutagen.id3.ID3(final_filename) + untagged = 'TIT2' not in id3 + except mutagen.id3.ID3NoHeaderError: + untagged = True + if untagged: + self.tag_file(final_filename, message) return filenames From d308f48a1e9b52b30832702cda0be71cdd111a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sat, 4 May 2019 23:27:28 +0200 Subject: [PATCH 5/5] less strict filter for raw url downloads --- delojza.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/delojza.py b/delojza.py index 1be6575..3cc6add 100755 --- a/delojza.py +++ b/delojza.py @@ -296,9 +296,10 @@ class DelojzaBot: if len(ytdl_urls) > 0: self.handle(ytdl_urls, message, hashtag, self.download_ytdl) if len(normal_urls) > 0: - image_urls = [url for url in normal_urls if "image" in requests.head(url).headers.get("Content-Type", "")] - if len(image_urls) > 0: - self.handle(image_urls, message, hashtag, self.download_raw) + file_urls = [url for url in normal_urls if + "text" not in requests.head(url).headers.get("Content-Type", "text")] + if len(file_urls) > 0: + self.handle(file_urls, message, hashtag, self.download_raw) # noinspection PyBroadException def tg_handle_rest(self, bot, update):