Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Clean code a bit and fix grammer #7

Merged
merged 6 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
![mmdl](https://raw.githubusercontent.com/techboy-coder/mmdl/main/mmdl%20image.png)
![mmdl](mmdl_image.png)

# mmdl - Mega Music Downloader

![License](https://img.shields.io/pypi/l/mmdl?style=for-the-badge) ![PyPI](https://img.shields.io/pypi/v/mmdl?style=for-the-badge) ![Downloads](https://img.shields.io/pypi/dw/mmdl?style=for-the-badge)

## What is mmdl ❓

MMDL is a cli app which allows you to quickly and efficiently download one or multiple songs from YouTube.
**TLDR**: MMDL is a cli app which allows you to quickly and efficiently download one or multiple songs from YouTube.

I wanted a tool to quickly and efficiently download songs/audios from YouTube based on the name of the song. I also wanted the songs to be tagged with metadata. This is why I created this simple to use tool.

### Why

Expand Down Expand Up @@ -68,15 +70,15 @@ Please [open a issue](https://github.com/techboy-coder/mmdl/issues/new) with som

### Questions ❓

Please [start/check a discussion](https://github.com/techboy-coder/mmdl/discussions/new).
Please [start/search for a discussion](https://github.com/techboy-coder/mmdl/discussions/new).

## Contributing 🤜

We welcome contributions very much. They are appreciated.
We welcome contributions very much (Even small ones). They are appreciated.

### Steps

1. Check for bugs/issues you would like to solve.
1. Check for bugs/issues you would like to solve or think of new features you would like to implement.
2. Fork the repo and make your changes.
3. Send a pull request.

Expand All @@ -89,7 +91,11 @@ We welcome contributions very much. They are appreciated.
- https://github.com/willmcgugan/rich - Rich by Will McGugan
- https://github.com/ytdl-org/youtube-dl - YoutubeDl

## License ⚖️
## Legality ⚖️

**I assume no liability or responsibility for how this app is used.** Please stay legal and respect the laws in your country. This tool is intended for archiving music for which you have a license.

## License 📜

The MIT License (MIT)

Expand Down
12 changes: 6 additions & 6 deletions build/lib/mmdl/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ def asker():
).ask()

if single_songs == "One song":
return [questionary.text("What is the song name").ask()]
return [questionary.text("What is the song name?").ask()]
else:
input_method = questionary.select(
"Which songs do you want to download?",
"How do you want to download?",
choices=[
"Songs, comma seperated",
"Write song titles, comma seperated",
'List in textfile (1 Song per line)',
'From YTMusic (beta)',
]).ask() # returns value of selection

if input_method == "From YTMusic":
if input_method == "From YTMusic (beta)":
console.print("""[bold red]YT-Music[/bold red].
- Go to your YTMusic liked songs playlist (https://music.youtube.com/playlist?list=LM)
- Make sure you are logged in
Expand All @@ -57,8 +57,8 @@ def asker():
text_file = open(file ,encoding='utf-8')
songs_list = text_file.read().splitlines()
return songs_list
elif input_method=="Songs, comma seperated":
songs_list = questionary.text("Write all songs (comma seperated)").ask().split(",")
elif input_method=="Write song titles, comma seperated":
songs_list = questionary.text("Write all songs (comma seperated):").ask().split(",")
return songs_list
except Exception as e:
## eventually change :/
Expand Down
121 changes: 35 additions & 86 deletions build/lib/mmdl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from mmdl import MusicDownloader
from .ask import asker
from rich.console import Console
from .utils import *
import questionary
console = Console()
from click_help_colors import HelpColorsGroup, HelpColorsCommand
Expand Down Expand Up @@ -50,23 +51,15 @@ def go(verbose, debug):
# Go Command
> Easy way to download songs. Uses inputs/inquirer. (Simply run 'mmdl go')
"""
print_logo()

if debug:
console.log("Verbose: ", verbose)
console.log("Debug: ", debug)

console.print("""\b[red]
_ _
| | |
_ __ ___ _ __ ___ __| | |
| '_ ` _ \| '_ ` _ \ / _` | |
| | | | | | | | | | | (_| | | [/]by techboy-coder[red]
|_| |_| |_|_| |_| |_|\__,_|_| [/]find me on https://github.com/techboy-coder

[green]mmdl [Mega Music Downloader] - A tool to easily download music.[/green]
""")

song_names=asker()
console.print("\n[cyan]> [/] Total number of songs: %s. \n" % (len(song_names)))
num_of_songs_printer(len(song_names))
# List, verbose, debug
MusicDownloader(song_names, verbose, debug).download_songs()

Expand Down Expand Up @@ -114,19 +107,11 @@ def file(file, seperator, verbose, debug):
console.log("Verbose: ", verbose)
console.log("Debug: ", debug)

console.print("""\b[red]
_ _
| | |
_ __ ___ _ __ ___ __| | |
| '_ ` _ \| '_ ` _ \ / _` | |
| | | | | | | | | | | (_| | | [/]by techboy-coder[red]
|_| |_| |_|_| |_| |_|\__,_|_| [/]find me on https://github.com/techboy-coder

[green]mmdl [Mega Music Downloader] - A tool to easily download music.[/green]
""")
console.print("\n[cyan]> [/] Total number of songs: %s. \n" % (len(songs)))
if not questionary.confirm("Do you want to continue").ask():
quit()
print_logo()

num_of_songs_printer(len(songs))

wanna_continue()
# file, verbose, debug
MusicDownloader(songs, verbose, debug).download_songs()
return
Expand All @@ -153,14 +138,14 @@ def list(songs, verbose, debug, ask):
"""
if ask:
console.print("[cyan][>][/] We'll be manually asking you for songs.")
songs_list = questionary.text("Write all songs search terms (comma seperated)").ask()
songs_list = questionary.text("Write all songs search terms (comma seperated): ").ask()
if not songs_list:
quit()
songs_list = songs_list.split(",")
else:
if len(songs) < 1:
# console.print("[cyan][-][/] You didn't specify any songs. So we'll be manually asking them to you.")
songs_list = questionary.text("Write all songs search terms (comma seperated)").ask()
songs_list = questionary.text("Write all songs search terms (comma seperated):").ask()
if not songs_list:
quit()
songs_list = songs_list.split(",")
Expand All @@ -174,17 +159,8 @@ def list(songs, verbose, debug, ask):
console.log("Verbose: ", verbose)
console.log("Debug: ", debug)

console.print("""\b[red]
_ _
| | |
_ __ ___ _ __ ___ __| | |
| '_ ` _ \| '_ ` _ \ / _` | |
| | | | | | | | | | | (_| | | [/]by techboy-coder[red]
|_| |_| |_|_| |_| |_|\__,_|_| [/]find me on https://github.com/techboy-coder

[green]mmdl [Mega Music Downloader] - A tool to easily download music.[/green]
""")
console.print("\n[cyan]> [/] Total number of songs: %s. \n" % (len(songs_list)))
print_logo()
num_of_songs_printer(len(songs_list))
# file, verbose, debug
MusicDownloader(songs_list, verbose, debug).download_songs()
return
Expand All @@ -209,66 +185,48 @@ def ytmusic(file, verbose, debug, ask):
"""
if not ask and not file:
ask = True
if ask:
console.print("[cyan][>][/] We'll be manually asking you for the file location.")
console.print("""

guide = """
[bold red]YT-Music[/bold red].
- Go to your YTMusic liked songs playlist (https://music.youtube.com/playlist?list=LM)
- Make sure you are logged in
- Press Ctrl/Cmd + Shift + i and open the dev tools
- Keep scrolling down until you reach the end of your playlist (Songs will stop loading)
- Copy the all the html markup
- Create a text file and paste the html into it.
""")
if not questionary.confirm("Only continue if you have done the task.").ask():
quit()
"""

if ask:
console.print("[cyan][>][/] We'll be manually asking you for the file location.")
console.print(guide)
wanna_continue("Only continue if you have done the task.")

file = questionary.path("Where is that file located?").ask()
with open(file, "r", encoding="utf-8") as f:
data = f.read()
h = fromstring(data)
sel = CSSSelector("yt-formatted-string.title.style-scope.ytmusic-responsive-list-item-renderer.complex-string > a.yt-simple-endpoint.style-scope.yt-formatted-string")
songs_list=[e.text for e in sel(h)]
if not songs_list[0]:
console.log("[red][-] Hmm. No songs could be parsed from html. Did you select the correct HTML? If you see a error please make a bug report. Thanks!")
quit()

if not ask:
if not file:
console.log("[red][-] You need to enter the file location or add the -a flag.")
quit()
data = file.read()
h = fromstring(data)
sel = CSSSelector("yt-formatted-string.title.style-scope.ytmusic-responsive-list-item-renderer.complex-string > a.yt-simple-endpoint.style-scope.yt-formatted-string")
songs_list=[e.text for e in sel(h)]
if not songs_list[0]:
console.log("[red][-] Hmm. No songs could be parsed from html. Did you select the correct HTML? If you see a error please make a bug report. Thanks!")
console.print("""
[bold red]YT-Music[/bold red].
- Go to your YTMusic liked songs playlist (https://music.youtube.com/playlist?list=LM)
- Make sure you are logged in
- Press Ctrl/Cmd + Shift + i and open the dev tools
- Keep scrolling down until you reach the end of your playlist (Songs will stop loading)
- Copy the all the html markup
- Create a text file and paste the html into it.
""")


h = fromstring(data)
sel = CSSSelector("yt-formatted-string.title.style-scope.ytmusic-responsive-list-item-renderer.complex-string > a.yt-simple-endpoint.style-scope.yt-formatted-string")
songs_list=[e.text for e in sel(h)]
if not songs_list[0]:
console.log("[red][-] Hmm. No songs could be parsed from html. Did you select the correct HTML? If you see a error please make a bug report. Thanks!")
console.print(guide)


if debug:
console.log("Songs: ", str(songs_list))
console.log("Verbose: ", verbose)
console.log("Debug: ", debug)
console.print("""\b[red]
_ _
| | |
_ __ ___ _ __ ___ __| | |
| '_ ` _ \| '_ ` _ \ / _` | |
| | | | | | | | | | | (_| | | [/]by techboy-coder[red]
|_| |_| |_|_| |_| |_|\__,_|_| [/]find me on https://github.com/techboy-coder

[green]mmdl [Mega Music Downloader] - A tool to easily download music.[/green]
""")
console.print("\n[cyan]> [/] Total number of songs: %s. \n" % (len(songs_list)))
if not questionary.confirm("Do you want to continue").ask():
quit()
print_logo()
num_of_songs_printer(len(songs_list))
wanna_continue()
# file, verbose, debug
MusicDownloader(songs_list, verbose, debug).download_songs()
return
Expand Down Expand Up @@ -300,16 +258,7 @@ def single(song, verbose, debug):
console.log("Verbose: ", verbose)
console.log("Debug: ", debug)

console.print("""\b[red]
_ _
| | |
_ __ ___ _ __ ___ __| | |
| '_ ` _ \| '_ ` _ \ / _` | |
| | | | | | | | | | | (_| | | [/]by techboy-coder[red]
|_| |_| |_|_| |_| |_|\__,_|_| [/]find me on https://github.com/techboy-coder

[green]mmdl [Mega Music Downloader] - A tool to easily download music.[/green]
""")
print_logo()
songs = [song]
console.print("\n[cyan]> [/] Song: %s. \n" % (song))
# file, verbose, debug
Expand Down
76 changes: 1 addition & 75 deletions build/lib/mmdl/mdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,81 +36,6 @@
##Dev Dep
import shutil

class DisplayablePath(object):
display_filename_prefix_middle = '├──'
display_filename_prefix_last = '└──'
display_parent_prefix_middle = ' '
display_parent_prefix_last = '│ '

def __init__(self, path, parent_path, is_last):
self.path = Path(str(path))
self.parent = parent_path
self.is_last = is_last
if self.parent:
self.depth = self.parent.depth + 1
else:
self.depth = 0

@property
def displayname(self):
if self.path.is_dir():
return self.path.name + '/'
return self.path.name

@classmethod
def make_tree(cls, root, parent=None, is_last=False, criteria=None):
root = Path(str(root))
criteria = criteria or cls._default_criteria

displayable_root = cls(root, parent, is_last)
yield displayable_root

children = sorted(list(path
for path in root.iterdir()
if criteria(path)),
key=lambda s: str(s).lower())
count = 1
for path in children:
is_last = count == len(children)
if path.is_dir():
yield from cls.make_tree(path,
parent=displayable_root,
is_last=is_last,
criteria=criteria)
else:
yield cls(path, displayable_root, is_last)
count += 1

@classmethod
def _default_criteria(cls, path):
return True

@property
def displayname(self):
if self.path.is_dir():
return self.path.name + '/'
return self.path.name

def displayable(self):
if self.parent is None:
return self.displayname

_filename_prefix = (self.display_filename_prefix_last
if self.is_last
else self.display_filename_prefix_middle)

parts = ['{!s} {!s}'.format(_filename_prefix,
self.displayname)]

parent = self.parent
while parent and parent.parent is not None:
parts.append(self.display_parent_prefix_middle
if parent.is_last
else self.display_parent_prefix_last)
parent = parent.parent

return ''.join(reversed(parts))

class MusicDownloader():
def __init__(self, song_names: list[str], verbose: int, debug: bool):
"""Music Downloader Class. This is the main class :/
Expand Down Expand Up @@ -171,6 +96,7 @@ def download_songs(self): # sourcery no-metrics
]
temp = []
cwd = Utils.get_cwd()

for f in filenames:
# print(f["filename"])
does_exist = executor.submit(Utils.check_file_exists, f["filename"], f)
Expand Down
Loading