scan2.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import os
  2. import sys
  3. import dataset
  4. import codecs
  5. fname_dict={}
  6. #fulllst=['#31','#32','#33','#34','#35','#36','#37','#38','#39','#40','#41','#42']
  7. fulllst=['#49','#50','#51','#52','#53','#54','#55']
  8. fr=codecs.open('c:/tmp/ytfiles.csv','r','utf-8')
  9. lines=fr.readlines()
  10. fr.close()
  11. ## .mp4 -> yid
  12. fname_yiddict={}
  13. for l in lines:
  14. elmts=l.split(',')
  15. if len(elmts[2])>10:
  16. fname_yiddict[elmts[0].lower().replace('\r','').replace('\n','')]=elmts[2].replace('\r','').replace('\n','').replace("http://youtu.be/",'').replace("https://youtu.be/",'')
  17. for lst_elmt in fulllst:
  18. lst=os.listdir('O:\\【完整版】幸福空間節目\\'+lst_elmt)
  19. for l in lst:
  20. fname_dict[l]='O:\\【完整版】幸福空間節目\\'+lst_elmt+"\\"+l
  21. print(l)
  22. print('O:\\【完整版】幸福空間節目\\'+lst_elmt+"\\"+l)
  23. db2 = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
  24. table=db2['yt_tasks2']
  25. db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@127.0.0.1:13317/xoops?charset=utf8mb4')
  26. # yid -> detail
  27. yiddict={}
  28. cursor=db.query('select youtube_video_id,title,description from youtube_list')
  29. title=None
  30. desc=None
  31. for c in cursor:
  32. # print(c['youtube_video_id'])
  33. yiddict[c['youtube_video_id']]=c
  34. # title=c['title']
  35. # desc=c['description']
  36. for k,v in fname_yiddict.items():
  37. # print(k)
  38. # print(v)
  39. if yiddict.get(v):
  40. if fname_dict.get(k):
  41. table.insert({'fname':k,'path':fname_dict[k],'yid':yiddict[v]['youtube_video_id'],'title':yiddict[v]['title'],'desc':yiddict[v]['description']})
  42. print(k)
  43. print(fname_dict[k])
  44. print(yiddict[v]['youtube_video_id'])
  45. print(yiddict[v]['title'])
  46. #print(lst)