1. <legend id='00AjR'><style id='00AjR'><dir id='00AjR'><q id='00AjR'></q></dir></style></legend>
      <bdo id='00AjR'></bdo><ul id='00AjR'></ul>

    <i id='00AjR'><tr id='00AjR'><dt id='00AjR'><q id='00AjR'><span id='00AjR'><b id='00AjR'><form id='00AjR'><ins id='00AjR'></ins><ul id='00AjR'></ul><sub id='00AjR'></sub></form><legend id='00AjR'></legend><bdo id='00AjR'><pre id='00AjR'><center id='00AjR'></center></pre></bdo></b><th id='00AjR'></th></span></q></dt></tr></i><div id='00AjR'><tfoot id='00AjR'></tfoot><dl id='00AjR'><fieldset id='00AjR'></fieldset></dl></div>

    <tfoot id='00AjR'></tfoot>
  2. <small id='00AjR'></small><noframes id='00AjR'>

    1. 如何从文件列表开始创建电影数据库

      How to create a movie database starting from a list of files(如何从文件列表开始创建电影数据库)
        <tbody id='RTUWF'></tbody>

      <small id='RTUWF'></small><noframes id='RTUWF'>

        1. <legend id='RTUWF'><style id='RTUWF'><dir id='RTUWF'><q id='RTUWF'></q></dir></style></legend>
        2. <i id='RTUWF'><tr id='RTUWF'><dt id='RTUWF'><q id='RTUWF'><span id='RTUWF'><b id='RTUWF'><form id='RTUWF'><ins id='RTUWF'></ins><ul id='RTUWF'></ul><sub id='RTUWF'></sub></form><legend id='RTUWF'></legend><bdo id='RTUWF'><pre id='RTUWF'><center id='RTUWF'></center></pre></bdo></b><th id='RTUWF'></th></span></q></dt></tr></i><div id='RTUWF'><tfoot id='RTUWF'></tfoot><dl id='RTUWF'><fieldset id='RTUWF'></fieldset></dl></div>
          <tfoot id='RTUWF'></tfoot>
                <bdo id='RTUWF'></bdo><ul id='RTUWF'></ul>

              • 本文介绍了如何从文件列表开始创建电影数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的家庭服务器上有大量电影(大约 4000 部).这些文件都被命名为Title - Subtitle (year).extension.我想为我所有的电影创建一个数据库(即使在 excel 中也可以).数据库应包含以下列:标题、副标题(如果存在)、服务器上文件的年份和位置(某些电影按类型或演员组织在文件夹中).到目前为止,我有一个 bash 脚本,它只返回一个 txt 文件,其中包含每个硬盘驱动器的文件列表(每个文件都包含每个硬盘驱动器的列表).如何在我的家庭服务器(运行 debian)上自动创建这种数据库?

                I have a large amount of movies on my home server (4000 circa). The files are all named Title - Subtitle (year).extension. I would like to create a database (even in excel would be fine) of all my movies. The database should contain as columns: title, subtitle (if exists), year and location of the file on the server (some movies are organized in folders by genere or actor). As of now I have a bash script that returns just a txt file containing a list of files for each hard drive (each file contains the list for each hard drive). How can I create this kind of database automatically on my home server (which is running debian)?

                使用一些电影数据库api自动检索有关电影的其他信息也很好,但我想这会很复杂.

                It would be great also to automatically retrieve other informations about the movies using some movie databases api, but I guess that this would be very complicated.

                推荐答案

                这是一个相当广泛的问题,在这里并不合适(这更像是一个教程而不是一个快速代码问题),但这里有一些战略建议:

                This is a pretty broad question and not really appropriate here (this is more of a tutorial than a quick code question), but here's some strategic advice:

                • Excel 将打开一个 .csv 文件并将逗号/换行符视为单元格.所以
                • 您需要对目录进行迭代,也许是递归的
                • 扩展路径名——如果你使用像 Python 这样的高级语言,这可以通过标准函数来实现;然后使用正则表达式解析最后一位
                • 将每个路径的格式化内容存储为列表中的行
                • 将该列表打印到文本文件,用逗号连接每个元素,用换行符连接每行
                • 为所述文件提供 .csv 后缀并在 Excel 中打开

                请注意,如果您真的想要一个合适的数据库,Python 又是一个不错的选择——SQLite 是标准安装的一部分.

                Note that if you really want a database proper, Python again is a nice choice—SQLite is part of the standard install.

                干杯,祝你好运

                更新:哈哈,您在我回答时编辑了问题.似乎您需要的一切都在文件名中,但如果您打算使用元数据,请注意.如果元数据并非都来自同一个来源,那么从文件中提取元数据会变得更加棘手;并非每种媒体类型都具有相同的元数据结构,并非每个创建文件的应用程序都提供相同的元数据结构.因此,获取元数据的逻辑可能会变得混乱.

                UPDATE: Haha, you edited the question whilst I answered. It seems like everything you need is in the file name, but if you're planning on using metadata, here's a caution. Pulling the metadata out of your files can get trickier if they've not all come from the same source; not every media type has the same metadata structure, not every application that creates the files provides the same. So the logic of getting your metadata can get messy.

                您是否有理由不能使用现有程序来执行此操作?

                Is there a reason you can't use extant programs to do this?

                最后你提到在你的网络服务器上安装它;再次遵循 Python,标准包中也内置了向您的服务器发出所需请求的能力.

                Finally you mention getting it on your web-server; once again deferring to Python, the capacity to make the requests of your server you need is also built into the standard package.

                最终更新

                无法帮助您使用 bash;我很喜欢,我也不是 Python 专家,但你的目标很简单.我还没有对此进行测试——可能有一两个错字,认为它是伪代码,主要是 Python 就绪的.

                Can't help you with bash; I'm all thumbs there, and I'm no expert in Python either but your goals are pretty simple. I haven't tested this—there is probably a typo or two, consider it pseudo-code that is mostly python-ready.

                # import the standard libraries you'll need
                import os # https://docs.python.org/2/library/os.html
                import re # https://docs.python.org/2/library/re.html
                
                # this function will walk your directories and output a list of file paths
                def getFilePaths(directory):
                    file_paths = []
                    for root, directories, files in os.walk(directory):
                        for filename in files:
                            filepath = os.path.join(root, filename)
                            file_paths.append(filepath)
                    return file_paths
                
                
                
                video_file_paths = getFilePaths("path/to/video/library")
                output_to_csv = [];
                for video_file in video_file_paths:
                    base_path, fname = os.path.split(video_file) 
                
                     """ This is a super simple bit of regex that, provided  your files are all formatted as
                     written, will parse out title, subtitle, year and file extension. If your file names
                     turn out to have more exceptions than you expect (I'd be shocked if not), you may need
                     to make this part more robust, either with much more savvy regex, or else some conditional
                     logic—maybe a recursive try... catch loop"""
                    reg_ex = re.compile("/^(.*) - (.*) ((.*)).(.*)$/");
                
                    # now apply the compiled regex to each path
                    name_components = reg_ex.match(fname);
                
                    """Each output is a row of your CSV file; .join() will join the 4 elements of the regex
                    match (assuming, again, that your filenames are as clean as you claim), and then add
                    the basepath, so you should be building, in this loop, a list with elements like:
                    title, subtitle, year, file_extension, full path"""
                
                    output_to_csv.append("{0},{1}".format(name_components.join(","), base_path));
                
                #create the file, making sure the location is writeable
                csv_doc = open("my_video_database.csv", "w");
                
                # now join all the rows with line breaks and write the compiled text to the file
                csv_doc.write( ouput_to_csv.join("
                ") ); 
                
                #close  your new database
                csv_doc.close()
                

                这篇关于如何从文件列表开始创建电影数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
              • <i id='rjZ9b'><tr id='rjZ9b'><dt id='rjZ9b'><q id='rjZ9b'><span id='rjZ9b'><b id='rjZ9b'><form id='rjZ9b'><ins id='rjZ9b'></ins><ul id='rjZ9b'></ul><sub id='rjZ9b'></sub></form><legend id='rjZ9b'></legend><bdo id='rjZ9b'><pre id='rjZ9b'><center id='rjZ9b'></center></pre></bdo></b><th id='rjZ9b'></th></span></q></dt></tr></i><div id='rjZ9b'><tfoot id='rjZ9b'></tfoot><dl id='rjZ9b'><fieldset id='rjZ9b'></fieldset></dl></div>
                • <bdo id='rjZ9b'></bdo><ul id='rjZ9b'></ul>
                  <legend id='rjZ9b'><style id='rjZ9b'><dir id='rjZ9b'><q id='rjZ9b'></q></dir></style></legend>

                            <tbody id='rjZ9b'></tbody>

                          <small id='rjZ9b'></small><noframes id='rjZ9b'>

                          <tfoot id='rjZ9b'></tfoot>