@@ -209,21 +209,13 @@ char *mp_get_playback_resume_dir(struct MPContext *mpctx)
209209}
210210
211211static char * mp_get_playback_resume_config_filename (struct MPContext * mpctx ,
212- const char * fname )
212+ const char * path )
213213{
214214 struct MPOpts * opts = mpctx -> opts ;
215215 char * res = NULL ;
216216 void * tmp = talloc_new (NULL );
217- const char * path = NULL ;
218- if (mp_is_url (bstr0 (fname ))) {
219- path = fname ;
220- } else if (opts -> ignore_path_in_watch_later_config ) {
221- path = mp_basename (fname );
222- } else {
223- path = mp_normalize_path (tmp , fname );
224- if (!path )
225- goto exit ;
226- }
217+ if (opts -> ignore_path_in_watch_later_config && !mp_is_url (bstr0 (path )))
218+ path = mp_basename (path );
227219 uint8_t md5 [16 ];
228220 av_md5_sum (md5 , path , strlen (path ));
229221 char * conf = talloc_strdup (tmp , "" );
@@ -234,8 +226,6 @@ static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
234226 if (wl_dir && wl_dir [0 ])
235227 res = mp_path_join (NULL , wl_dir , conf );
236228 talloc_free (wl_dir );
237-
238- exit :
239229 talloc_free (tmp );
240230 return res ;
241231}
@@ -296,32 +286,29 @@ static void write_redirects_for_parent_dirs(struct MPContext *mpctx, char *path)
296286 // "/a/b/c.mkv" is the current entry, also create resume files for /a/b and
297287 // /a, so that "mpv --directory-mode=lazy /a" resumes playback from
298288 // /a/b/c.mkv even when b isn't the first directory in /a.
289+ char * path_copy = talloc_strdup (NULL , path );
299290 bstr dir = mp_dirname (path );
300291 // There is no need to write a redirect entry for "/".
301- while (dir .len > 1 && dir .len < strlen (path )) {
302- path [dir .len ] = '\0' ;
303- mp_path_strip_trailing_separator (path );
304- write_redirect (mpctx , path );
305- dir = mp_dirname (path );
292+ while (dir .len > 1 && dir .len < strlen (path_copy )) {
293+ path_copy [dir .len ] = '\0' ;
294+ mp_path_strip_trailing_separator (path_copy );
295+ write_redirect (mpctx , path_copy );
296+ dir = mp_dirname (path_copy );
306297 }
298+ talloc_free (path_copy );
307299}
308300
309301void mp_write_watch_later_conf (struct MPContext * mpctx )
310302{
311303 struct playlist_entry * cur = mpctx -> playing ;
312304 char * conffile = NULL ;
313- void * ctx = talloc_new (NULL );
314305
315306 if (!cur )
316307 goto exit ;
317308
318- char * path = mp_normalize_path (ctx , cur -> filename );
319- if (!path )
320- goto exit ;
321-
322309 struct demuxer * demux = mpctx -> demuxer ;
323310
324- conffile = mp_get_playback_resume_config_filename (mpctx , path );
311+ conffile = mp_get_playback_resume_config_filename (mpctx , cur -> filename );
325312 if (!conffile )
326313 goto exit ;
327314
@@ -337,7 +324,7 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
337324 goto exit ;
338325 }
339326
340- write_filename (mpctx , file , path );
327+ write_filename (mpctx , file , cur -> filename );
341328
342329 bool write_start = true;
343330 double pos = get_playback_time (mpctx );
@@ -374,34 +361,33 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
374361 }
375362 fclose (file );
376363
377- if (mpctx -> opts -> position_check_mtime && !mp_is_url (bstr0 (path )) &&
378- !copy_mtime (path , conffile ))
364+ if (mpctx -> opts -> position_check_mtime && !mp_is_url (bstr0 (cur -> filename )) &&
365+ !copy_mtime (cur -> filename , conffile ))
379366 {
380367 MP_WARN (mpctx , "Can't copy mtime from %s to %s\n" , cur -> filename ,
381368 conffile );
382369 }
383370
384- write_redirects_for_parent_dirs (mpctx , path );
371+ write_redirects_for_parent_dirs (mpctx , cur -> filename );
385372
386373 // Also write redirect entries for a playlist that mpv expanded if the
387374 // current entry is a URL, this is mostly useful for playing multiple
388375 // archives of images, e.g. with mpv 1.zip 2.zip and quit-watch-later
389376 // on 2.zip, write redirect entries for 2.zip, not just for the archive://
390377 // URL.
391- if (cur -> playlist_path && mp_is_url (bstr0 (path ))) {
392- char * playlist_path = mp_normalize_path (ctx , cur -> playlist_path );
393- write_redirect (mpctx , playlist_path );
394- write_redirects_for_parent_dirs (mpctx , playlist_path );
378+ if (cur -> playlist_path && mp_is_url (bstr0 (cur -> filename ))) {
379+ write_redirect (mpctx , cur -> playlist_path );
380+ write_redirects_for_parent_dirs (mpctx , cur -> playlist_path );
395381 }
396382
397383exit :
398384 talloc_free (conffile );
399- talloc_free (ctx );
400385}
401386
402387void mp_delete_watch_later_conf (struct MPContext * mpctx , const char * file )
403388{
404- char * path = mp_normalize_path (NULL , file ? file : mpctx -> filename );
389+ char * path = file ? mp_normalize_path (NULL , file )
390+ : talloc_strdup (NULL , mpctx -> filename );
405391 if (!path )
406392 goto exit ;
407393
0 commit comments