mirror of
https://github.com/cooperhammond/irs.git
synced 2025-01-23 06:40:59 +00:00
tagger edits
This commit is contained in:
parent
e402bcea14
commit
ae5c7d3ed4
|
@ -1,9 +1,5 @@
|
||||||
version: 1.0
|
version: 1.0
|
||||||
shards:
|
shards:
|
||||||
cr-taglib:
|
|
||||||
github: teknomunk/cr-taglib
|
|
||||||
commit: 5bfca75aaac31c0e4eee4c6e0d72c624af773c09
|
|
||||||
|
|
||||||
ydl_binaries:
|
ydl_binaries:
|
||||||
github: cooperhammond/ydl-binaries
|
github: cooperhammond/ydl-binaries
|
||||||
commit: 8a622bf9d2c0b848db8d8db2f46f09334a1f03f8
|
commit: 8a622bf9d2c0b848db8d8db2f46f09334a1f03f8
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Ripper
|
||||||
# Ripper.download_mp3("https://youtube.com/watch?v=0xnciFWAqa0",
|
# Ripper.download_mp3("https://youtube.com/watch?v=0xnciFWAqa0",
|
||||||
# "Queen/A Night At The Opera/Bohemian Rhapsody.mp3")
|
# "Queen/A Night At The Opera/Bohemian Rhapsody.mp3")
|
||||||
# ```
|
# ```
|
||||||
def download_mp3(video_url : String, output_filename : String)
|
def download_mp3(video_url : String, output_filename : String) : Nil
|
||||||
ydl_loc = BIN_LOC.join("youtube-dl")
|
ydl_loc = BIN_LOC.join("youtube-dl")
|
||||||
|
|
||||||
# remove the extension that will be added on by ydl
|
# remove the extension that will be added on by ydl
|
||||||
|
@ -32,7 +32,7 @@ module Ripper
|
||||||
options.keys.each do |option|
|
options.keys.each do |option|
|
||||||
command += " #{option} #{options[option]}"
|
command += " #{option} #{options[option]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
system(command)
|
system(command)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,11 @@ class Tags
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_text_tag(key : String, value : String)
|
def add_text_tag(key : String, value : String) : Nil
|
||||||
@query_args.push(%(-metadata #{key}="#{value}"))
|
@query_args.push(%(-metadata #{key}="#{value}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_album_art(image_location : String)
|
def add_album_art(image_location : String) : Nil
|
||||||
if !File.exists?(image_location)
|
if !File.exists?(image_location)
|
||||||
raise "Image file not found at location: #{image_location}"
|
raise "Image file not found at location: #{image_location}"
|
||||||
end
|
end
|
||||||
|
@ -33,10 +33,13 @@ class Tags
|
||||||
@query_args.push(%(-metadata:s:v title="Album cover"))
|
@query_args.push(%(-metadata:s:v title="Album cover"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save : Nil
|
||||||
@query_args.push(%("#{@filename}"))
|
@query_args.push(%("_#{@filename}"))
|
||||||
command = @BIN_LOC.to_s + "/ffmpeg " + @query_args.join(" ")
|
command = @BIN_LOC.to_s + "/ffmpeg " + @query_args.join(" ")
|
||||||
puts command
|
system command
|
||||||
|
|
||||||
|
File.delete(@filename)
|
||||||
|
File.rename("_" + @filename, @filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class SpotifySearcher
|
||||||
# ```
|
# ```
|
||||||
# SpotifySearcher.new().authorize("XXXXXXXXXX", "XXXXXXXXXX")
|
# SpotifySearcher.new().authorize("XXXXXXXXXX", "XXXXXXXXXX")
|
||||||
# ```
|
# ```
|
||||||
def authorize(client_id : String, client_secret : String)
|
def authorize(client_id : String, client_secret : String) : self
|
||||||
auth_url = "https://accounts.spotify.com/api/token"
|
auth_url = "https://accounts.spotify.com/api/token"
|
||||||
|
|
||||||
headers = HTTP::Headers{
|
headers = HTTP::Headers{
|
||||||
|
@ -51,7 +51,8 @@ class SpotifySearcher
|
||||||
# })
|
# })
|
||||||
# => {track metadata}
|
# => {track metadata}
|
||||||
# ```
|
# ```
|
||||||
def find_item(item_type : String, item_parameters : Hash, offset=0, limit=20)
|
def find_item(item_type : String, item_parameters : Hash, offset=0,
|
||||||
|
limit=20) : JSON::Any?
|
||||||
|
|
||||||
query = __generate_query(item_type, item_parameters, offset, limit)
|
query = __generate_query(item_type, item_parameters, offset, limit)
|
||||||
|
|
||||||
|
@ -70,14 +71,17 @@ class SpotifySearcher
|
||||||
|
|
||||||
points = __rank_items(items, item_parameters)
|
points = __rank_items(items, item_parameters)
|
||||||
|
|
||||||
return items[points[0][1]]
|
begin
|
||||||
|
return items[points[0][1]]
|
||||||
|
rescue IndexException
|
||||||
|
return nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates url to run a GET request against to the Spotify open API
|
# Generates url to run a GET request against to the Spotify open API
|
||||||
# Returns a `String.`
|
# Returns a `String.`
|
||||||
private def __generate_query(item_type : String, item_parameters : Hash,
|
private def __generate_query(item_type : String, item_parameters : Hash,
|
||||||
offset : Int32, limit : Int32)
|
offset : Int32, limit : Int32) : String
|
||||||
query = ""
|
query = ""
|
||||||
|
|
||||||
# parameter keys to exclude in the api request. These values will be put
|
# parameter keys to exclude in the api request. These values will be put
|
||||||
|
@ -108,7 +112,8 @@ class SpotifySearcher
|
||||||
# Ranks the given items based off of the info from parameters.
|
# Ranks the given items based off of the info from parameters.
|
||||||
# Meant to find the item that the user desires.
|
# Meant to find the item that the user desires.
|
||||||
# Returns an `Array` of `Array(Int32)` or [[3, 1], [...], ...]
|
# Returns an `Array` of `Array(Int32)` or [[3, 1], [...], ...]
|
||||||
private def __rank_items(items : Array, parameters : Hash)
|
private def __rank_items(items : Array,
|
||||||
|
parameters : Hash) : Array(Array(Int32))
|
||||||
points = [] of Array(Int32)
|
points = [] of Array(Int32)
|
||||||
index = 0
|
index = 0
|
||||||
|
|
||||||
|
@ -152,7 +157,7 @@ class SpotifySearcher
|
||||||
# If the strings are the exact same, return 3 pts.
|
# If the strings are the exact same, return 3 pts.
|
||||||
# If *item1* includes *item2*, return 1 pt.
|
# If *item1* includes *item2*, return 1 pt.
|
||||||
# Else, return 0 pts.
|
# Else, return 0 pts.
|
||||||
private def __points_compare(item1 : String, item2 : String)
|
private def __points_compare(item1 : String, item2 : String) : Int32
|
||||||
item1 = item1.downcase.gsub(/[^a-z0-9]/, "")
|
item1 = item1.downcase.gsub(/[^a-z0-9]/, "")
|
||||||
item2 = item2.downcase.gsub(/[^a-z0-9]/, "")
|
item2 = item2.downcase.gsub(/[^a-z0-9]/, "")
|
||||||
|
|
||||||
|
@ -171,7 +176,7 @@ class SpotifySearcher
|
||||||
# __query_encode("album", "A Night At The Opera")
|
# __query_encode("album", "A Night At The Opera")
|
||||||
# => "album:A+Night+At+The+Opera"
|
# => "album:A+Night+At+The+Opera"
|
||||||
# ```
|
# ```
|
||||||
private def __param_encode(key : String, value : String)
|
private def __param_encode(key : String, value : String) : String
|
||||||
return key.gsub(" ", "+") + ":" + value.gsub(" ", "+") + "+"
|
return key.gsub(" ", "+") + ":" + value.gsub(" ", "+") + "+"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@ module Youtube
|
||||||
# Youtube.find_url("Bohemian Rhapsody", "Queen")
|
# Youtube.find_url("Bohemian Rhapsody", "Queen")
|
||||||
# => "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
# => "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
||||||
# ```
|
# ```
|
||||||
def find_url(song_name : String, artist_name : String, search_terms = "", download_first = false)
|
def find_url(song_name : String, artist_name : String, search_terms = "",
|
||||||
|
download_first = false) : Nil
|
||||||
query = (song_name + " " + artist_name + " " + search_terms).strip.gsub(" ", "+")
|
query = (song_name + " " + artist_name + " " + search_terms).strip.gsub(" ", "+")
|
||||||
|
|
||||||
url = "https://www.youtube.com/results?search_query=" + query
|
url = "https://www.youtube.com/results?search_query=" + query
|
||||||
|
@ -56,7 +57,8 @@ module Youtube
|
||||||
# Will rank videos according to their title and the user input
|
# Will rank videos according to their title and the user input
|
||||||
# Returns an `Array` of Arrays each layed out like
|
# Returns an `Array` of Arrays each layed out like
|
||||||
# [<points>, <original index>].
|
# [<points>, <original index>].
|
||||||
private def __rank_videos(song_name : String, artist_name : String, query : String, nodes : Array(XML::Node))
|
private def __rank_videos(song_name : String, artist_name : String,
|
||||||
|
query : String, nodes : Array(XML::Node)) : Array(Array(Int32))
|
||||||
points = [] of Hash(String, Int32)
|
points = [] of Hash(String, Int32)
|
||||||
index = 0
|
index = 0
|
||||||
|
|
||||||
|
@ -94,7 +96,7 @@ module Youtube
|
||||||
# If after the items have been blanked, *item1* includes *item2*,
|
# If after the items have been blanked, *item1* includes *item2*,
|
||||||
# return 1 pts.
|
# return 1 pts.
|
||||||
# Else, return 0 pts.
|
# Else, return 0 pts.
|
||||||
private def __points_compare(item1 : String, item2 : String)
|
private def __points_compare(item1 : String, item2 : String) : Int32
|
||||||
if item2.includes?(item1)
|
if item2.includes?(item1)
|
||||||
return 3
|
return 3
|
||||||
end
|
end
|
||||||
|
@ -114,7 +116,7 @@ module Youtube
|
||||||
# *video_name* is the title of the video, and *query* is what the user the
|
# *video_name* is the title of the video, and *query* is what the user the
|
||||||
# program searched for. *query* is needed in order to make sure we're not
|
# program searched for. *query* is needed in order to make sure we're not
|
||||||
# subtracting points from something that's naturally in the title
|
# subtracting points from something that's naturally in the title
|
||||||
private def __count_buzzphrases(query : String, video_name : String)
|
private def __count_buzzphrases(query : String, video_name : String) : Int32
|
||||||
good_phrases = 0
|
good_phrases = 0
|
||||||
bad_phrases = 0
|
bad_phrases = 0
|
||||||
|
|
||||||
|
@ -124,7 +126,7 @@ module Youtube
|
||||||
if query.downcase.gsub(/[^a-z0-9]/, "").includes?(gold_phrase)
|
if query.downcase.gsub(/[^a-z0-9]/, "").includes?(gold_phrase)
|
||||||
next
|
next
|
||||||
elsif video_name.downcase.gsub(/[^a-z0-9]/, "").includes?(gold_phrase)
|
elsif video_name.downcase.gsub(/[^a-z0-9]/, "").includes?(gold_phrase)
|
||||||
bad_phrases += 1
|
good_phrases += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,7 +145,7 @@ module Youtube
|
||||||
|
|
||||||
# Finds valid video links from a `HTTP::Client.get` request
|
# Finds valid video links from a `HTTP::Client.get` request
|
||||||
# Returns an `Array` of `XML::Node`
|
# Returns an `Array` of `XML::Node`
|
||||||
private def __get_video_link_nodes(doc : String)
|
private def __get_video_link_nodes(doc : String) : Array(XML::Node)
|
||||||
nodes = XML.parse(doc).xpath_nodes("//a")
|
nodes = XML.parse(doc).xpath_nodes("//a")
|
||||||
valid_nodes = [] of XML::Node
|
valid_nodes = [] of XML::Node
|
||||||
|
|
||||||
|
@ -158,7 +160,7 @@ module Youtube
|
||||||
|
|
||||||
# Tests if the provided `XML::Node` has a valid link to a video
|
# Tests if the provided `XML::Node` has a valid link to a video
|
||||||
# Returns a `Bool`
|
# Returns a `Bool`
|
||||||
private def __video_link_node?(node : XML::Node)
|
private def __video_link_node?(node : XML::Node) : Bool
|
||||||
# If this passes, then the node links to a playlist, not a video
|
# If this passes, then the node links to a playlist, not a video
|
||||||
if node["href"]?
|
if node["href"]?
|
||||||
return false if node["href"].includes?("&list=")
|
return false if node["href"].includes?("&list=")
|
||||||
|
|
Loading…
Reference in a new issue