Skip to content

Commit

Permalink
Merge pull request #10 from arsaboo/debug
Browse files Browse the repository at this point in the history
Extract audio conversion to a separate function and add output logs if conversion fails
  • Loading branch information
Liupold authored Mar 20, 2023
2 parents e7492a2 + a7dbb9e commit ba92b46
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
1 change: 0 additions & 1 deletion .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Run test script
run: python ./scripts/ci_test.py

4 changes: 2 additions & 2 deletions fmdpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from . import conf

VERSION = "0.6.1"
install_requires = ['ffmpeg-python', 'click', 'music-tag>=0.4.3', 'requests',
'pillow', 'lyricsgenius', 'dataclasses', 'spotipy', 'tqdm']
install_requires = ['click', 'music-tag>=0.4.3', 'requests', 'pillow',
'lyricsgenius', 'dataclasses', 'spotipy', 'tqdm', 'pydub']

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' +
Expand Down
4 changes: 2 additions & 2 deletions fmdpy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def parse_url_query(query_json):
return song_list


def query_songs_seacrh(query_text, max_results=5):
def query_songs_search(query_text, max_results=5):
"""Search Songs using text."""
if ("fmd" in query_text) or ("liupold" in query_text):
print(ART)
Expand Down Expand Up @@ -101,4 +101,4 @@ def query(query_string, max_results=5):
return query_album_from_url(query_string)
if query_string == "":
query_string = "new"
return query_songs_seacrh(query_string, max_results)
return query_songs_search(query_string, max_results)
36 changes: 24 additions & 12 deletions fmdpy/download.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
"""Downloader for fmdpy."""
import os
#import sys
import tempfile
import requests
import ffmpeg
import music_tag

import lyricsgenius
import music_tag
import requests
from pydub import AudioSegment
from tqdm import tqdm
from fmdpy import headers, config, utils

from fmdpy import config, headers, utils

def convert_audio(input_file_path, output_file_path, bitrate, dlformat):
try:
input_audio = AudioSegment.from_file(input_file_path, "mp4")
except FileNotFoundError:
print(f"Input file {input_file_path} not found.")
return
except Exception as e:
print(f"Error reading input file {input_file_path}: {e}")
return
try:
input_audio.export(output_file_path, format=dlformat, bitrate=bitrate)
except FileNotFoundError:
print(f"Output file path {output_file_path} not found.")
return
except Exception as e:
print(f"Error writing output file {output_file_path}: {e}")
return

def dlf(url, file_name, silent=0, dltext=""):
"""Download a file to a specified loaction."""
Expand Down Expand Up @@ -76,13 +94,7 @@ def main_dl(
if dlformat != 'native':
output_file += f".{dlformat}"
# convert to desired format.
(
ffmpeg
.input(tf_song.name)
.output(output_file, **{'b:a': f'{bitrate}k'})
.global_args('-loglevel', 'error', '-vn')
.run()
)
convert_audio(tf_song.name, output_file, f'{bitrate}k', dlformat)
else:
output_file += '.mp4'
if not os.path.isfile(output_file):
Expand Down

0 comments on commit ba92b46

Please sign in to comment.