Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. import shutil
  2. import re
  3. import os
  4.  
  5.  
  6. def get_file_list(filelist):
  7.     with open('%s' % filelist, 'r') as playlist:
  8.         ts_filenames = [line.rstrip() for line in playlist
  9.             if line.rstrip().endswith('.ts?null=')]
  10.  
  11.  
  12.     count = 0
  13.     fo = open("filelist.txt", "wb")
  14.     for ts_file in ts_filenames:
  15.         count = count + 1
  16.         fo.write(ts_file)
  17.         fo.write("\n")
  18.     fo.close()
  19.    
  20.     print 'Total files : %d' %count
  21.  
  22. def newfile(newname,filelist):
  23.     with open('%s' % filelist, 'r') as playlist:
  24.         ts_filenames = [line.rstrip() for line in playlist
  25.             if line.rstrip().endswith('.ts?null=')]
  26.    
  27.     with open(newname, 'wb') as merged:
  28.         for ts_file in ts_filenames:
  29.             result = re.search('segment(.*)?null=', ts_file)
  30.             filename = result.group(1).replace("?", "")
  31.             with open("temp/segment%s" %(filename), 'rb') as mergefile:
  32.                 shutil.copyfileobj(mergefile, merged)
  33.     print "Done"
  34.  
  35.  
  36.  
  37. def main():
  38.     if not os.path.exists('temp'):
  39.         os.makedirs('temp')
  40.    
  41.     # get_file_list ( file name )
  42.     filelist = 'index_0_av.m3u8'
  43.     get_file_list(filelist)
  44.  
  45.  
  46.     # load the list to the download manager 'DownThemAll!'
  47.     # save them to the folder 'temp'
  48.  
  49.     # after downloading use this one
  50.    
  51.     ֳ#newname = 'newfile.ts'
  52.     ֳ#newfile(newname,filelist)
  53.  
  54. if __name__ == "__main__":
  55.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement