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. diff --git a/delojza.py b/delojza.py index 29ec8d9..50d2ab8 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 = os.path.abspath(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 @@ -123,7 +124,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" @@ -205,7 +206,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 @@ -287,9 +294,10 @@ class DelojzaBot: if len(ytdl_urls) > 0: self.handle(ytdl_urls, message, hashtags, 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, hashtags, 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, hashtags, self.download_raw) # noinspection PyBroadException def tg_handle_rest(self, bot, update): @@ -476,7 +484,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'),