[Python] M3UWalker

Dieses Thema im Forum "Projekte / Codes" wurde erstellt von cable, 15. März 2010 .

Schlagworte:
  1. 15. März 2010
    M3UWalker

    Hoi!

    Ich mal wieder mit einem kleinen nützlichen Tool. Der Name ist eventuell nicht so sprichlich, aber ich erkläre hier, was das Script tut. Die Idee kam mir, als ich alle meine Lieder, die ich in einer .m3u Playlist gespeichert hatte, an einem bestimmten Ort speichern wollte (MP3 Player). Ich hatte antürlich keine Lust alle Dateien per Hand zu kopieren und so entstand in 5 Min dieses Script.

    Python Version: 3.1
    Plattform: Win (Unix sollte auch funktionieren, aber nicht getestet)

    PHP:
    import os
    import shutil

    def copyFiles
    ( m3ufile toPath ):
        
    srcPath  os . path . dirname ( m3ufile )
        if 
    os . getcwd () !=  srcPath :
            
    os . chdir ( srcPath )
        
    open ( m3ufile 'r' )
        
    song  ''
        
    for  line in f :
            if 
    line . endswith ( '\n' ):
                
    line  line [ 0 :- 1 #delete the newline at the end
            
    if  line . startswith ( '#' ) and  line  !=  '#EXTM3U' :
                
    song  line [ line . find ( ',' ) +  1 :]
            else:
                if 
    os . path . exists ( line ):
                    try:
                        
    shutil . copy ( line os . path . join ( toPath os . path . basename ( line )))
                        print(
    'Copying:' song )
                    
    except :
                        print(
    'Error while copying ' os . path . basename ( line ))
                    
        
    f . close ()

    if 
    __name__  ==  '__main__' :
        
    m3u  input ( 'Type the path and filename of the .m3u file: ' )
        if 
    m3u . endswith ( '\n' ):
            
    m3u  m3u [ 0 :- 1 #delete the newline
        
    if  os . path . exists ( m3u ) and  m3u . endswith ( '.m3u' ):
            
    dest  input ( 'Type the folder to copy the files to: ' )
            if 
    dest . endswith ( '\n' ):
                
    dest  dest [ 0 :- 1 #delete the newline
            
    if  os . path . exists ( dest ) and  os . path . isdir ( dest ):
                
    copyFiles ( m3u dest )
            else:
                print(
    dest 'is no existing path or not a folder!' )
        else:
            print(
    'There is no such file:' m3u )
            
        print()
        print(
    'FINISH' )
    Ihr gebt den Pfad zur .m3u Datei an und den Ort, wo die Datei gespeichert werden soll und die Sache geschieht automatisch

    greez
     
  2. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.