Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert change to folder filtering + add special handling for shuffle arg instead (fixes regression: #4548) #4566

Merged
merged 4 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 22 additions & 8 deletions iina/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
var iinaArgFilenames: [String] = []
var dropNextArg = false

Logger.log("Got arguments \(arguments)")
Logger.log("Command-line args: \(arguments)")
for arg in arguments {
if dropNextArg {
dropNextArg = false
Expand All @@ -251,9 +251,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
}
}

Logger.log("IINA arguments: \(iinaArgs)")
Logger.log("Filenames from arguments: \(iinaArgFilenames)")
commandLineStatus.parseArguments(iinaArgs)
Logger.log("Filenames from args: \(iinaArgFilenames)")
Logger.log("Derived mpv properties from args: \(commandLineStatus.mpvArguments)")

print("IINA \(version) Build \(build)")

Expand Down Expand Up @@ -317,9 +317,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
Timer.scheduledTimer(timeInterval: TimeInterval(0.1), target: self, selector: #selector(self.checkForShowingInitialWindow), userInfo: nil, repeats: false)
} else {
var lastPlayerCore: PlayerCore? = nil
let getNewPlayerCore = { () -> PlayerCore in
let getNewPlayerCore = { [self] () -> PlayerCore in
let pc = PlayerCore.newPlayerCore
self.commandLineStatus.assignMPVArguments(to: pc)
commandLineStatus.assignMPVArguments(to: pc)
if commandLineStatus.shufflePlaylist {
pc.shufflePending = true
}
lastPlayerCore = pc
return pc
}
Expand Down Expand Up @@ -1038,6 +1041,7 @@ struct CommandLineStatus {
var openSeparateWindows = false
var enterMusicMode = false
var enterPIP = false
var shufflePlaylist = false
var mpvArguments: [(String, String)] = []
var iinaArguments: [(String, String)] = []
var filenames: [String] = []
Expand All @@ -1053,10 +1057,20 @@ struct CommandLineStatus {
let strippedName = String(name.dropFirst(4))
if strippedName == "-" {
isStdin = true
} else if splitted.count <= 1 {
mpvArguments.append((strippedName, "yes"))
} else {
mpvArguments.append((strippedName, String(splitted[1])))
let argPair: (String, String)
if splitted.count <= 1 {
argPair = (strippedName, "yes")
} else {
argPair = (strippedName, String(splitted[1]))
}

if argPair.0 == "shuffle" && argPair.1 == "yes" {
Logger.log("Found shuffle request in command-line args. Will convert it to \"playlist-shuffle\" command")
shufflePlaylist = true
} else {
mpvArguments.append(argPair)
}
}
} else {
// other args
Expand Down
6 changes: 6 additions & 0 deletions iina/MPVController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ not applying FFmpeg 9599 workaround
// Request tick event.
// chkErr(mpv_request_event(mpv, MPV_EVENT_TICK, 1))

addHook(MPVHook.onLoad, hook: MPVHookValue(withBlock: { [self] next in
Logger.log("Callback triggered for mpv 'on-load' hook", level: .verbose, subsystem: player.subsystem)
player.fileWillLoad()
next()
}))

// Set a custom function that should be called when there are new events.
mpv_set_wakeup_callback(self.mpv, { (ctx) in
let mpvController = unsafeBitCast(ctx, to: MPVController.self)
Expand Down
18 changes: 16 additions & 2 deletions iina/PlayerCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ class PlayerCore: NSObject {

var isSearchingOnlineSubtitle = false

/// For supporting `--shuffle` arg, to shuffle playlist when launching from command line
var shufflePending = false

// test seeking
var triedUsingExactSeekForCurrentFile: Bool = false
var useExactSeekForCurrentFile: Bool = true
Expand Down Expand Up @@ -307,8 +310,7 @@ class PlayerCore: NSObject {
if urls.count == 1 {
let url = urls[0]

if url.isExistingDirectory
|| isBDFolder(url)
if isBDFolder(url)
|| Utility.playlistFileExt.contains(url.absoluteString.lowercasedPathExtension) {
info.shouldAutoLoadFiles = false
open(url)
Expand Down Expand Up @@ -1556,6 +1558,18 @@ class PlayerCore: NSObject {
events.emit(.fileStarted)
}

/// Called via mpv hook `on_load`, right before file is loaded.
func fileWillLoad() {
/// Currently this method is only used to honor `--shuffle` arg via iina-cli
guard shufflePending else { return }
shufflePending = false

Logger.log("Shuffling playlist", subsystem: subsystem)
mpv.command(.playlistShuffle)
/// will cancel this file load sequence (so `fileLoaded` will not be called), then will start loading item at index 0
mpv.command(.playlistPlayIndex, args: ["0"])
}

/** This function is called right after file loaded. Should load all meta info here. */
func fileLoaded() {
Logger.log("File loaded", subsystem: subsystem)
Expand Down